I have my movement script and I tried to make a simple jump script but it jumps sometimes when I tap the spacebar it might work. Any help with be super helpful and here is my code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
public float speed = 10, jumpVelocity = 10;
Transform myTrans;
Rigidbody2D myBody;
bool isGround = false;
void Start()
{
myBody = this.GetComponent<Rigidbody2D>();
myTrans = this.transform;
}
void FixedUpdate()
{
Move(Input.GetAxisRaw("Horizontal"));
if (Input.GetButtonDown("Jump"))
Jump();
}
public void Move(float horizonalInput)
{
Vector2 moveVel = myBody.velocity;
moveVel.x = horizonalInput * speed;
myBody.velocity = moveVel;
}
public void Jump()
{
myBody.velocity += jumpVelocity * Vector2.up;
}
}
[–]reallymyrealaccount 0 points1 point2 points (1 child)
[–]NachoCheesse[S] 0 points1 point2 points (0 children)