- Home /
Question by
unity_gOlvmw3PKZxMRw · Dec 16, 2018 at 06:14 AM ·
c#movement scriptjumpingjumping object
Character floats down after jumping
Hey guys, I have messed around with this code for a while and I can't seem to get the character from floating down after jumping while moving in a direction. Any ideas?
if (Input.GetKey(KeyCode.W)) { rb.velocity = 1 Vector3.forward speed; }
if (Input.GetKey(KeyCode.S))
{
rb.velocity = 1* Vector3.back * speed;
}
if (Input.GetKey(KeyCode.A))
{
rb.velocity = 1* Vector3.left * speed;
}
if (Input.GetKey(KeyCode.D))
{
rb.velocity = 1* Vector3.right * speed;
}
if (jFrame > 0)
{
jFrame--;
isGrounded = false;
}
if (Input.GetButtonDown("Jump") && isGrounded)
{
if (jFrame == 0)
{
jFrame = 3;
isGrounded = false;
rb.velocity = Vector3.up * speed;
if(Input.GetKey(KeyCode.W)|| Input.GetKey(KeyCode.S)||Input.GetKey(KeyCode.A)|| Input.GetKey(KeyCode.D))
{
rb.velocity = 1 * Vector3.down;
}
}
}
Comment
don't just use a full vector right it down, they will override the orthogonal direction.
for horizontal movement alter x and z of the Velocity and for the jump only y. construct a vector you supply to Velocity at the end of the calculations.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Can't get platforming character to jump 2 Answers
Jumping only once (2D) 2 Answers
Jumping: Endless Runner,Hey can anyone help with this endless runner script ? 1 Answer