Jump to content

detecting collision with non entity objects


Braqoon
 Share

Recommended Posts

Hi,

 

So on collision if object we are colliding with has a script attached to it it will be an entity with eg. name

 

function Script:Collision(entity, position, normal, speed)
if(entity:GetKeyValue("name") == "wall") then
--Do Something
end
end

 

 

Now I guess that in order to code specifically certain behaviours based on what object I'm colliding with, that object should be an entity which equals to have a script attached to it, right ? regardless is that a primitive or a prefab model. Even if that object is doing nothing apart from being just an obstacle. Is that correct ?

 

Is that approach is one that everybody is using or should be used or is there another, simple, go to method of finding about an object player have just collided with ?

Link to comment
Share on other sites

If its just an obstacle, it doesn't need a script. You make the collision function in the player for example, and when the player collides with something the Collision function will be called, which passes the entity that you collided with so you can do something with it.

Link to comment
Share on other sites

Yes, I understand that, basics are simple. I'm wandering how should I approach where collision is a trigger to do other things.

 

Take for example a shooter game (which I got it working), so if ship collides with something that it's not an entity I have no way of telling what it was, and I have to apply one rule for all on such collision. That makes me think that if I want this ship of mine to eg. bounce of the side walls, those walls needs at least a name that collision function of my ship can detect. Otherwise any wall will just trigger collision in the same way and here I might don't want that.

Link to comment
Share on other sites

In that example, I would personally create a script just for the walls that apply a force to any object that touches it. That way it stays consistent, but that might not be what you want, so I guess its up to you how to go about it. You could either do the collision on the player and check for a name, or a have a script for the walls that checks for the player (or maybe all objects). If your walls don't specifically have a collision shape, then I would write a script for the wall to create a collision shape.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...