Jump to content
Braqoon

detecting collision with non entity objects

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 ?

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

Why would you need a script to make your ship bounce off of walls? Won't it just do that automatically?

Share this post


Link to post

Why would you need a script to make your ship bounce off of walls? Won't it just do that automatically?

I'm pretty sure he means to literally bounce off the walls. i.e. adding force velocity, rather than just colliding.

Share this post


Link to post

Yes Brutile. This is just an example. So overall you need to have a script attached to an object if you want more than physical collision with that object, even if this is just to get the name of the object.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.

×
×
  • Create New...