- Home /
Can I use transorm.position here?
I'm making a script for the bad guy AI in my 2d platformer. I want him to move to the side and if he touches the player, the player loses. I'm new at scripting so I watched the unity tutorial on transform. position to move an object. But at the end o the video, it says that if you want it to have a collider, you need to use rigidbody/ rigidbody2d. I'm wondering if I can use transform.position in my case? If not, can you link me a tutorial for using rigidbody2d to move an object?
Answer by malkere · Dec 26, 2015 at 05:16 AM
colliders are used to automatically detect collisions, but you can do it yourself with math all you want. just have the bad guy compare his position to the players position, and if they are too close you know they've touched. if you have 50 bad guys and they are all always calculating their own position it can be tougher on the computer than if you use colliders to watch for you.
if you do use colliders and you flat out set the position of the player right on top of the bad guy they physics engine won't know that you passed through the collider because you didn't you just teleported the player straight to somewhere new. if you use a rigidbody it will draw a mathematical line through the collider as it moves through it that the physics engine will see and respond to.
check this stuff out: http://unity3d.com/learn/tutorials/topics/physics
Your answer
Follow this Question
Related Questions
How do I stop an Enemy NavMeshAgent from intersecting the player model? 3 Answers
problem with collider 0 Answers
OnTriggerEnter called only one time?!! 5 Answers
Collider with trouble 1 Answer