- Home /
ok so velocity..
i have a falling gameobject"main guy" and an empty game object with ontriggerEnter to detect an objects velocity before it hits the ground. and i have this script to apply damage when falling to fast.
function OnTriggerEnter2D(coll: Collider2D){
var mainguy = GameObject.Find("main guy");
var myVelocity = mainguy.gameObject.rigidbody2D.velocity.y;
if(coll.gameObject.name =="main guy"){
if(myVelocity > 2){
GameObject.Find("main guy").SendMessage("ApplyDamage");
}
Debug.Log(myVelocity);
}
}
i have a feeling that when i put "if(myVelocity > 2)" it looks at the starting velocity of the object the the velocity when it detects the ontriggerenter. i need it to have the velocity when detected by the OnTriggerEnter. can anyone help??
Answer by highpockets · Mar 08, 2014 at 06:08 AM
Well, he is falling, so velocity is most likely negative something, so if you're saying if the velocity.y is more than 2, this would only be true if the object is moving upwards. What you want is less than -2 as an example.
if(myVelocity < -2)
The bigger the negative number, the faster the object is falling
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
health and damage system help 1 Answer
Taking Damage 2 Answers
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers