Hi, ive been scouring the internet left and right to put double jumps into my code,i’m making a 3D platformer, using a 3rd person controller and c#. I would like to know what additional script for the double jumping ill have to use and where abouts to include it.
Thanks. I’m quite new to this.
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public CharacterController controller;
public GameObject projectile;
Vector3 movementVector = Vector3.zero;
//movement variables
public float moveForce = 0;
public float moveDamping = 0.5f;
public float moveForceToAdd = 1f;
public float movementSpeed = 2f;
//jumping variables
public float jumpForce = 1.0f;
public float jumpDamping = 0.5f;
public float jumpForceToAdd = 100f;
int jumpCount = 1;
bool grounded = false;
// Use this for initialization
void Start () {
int result = AddNumber (2, 3);
Debug.Log (result);
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown (KeyCode.Q))
{
Instantiate (projectile, transform.position + transform.forward * 2, transform.rotation);
}
movementVector = new Vector3 (Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
if (Input.GetAxis ("Vertical") != 0 || Input.GetAxis ("Horizontal") != 0)
{
moveForce += moveForceToAdd;
}
if (Input.GetKeyDown (KeyCode.Space))
{
if (controller.isGrounded)
{
jumpForce += jumpForceToAdd;
}
}
movementVector *= moveForce;
movementVector += Physics.gravity;
movementVector += new Vector3 (0, jumpForce, 0);
gameObject.GetComponent<CharacterController>().Move (movementVector * Time.deltaTime);
jumpForce *= jumpDamping;
moveForce *= moveDamping;
}
int AddNumber (int a, int b)
{
return a + b;
}
}
`