Hey Guys
I use this script to make my player walk automaticly forward and jump if i click… But if i jump again when he grounded he gets slower and slower?
Here is my script:
using UnityEngine;
using System.Collections;
public class runnerscript : MonoBehaviour {
public float Acceleration = 10;
public float maxSpeed = 15;
public Vector3 jumpVelocity;
private bool touchGround = false;
private bool started = false;
IEnumerator PauseOnStartup() {
yield return new WaitForSeconds(5);
started = true;
}
void Start() {
StartCoroutine(PauseOnStartup());
}
void Update () {
if (!started) return;
if (touchGround Input.GetButtonDown ("Jump")) {
rigidbody.AddRelativeForce (jumpVelocity, ForceMode.VelocityChange);
touchGround = false;
}
var curSpeed = rigidbody.velocity;
curSpeed.y = 0;
if (touchGround curSpeed.magnitude < maxSpeed) {
rigidbody.AddRelativeForce (Acceleration, 0, 0);
}
}
void OnCollisionEnter(){
touchGround = true;
}
}
Or do i need to change something in the rigidbody?
Mass: 1
Drag: 0,1
Angular Drag: 1
Use Gravity: yes
Is Kinematic: no
Interpolate: None
Collision Detection:: Discrete
Freeze Rotation X Z