- Home /
death script remains ineffective
my first person controller has rigidbody; the enemy has a mesh collider. After this script is activated, i run into the enemy and nothing happens.
var player : GameObject;
var enemy : GameObject;
function Update()
{
if(Vector3.Distance(player.transform.position, enemy.transform.position) <= 3)
{
player.transform.position = Vector3(3184.726,-0.7071776,3728.418);
}
}
That's a pretty wasteful mechanism you have there. Not only is Vector3.Distance rather expensive (at least more so than checking the square magnitude), you're doing this every frame. You could do it in fixed update or have a coroutine do it every quarter second.
Alternatively, you could just use a trigger sphere collider that checks for things entering within a radius of three.
Answer by $$anonymous$$ · May 12, 2013 at 02:24 PM
Maybe you need to put a check mark on Mesh Collider "Convex" like on the picture : http://docs.unity3d.com/Documentation/Components/class-MeshCollider.html
Your answer
Follow this Question
Related Questions
Zombie Round Script Help 1 Answer
Spawn Script Not Working 1 Answer
[SOLVED] Problem with "foreach". 1 Answer
mistake in script 1 Answer
Elevator script problem (Java) 1 Answer