So my sprite is jumping so fast it’s practically at the point to where it’s practically teleporting. I’ve fiddled with the code and the rigidbody so much, but it always has the same effect.
Here’s what my sprite looks like when jumping
Here’s what how I want it to jump
Here’s the entire code, with the jumping algorithm being in the Update() method
private Animator myAnimator;
private SpriteRenderer mySpriteRenderer;
[SerializeField]
private Rigidbody2D MyRigidBody;
// Use this for initialization
public float jumpPower;
public float jumpTime;
[SerializeField]
private float moveSpeed;
private float moveX = 0f;
private float moveY = 0f;
void Start ()
{
myAnimator = GetComponent<Animator>();
}
public void Awake()
{
mySpriteRenderer = GetComponent<SpriteRenderer>();
}
// Update is called once per frame
void FixedUpdate()
{
moveX = Input.GetAxis("Horizontal");
MyRigidBody.velocity = new Vector2(moveX * moveSpeed, 0);
if (Input.GetKey(KeyCode.D))
{
myAnimator.SetBool("RunRight", true);
}
else
{
myAnimator.SetBool("RunRight", false);
}
if (Input.GetKey(KeyCode.A))
{
myAnimator.SetBool("RunLeft", true);
}
else
{
myAnimator.SetBool("RunLeft", false);
}
}
void Update()
{
if (Input.GetKeyDown(KeyCode.W))
{
MyRigidBody.AddForce(new Vector2(0, jumpPower));
}
}
I’ve tried putting the jumping code in FixedUpdate() and it didn’t make a difference. I’ve fiddled with the gravity, and jump power, and I still have no idea what I’m doing wrong. Please help, thanks.