Hi guys,
I’m starting with Unity, and I’m trying the engine for the moment. I followed two excellent tutorials for beginners, who definitely set me in the right position on how to start game dev…
I’m currently working on my first project with Unity, and already finding some problems. As far as I’ve understood, I can set any gameobject a rigidbody, and use attraction with it. That’s actually what I did, because gravity is in use in the project I’m working on. Great. This is what I’ve done so far.
Cube created. Set it as rigidbody, and activate gravity. In the script now, here is what I do : on the update function, when the cube reaches 0, deactivate gravity, and freeze position on the Y axis to 0. This works perfectly now…
But… I would like to know the speed of the object when it hits position 0 on the Y axis, store it to a variable to be reused by another gameobject.
I’ve searched the doc (that’s where I found how to deactivate the gravity with scripting), but was unable to find a way to know the speed value of a given object with gravity on it.
A little help on that one ?
Thanks a lot
Vampyre
Edit : I found the function by deduction, and after that in the doc, but I cannot access its value :
rigidbody.velocity = Vector3(0,10,0);
This is the code to modify the velocity of a rigidbody. I would like to store that value. I cannot create a var float, or int as this is vector3. And when I try to create a vector3, it tells me I cannot call getcomponent when declaring a variable…