Hi! I am working on a 2d platformer game and I have an underwater level. Currently, my movement is not really based on acceleration, rather it is based on moving my position. This works but it does not have the feeling of moving through the water like I imagine acceleration-based movement would have. I have attached my script for underwater movement below. Can someone help me convert this script into an acceleration-based movement to feel like I'm underwater?
//Player Stuff
public float moveSpeed = 5f;
public Rigidbody2D rb;
Vector2 movement;
Vector2 mousePos;
public Camera cam;
private bool m_FacingRight = true;
public Animator animator;
// Update is called once per frame
void Update()
{
//input
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
}
void FixedUpdate()
{
//movement
rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
animator.SetFloat("Speed", Mathf.Abs(movement.x + movement.y));
//Makes the player face the right way
if (movement.x > 0 && !m_FacingRight)
{
// animator.SetBool("TurningLeft", true);
Flip();
}
else if (movement.x < 0 && m_FacingRight)
{
Flip();
}
}
//Code to flip player
void Flip()
{
m_FacingRight = !m_FacingRight;
transform.Rotate(0f, 180f, 0f);
}
↧