How to move players in lanes [Solved]

Updated on June 17, 2017 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
5 on June 17, 2017

I want to make the player, a cube, travel forward in straight lanes. When I press right, he should snap in to the lane to the right, and etc.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • Liked by
Reply
1 on June 17, 2017

We are not your programmers. We’re help to help if you stumble upon problems. Did you try to do it yourself? If you did, what worked and what didn’t?

 

on June 17, 2017

I did try, and my player flew off the screen. Changed it a little, then he just sat there spinning. I don’t want you to do the work for me, I just wanted a point in the right direction. 🙂

Show more replies
  • Liked by
Reply
Cancel
1 on June 17, 2017
on June 17, 2017

THX. I’ll check it out. 🙂

Show more replies
  • Liked by
Reply
Cancel
0 on June 17, 2017

Hey guys, I figured it out. Here is what I did.

void FixedUpdate()
 {
 rb.AddForce(0, 0, forwardForce * Time.deltaTime);
if (Input.GetKeyDown("d"))
 {
animator.SetBool("movRight", true);
 rb.transform.position = (rb.transform.position + new Vector3(1, 0, 0));
}
if (Input.GetKeyDown("a"))
 {
 animator.SetBool("movLeft", true);
 rb.transform.position = (rb.transform.position + new Vector3(-1, 0, 0));
 }
}

I thought a long time about it, and then figured out that I just needed to add or subtract one unit to his position, instead of using standard controls, and trying to only allow him to be in one place. 🙂

  • Liked by
Reply
Cancel