- Home /
Setting a jump force on a rigidbody
Hello people, I'm very new in unity so any help will be really appreciated.
I'm making a game about a fish jumping out of the water and doing tricks (like dolphin Olympics).
My player is a game object with a rigidbody, and the water is a plane . when the player is on the water the rigidbody is set to IsKninematic and I move and rotate the player with transform.Translate and transform.rotate , when i get out of the water i use this
void Update ()
{
rigidbody.isKinematic = m_bIsKinematic;
//Amount to move
float amtToMove = playerVelocity * Time.deltaTime;
// player Movement
transform.Translate (Vector3.right * amtToMove);
//rotation
if (Input.GetKey(KeyCode.Z))
transform.Rotate(0,0,-rotateSpeed);
if (Input.GetKey(KeyCode.X))
transform.Rotate(0,0,rotateSpeed);
}
void OnTriggerExit(Collider Otherobject)
{
if (Otherobject.tag == "Sea")
{
bMove = false;
collider.attachedRigidbody.useGravity = true;
//a bool to enable or disable IsKinematic
m_bIsKinematic = false ;
playerVelocity = 0;
}
}
So when the player gets out it turn off the IsKinematic and the UseGravity is set to Enable and turn to 0 the player velocity .
SO here is the problem . I want to keep the momentum and velocity of my player to perform the tricks but as i set the player velocity to 0 it stop movement immediately. If i left the player velocity running it jumps out and the gravity pull me down but i can move in the jump like I'm still swimming (not like it should be).
Is there a function or a method or to keep my momentum and velocity but controlated by the physics? I just want to move the fish like a truly kumping dolphin. Any help , workaround , comment will be really apreciated. Thanks for your help.
Answer by Negagames · Apr 17, 2013 at 01:36 AM
Well it looks like you just need to reverse the effects of the OnTriggerExit function by resetting the settings and velocity once you enter the water trigger, to check for entering the water trigger, simply use OnTriggerEnter
Your answer
Follow this Question
Related Questions
Best way to achieve Sonic style physics? 0 Answers
Gravity on a rotating platform 1 Answer
how to make an object fall slowly ? 2 Answers
How can i rotate player when player jump ? 2 Answers
Roof of the builiding (physics) 1 Answer