Hi,I need help whit jumping forward in sidescroller… Right now it only jumps up, but it’s sidescroller so I need to make it jump forward and backward like in FPS controller! I am not good scripter so I would be happy if you help me whit it!
My script:
var speed : float = 3.0;
var rotateSpeed : float = 3.0;
private var dead = false;
private var time = true;
private var accel = false;
private var slow = false;
var slowdown = 0.2;
var score = 1f;
var timescale = 1f;
var acc = 0.2;
var ReadyToFire = true;
var ReadyToSlow = true;
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
var gravity = 20.0;
var JumpSpeed : float = 10;
function timecall(){
time = false;
yield WaitForSeconds (1);
timescale= timescale+1;
time = true;
}
function OnControllerColliderHit (hit : ControllerColliderHit)
{
if(hit.gameObject.tag == "dead")
{
Application.LoadLevel(2);
}
if(hit.gameObject.tag == "box")
{
//destroy the ammo box
Destroy(hit.gameObject);
score = score+1;
}
if(hit.gameObject.tag == "turbo")
{
//destroy the ammo box
Destroy(hit.gameObject);
speed = speed+6.5;
yield WaitForSeconds (2.75);
speed = speed-6.5;
}
if(hit.gameObject.tag == "Win")
{
Application.LoadLevel(3);
}
}
function Update () {
var controller : CharacterController = GetComponent(CharacterController);
var rigid : Rigidbody = GetComponent(Rigidbody);
if(grounded){
if (Input.GetButton("Jump")){
moveDirection.y = JumpSpeed;
}
}
moveDirection.y -= gravity * Time.deltaTime;
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags & CollisionFlags.CollidedBelow) != 0;
var right : Vector3 = transform.TransformDirection(Vector3.right);
var RotateSpeed : float = rotateSpeed * Input.GetAxis ("Horizontal");
controller.SimpleMove(right * RotateSpeed);
// Move forward / backward
var forward : Vector3 = transform.TransformDirection(Vector3.forward);
var curSpeed : float = speed;
controller.SimpleMove(forward * curSpeed);
}
function LateUpdate()
{
if(dead)
{
transform.position = Vector3(-0.023, 3.8, -14.89);
gameObject.Find("Main Camera").transform.position = Vector3(-0.023, 3.8, -14.89);
dead = false;
}
}
@script RequireComponent(CharacterController)