Question by
unity_5AC783045F230BC59873 · Apr 15, 2021 at 11:57 AM ·
rigidbody2dphysics2dmovement scriptspeedspeed issues
Limiting backwards speed ,Limiting backwards speed
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]
}
if not working https://giphy.com/gifs/Z7GYlGFiyEushafi72
Comment