Skip to content

Instantly share code, notes, and snippets.

@nastajus
Created July 29, 2014 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nastajus/b8326e2fec9f352d22f9 to your computer and use it in GitHub Desktop.
Save nastajus/b8326e2fec9f352d22f9 to your computer and use it in GitHub Desktop.
probably lame lane movement.
[RequireComponent(typeof(CharacterController))]
public class MyController : MonoBehaviour
{
enum Lane { left, middle, right };
Lane curLane = Lane.middle;
CharacterController cc;
void Start () {
cc = GetComponent<CharacterController>();
}
public void Move(int xDir)
{
float MoveDistanceSideways = 2f;
float MoveSpeedSideways = 1f;
int targetLane = xDir + ((int)curLane - 1);
var lanes = System.Enum.GetValues(typeof(Lane)).Cast<Lane>();
foreach (var lane in lanes)
{
int iLane = (int)lane - 1;
if (iLane == targetLane)
{
curLane = (Lane)(targetLane + 1);
cc.Move(new Vector3(xDir, 0, 0) * MoveDistanceSideways);// * Time.deltaTime);
cc.SimpleMove(Physics.gravity);
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment