is there any event for to detect when i release any key.when i release the left arrow or right arrow key in key board. when i press uparrow the character should move forward in the ice skating game.when i release the uparrow the character should move forward a little bit due to ice effect and gradually its speed should deceases and stop the movement.When i press the uparrow the character should move forward .
var smooth = 1.0;
var tiltAroundZ ;
var tiltAroundZ1 ;
var target1 ;
var target ;
var force = 10.0;
var offset = 1.0;
function Update ()
{
//left movement of the character ///
if(Input.GetAxis("Horizontal") < -.1 )
{
tiltAroundZ = Input.GetAxis("Horizontal") * ( - 45.0); //to tilt the character at 45 degree
target = Quaternion.Euler (0, 0, tiltAroundZ);
transform.rotation = Quaternion.Slerp(transform.rotation, target,Time.deltaTime * smooth);
transform.Rotate(Vector3.up * -0.2); // to rotate the character a little bit
}
else //to brig back the character to normal position after the tilt
{
tiltAroundZ = Input.GetAxis("Horizontal") * ( 0);
target = Quaternion.Euler (0, 0, tiltAroundZ);
transform.rotation = Quaternion.Slerp(transform.rotation, target,Time.deltaTime * smooth);
}
//right movement of the character//
if(Input.GetAxis("Horizontal") > .1 )
{
tiltAroundZ1 = Input.GetAxis("Horizontal") * (-45.0);
target1 = Quaternion.Euler (0, 0, tiltAroundZ1);
transform.rotation = Quaternion.Slerp(transform.rotation, target1, Time.deltaTime * smooth);
transform.Rotate(Vector3.up *0.2 );
}
else
{
tiltAroundZ1 = Input.GetAxis("Horizontal") * (0);
target1 = Quaternion.Euler (0, 0, tiltAroundZ1);
transform.rotation = Quaternion.Slerp(transform.rotation, target1, Time.deltaTime * smooth);
}
if(Input.GetKey(KeyCode.UpArrow)) // to move forward the character
{
transform.Translate(0,0,1);
}
else //this is to move the chacterter to little forward when the player release the uparrow due to ice effect
{
transform.Translate(0,0,0.3);
}
if(Input.GetKey(KeyCode.DownArrow))
{
transform.Translate(0,0,-0.1);
}
}
here i want the character to move a little forward direction when player release the uparrow due to skating effect and gradually decrease the character speed and make him stop(stand still).another need is when user press the uparrow the player speed should increases gradually like in cars when we start the car the speed is low as we press the uparrow the speed gradually increase and go fast.