- Home /
Question by
Adelphia · Apr 02, 2013 at 08:30 AM ·
beginnercharacter movementskateboard
Movement of character by holding the up arrow instead of repeatedly pressing it.
hi, i am following the design3 tutorial on a skateboarding game but they have it so you press the button down to go a bit faster every time you press the button. i would like to change it so i press the button down and hold it so the character will reach its maximum speed then continue to move forward for a period of time like in any tony hawks game. im very new to coding so any help would be appreciated. Here is the code i am using
var rotateSpeed = 90;
var pushImpulse = 3.5;
private var character : CharacterController;
private var trans : Transform;
private var speed = 0.0;
function Start ()
{
character = GetComponent(CharacterController);
trans = transform;
}
function Pushing()
{
speed += pushImpulse;
}
function Update ()
{
var horizontal = Input.GetAxis("Horizontal");
trans.Rotate(0,rotateSpeed * horizontal * Time.deltaTime,0);
if (Input.GetKeyDown(KeyCode.UpArrow))
Pushing();
character.Move(trans.forward * speed * Time.deltaTime);
}
Comment