Question by
unity_5AC783045F230BC59873 · Apr 15, 2021 at 12:53 PM ·
movementrigidbody2dphysics2drigidbody.addforce
Limiting backwards speed
https://giphy.com/gifs/Z7GYlGFiyEushafi72 I have to limit the backwards speed of the player but the backwards direction changes since the player rotation follows the cursor, here is movement script:
private void Update()
{
force.x = Input.GetAxisRaw("Horizontal");
force.y = Input.GetAxisRaw("Vertical");
force = Vector2.ClampMagnitude(force, 1f);
}
private void FixedUpdate()
{
ApplyInput();
// code to calculate speed
speed = Vector3.Distance(oldPosition, transform.position) * 100f;
oldPosition = transform.position;
}
private bool ApplyInput()
{
force.x *= SpeedModifier.sidewaySpeed * Time.deltaTime;
force.y *= SpeedModifier.forwardSpeed * Time.deltaTime;
rb.AddForce(force);
if (force != Vector2.zero)
{
return true;
}
return false;
// don't worry about return type![alt text][1]
}
Comment
Your answer
Follow this Question
Related Questions
2D Top-Down Character: How to make my character move using physics? 1 Answer
How to make instantiated rigidbodies continue moving the in the same direction as destroyed object? 1 Answer
Rigidbody2D and Slopes,Rigidbody2D an Slopes 0 Answers
How to stop the character moving after the button is pressed, using Rigidbody2D()..AddForce? 1 Answer
Avoid varying output on same amount of force applied to a Rigidbody2D. 0 Answers