Question by
Deranged-Pufferfish · Nov 29, 2021 at 05:30 PM ·
movementdirectionjitter
When Player is facing left, its movement is jittery and the bullet impact is covered by the walls/floor.
My character moves fine when facing right, and the bullet impact is visible over the walls/floor, but when facing left, my character's movement is jittery and the bullet impact is covered by the walls/floor.
(It's a bit harder to see the jitter in the recording)
This rotates my player:
void Update()
{
Vector3 gunPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
if (gunPosition.x < transform.position.x)
{
transform.eulerAngles = new Vector3(transform.rotation.x, 180f, transform.rotation.z);
}
else
{
transform.eulerAngles = new Vector3(transform.rotation.x, 0f, transform.rotation.z);
}
}
This moves my player:
void Update()
{
moveHorizontal = Input.GetAxisRaw("Horizontal");
moveVertical = Input.GetAxisRaw("Vertical");
}
void FixedUpdate()
{
if (moveHorizontal > 0.1f || moveHorizontal < -0.1f)
{
rb2D.AddForce(new Vector2(moveHorizontal * moveSpeed, 0f), ForceMode2D.Impulse);
}
if (!isJumping && moveVertical > 0.1f)
{
rb2D.AddForce(new Vector2(0f, moveVertical * jumpForce), ForceMode2D.Impulse);
}
}
This makes the bullet impact effect when the bullet collides:
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.tag == "Platform")
{
Instantiate(impactEffect, transform.position, transform.rotation);
Destroy(gameObject);
}
}
Comment
Your answer
Follow this Question
Related Questions
Ghost car movement jitters when replaying previous race 1 Answer
Air Control While Jumping? 1 Answer
Animations are not playing with certain directions? 1 Answer
2D enemy movement direction 0 Answers
How do I make it so that my First Person Controller script allows for movement in all directions? 1 Answer