- Home /
how i know my object speed ?
hi , please how i can know the speed of my object i shooted it . because i want to execute function when this object stop and it speed = 0 . I,m still new in unity :( function Shoot(){
var ball= Instantiate(Ball, transform.Find("me").transform.position, Quaternion.identity);
ball.rigidbody.AddRelativeForce(transform.forward * Force );
ball-=1;
}
The statement "ball-=1;" doesn't make sense. What do you expect it to do?
But "ball" is your instantiated object, and "Ball" is the object you instantiated from. None of those are integers. Do you have a differently named variable that tracks the number of balls? It must be named differently.
Hhhh yes i changed the variable name when i copied my code here. Thanks :)
Answer by fafase · May 05, 2014 at 12:25 PM
print(rigidbody.velocity.magnitude+"unit/s");
var ball= Instantiate(Ball, transform.Find("me").transform.position, Quaternion.identity);
ball.rigidbody.AddRelativeForce(transform.forward * Force );
print(rigidbody.velocity.magnitude+"unit/s");
ball-=1;
}
it gets me 0 unit / s !! please tell me how i write the code exactly . thanks
You need to have the print in the Update or any kind of repeating method. I would guess this bit of code is only code once so at this time the velocity is zero but next frame it will be positive.
You'll need to use ball.rigidbody.velocity.magnitude, not rigidbody.velocity.magnitude. The latter refers to the rigidbody of THIS gameObject, which might not even exist. Also, when putting this in Update, your variable "ball" must be globally visible, ins$$anonymous$$d of being declared within Shoot().
I make like this but no responding :( what,s the wrong please ?
var darba= Instantiate(Ball, transform.Find("myhand").transform.position, Quaternion.identity);
darba.rigidbody.AddRelativeForce(transform.forward * qowwatDaf3 );
print(darba.rigidbody.velocity.magnitude+"unit/s");
BallNum-=1;
}
Your answer
Follow this Question
Related Questions
Current speed of an object? 5 Answers
Storing and using weapons and objects 0 Answers
How can I implement a SimpleMove max speed? 1 Answer
Disable GameObject Only Father Not Children 2 Answers
Run through hastable of objects 1 Answer