Question by
jmgomezcobo23 · Apr 15, 2020 at 11:06 AM ·
2d-platformerrigidbody2dplayer movementaccelerationcrossplatform
How can I add acceleration and deceleration to my Rigidbody 2D?
Hi, everyone! I'm working in a university project in which I have to develop a 2D Platformer. I wanted to add acceleration and deceleration to my running method using the Rigidbody component of my player. I was wondering if anyone has an idea of how and what should I use to achieve this. I'm aware that this topic has been answered previosuly, but I couldn't apply it to the Rigidbody2D by using CrossPlatformInputManager.
Looking forward to your feedback!
[SerializeField] float movementSpeed = 5f;
public void Run()
{
Debug.Log("Input: Horizontal Speed: " + movementSpeed);
float controlThrow = CrossPlatformInputManager.GetAxis("Horizontal");
Vector2 playerVelocity = new Vector2(controlThrow * movementSpeed,
myRigidbody2D.velocity.y);
myRigidbody2D.velocity = playerVelocity;
}
Comment