- Home /
Movement (left/right) and jumping = laggy motions.. please help!
Alright. So i have this game - like subwaysurfer ! with my ball stuck in z position and only being able to move it in fixed positions left and right and jumping. Having the level with objects moving towards the player. you know what i mean.
I have everything working with two scripts.. but both of them combined doesn't seem to work. the motion when jumping is laggy and it seems like there is a problem with framerate. idk. please help .
this is my script for movement: function Start () { }
var speed : float = 3.0;
var positions : Vector3[];
private var isFalling = false;
private var index = 1;
function Update() {
if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.A)) {
index--;
if (index < 0) index = 0;
}
if (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown("d")) {
index++;
if (index >= positions.Length) index = positions.Length-1;
}
{
transform.position = Vector3.MoveTowards(transform.position, positions[index], Time.deltaTime * speed);
}
}
function OnCollisionStay ()
{
isFalling = false;
}
and this is my script for jumping:
var JumpH = 8;
var isFalling = false;
function Update () {
if (Input.GetKey(KeyCode.Space) && isFalling == false)
{
rigidbody.velocity.y = JumpH;
isFalling = true;
}
}
function OnCollisionStay () {
isFalling = false;
}
Your answer
Follow this Question
Related Questions
Can my lerp-function be optimized? 1 Answer
How can i synchronize prefab with NetworkTranform? 1 Answer
Unity 2D Scripted Movement 2 Answers
Mixamo Character Movement 0 Answers
Smoothly move player over a collection of checkpoints 0 Answers