Hi! How do I get the player to do a delay jump when it collides with a object? Do I suppose to set a time interval for when the character collides with the object?
I am a beginner in scripting so I don’t know where to start.
Also I not using a character controller. I am using a rigibody.
K I also upgraded by script. But I have a problem. When I collide with a object, jump is turned off. I want a delay for 3 seconds when the player collides with a wall, then he jumps. I also trying to turn off autorun when he collides with a object. How do I that?
using UnityEngine;
using System.Collections;
public class MoveForward : MonoBehaviour {
public float speed = 6.0F;
public float delayJumpTime = 2.0f;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;
private bool autorun = true;
public bool delayjump= false;
void OnControllerColliderHit(ControllerColliderHit hit)
{
if (hit.collider.tag != "Jumpstuff")
{
Debug.Log("I'm Here");
delayjump = true;
}
//Invoke("changeAutoJump", 3);
}
public void Start ()
{
CharacterController c = GetComponent<CharacterController>();
c.detectCollisions = true;
}
// Update is called once per frame
void Update () {
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded) {
moveDirection = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 2);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton("Jump") && delayjump == false)
{
moveDirection.y = jumpSpeed;
}
if (Input.GetButton("Jump") && delayjump == true)
{
Pizza();
}
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
void changeAutoRun()
{
autorun = true;
}
void changeDelayJump()
{
delayjump = true;
}
IEnumerator Pizza()
{
yield return new WaitForSeconds(3.0f);
Debug.Log("We need to hurry");
moveDirection.y = jumpSpeed;
}
}