please help me with my jumping script
when trying to make the player jump i ran into a problems with two code not agreeing to work together, here they are: moving:
public class Controller2 : MonoBehaviour
{
public float speed;
private Rigidbody rb;
private void Start()
{
rb = GetComponent<Rigidbody>();
}
private void FixedUpdate()
{
float H = Input.GetAxis ("Horizontal");
float V = Input.GetAxis ("Vertical");
rb.velocity = new Vector3 (speed * H, 0, speed * V);
}
}
jumping:
public class Jumping : MonoBehaviour
{
public LayerMask GroundLayers;
public float JumpForce;
private Rigidbody rb;
private SphereCollider col;
void Start()
{
rb = GetComponent<Rigidbody>();
col = GetComponent<SphereCollider>();
}
void FixedUpdate()
{
if (Input.GetKeyDown(KeyCode.Space))
{
rb.AddForce(Vector3.up * JumpForce, ForceMode.Impulse);
}
}
}
Thanks in advanced
ps. i am new to unity and coding
Comment
Best Answer
Answer by Hellium · Mar 22, 2018 at 01:31 PM
Have you tried to simply retrieve the y velocity?
rb.velocity = new Vector3 (speed * H, rb.velocity.y, speed * V);