Question by
OverTheKotatsu · Jun 01, 2017 at 09:14 PM ·
c#2d game2d-platformerwall collision
How To Make Horizontal Force less than Gravitational Force?
I'm currently making my Game Design Year 1 final project, and it is a simple 2D platformer. I believe my horizontal force is greater than the gravitational force(so I think, anyways). When my character collides with a wall and you continue to hold down the A or D key, depending on which way you are facing the wall, the character will slide down the wall a little bit and then just stay there until you move away from it or jump off. How would I go about fixing this? Forgive me, as I'm still new to Unity and C#.
Here is the bit of code that moves my player:
public float maxSpeed = 5;
public float speed = 50f;
void FixedUpdate()
{
float h = Input.GetAxis("Horizontal");
//Moves player
rb2d.AddForce((Vector2.right * speed) * h);
//Limits speed of player
if (rb2d.velocity.x > maxSpeed)
{
rb2d.velocity = new Vector2(maxSpeed, rb2d.velocity.y);
}
if (rb2d.velocity.x < -maxSpeed)
{
rb2d.velocity = new Vector2(-maxSpeed, rb2d.velocity.y);
}
Comment