using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
public CharacterController canDubJump;
private float dubjump = 0;
private float JumpSpeed = 200.0f;
private Rigidbody rb;
public float Multiplier;
void Start () {
rb = GetComponent<Rigidbody>();
canDubJump = GetComponent<CharacterController>();
}
void Update () {
float movehorizontal = Input.GetAxis("Horizontal");
float movevertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(movehorizontal, 0.0f, movevertical);
rb.AddForce(movement * Multiplier);
if (canDubJump.isGrounded)
{
print("We are Grounded");
}
if (canDubJump.isGrounded && Input.GetKeyDown(KeyCode.Space))
{
rb.AddForce(Vector3.up * JumpSpeed);
}
}
}
For a platformer game I’m creating, I am trying to implement a jump mechanism that doesn’t allow infinite jumping, but the code posted above doesn’t work, and the ball doesn’t jump. Do I have to add a component to the object which is my ground?