- Home /
Question by
re8r0 · Sep 13, 2021 at 10:23 AM ·
unity 2dplatformer
Here when I hold D and then press w or space I don't know why my 2D character is not jumping and he falls off the given platform,I am not able to think how to fix this issue,please help
void FixedUpdate()
{
if (Input.GetKey(KeyCode.A))
{
rb.velocity = new Vector2(-runspeed * Time.fixedDeltaTime, rb.velocity.y);
transform.localScale = new Vector2(-1, 1);
}
if (Input.GetKey(KeyCode.D))
{
rb.velocity = new Vector2(runspeed * Time.fixedDeltaTime, rb.velocity.y);
transform.localScale = new Vector2(1, 1);
}
if ((Input.GetKey(KeyCode.Space))|| (Input.GetKey(KeyCode.W)))
{
if (coll.IsTouchingLayers(ground))
{
rb.velocity = new Vector2(rb.velocity.x, jumpforce * Time.fixedDeltaTime);
state = State.jumping;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Projectile gets stuck at character's position (Unity2d) 0 Answers
trying to make an enemy shoot a projectile at the player when the player enters the enemys range 2 Answers
character can jump, then isnt able to when I walk. Unity 2d 1 Answer
When I build my 2D game and set it to fullscreen, the resolution looks off 0 Answers
Problem with Wall Jump - 2D 0 Answers