- Home /
Question by
SparkyTheAlbino · Apr 23, 2014 at 08:07 PM ·
c#movementitween
Problem with three lane movement
Hello. I have a script which moves te ain character between three lanes, It worked fine before I used iTween but I need the player to smoothly translate between lanes.
What happens now is that it moves smoothly but soon as the player moes just once it moves the lanes so the player cannot move back to its original possition
using UnityEngine;
using System.Collections;
public class Lane_Changer : MonoBehaviour
{
//public float speed = 10.0f;
public float laneWidth = 5.0f;
//public float accelleration = 1.0001f;
private bool inLeft, inRight, inCenter = false;
public bool isDead = false;
void Start () {
inCenter = true;
}
void Update () {
// Debug
if(Input.GetKey(KeyCode.Escape))
{
Application.Quit();
}
if(!isDead)
{
if(Input.GetKeyDown(KeyCode.A))
{
if(inRight)
{
inRight = false;
inCenter = true;
// From Right to Center
//transform.position += new Vector3(-5,0,0);
iTween.MoveBy(gameObject, new Vector3(-laneWidth, 0, 0), 0.8f);
}
else
{
if(inCenter)
{
inCenter = false;
inLeft = true;
// From Center to Right
//transform.position += new Vector3(-5,0,0);
//transform.parent.animation.Play("PlayerMoveLeft");
iTween.MoveBy(gameObject, new Vector3(-laneWidth, 0, 0), 0.8f);
}
else
{
// Do nothing
}
}
}
else
{
if(Input.GetKeyDown(KeyCode.D))
{
if(inLeft)
{
inLeft = false;
inCenter = true;
// From Right to Center
//transform.position += new Vector3(5,0,0);
//transform.parent.animation.Play("PlayerMoveRight");
iTween.MoveBy(gameObject, new Vector3(laneWidth, 0, 0), 0.8f);
}
else
{
if(inCenter)
{
inCenter = false;
inRight = true;
// From Center to Right
//transform.position += new Vector3(5,0,0);
//transform.parent.animation.Play("PlayerMoveRight");
iTween.MoveBy(gameObject, new Vector3(laneWidth, 0, 0), 0.8f);
}
else
{
// Do nothing
}
}
}
}
}
else
{
}
//transform.Translate((Vector3.forward * speed) * Time.deltaTime);
//speed = speed * 1.00001f;
}
}
Comment