- Home /
Question by
LochandLoad · Nov 27, 2013 at 01:44 AM ·
collidercollision-detection
How can I make my Player constantly jump on objects?
I need to know how i can make my player constantly jump on stairs without me letting my finger off the jump button. This is my code to just jump. It is a 2D game.
#pragma strict
var speed : float = 10; //Variables
var jump :float = 0; //Check if the player can jump
var jumpspeed : float = 15; //Check how high the player can jump
var jumptimer :float = 0; //Make the player can jump again using this timer
var ConstantSpeed : float = 20;
function Start () {
}
function Update ()
{
if (Input.GetButton ("a"))
{
transform.Translate(Vector3(-speed,0,0) * Time.deltaTime);
}
if (Input.GetButton ("d"))
{
transform.Translate(Vector3(speed,0,0) * Time.deltaTime);
}
{
if (jump == 1) {
jumptimer = jumptimer +1;
if (jumptimer >= 1) {
jumptimer = 0;
jump = 0;
}
}
if (Input.GetKeyDown ("w"))
{
if (jump == 0) {
rigidbody2D.velocity.y = jumpspeed;
jump = 1;
}
}
}
transform.position.x = transform.position.x + ConstantSpeed;
}
Comment