4
\$\begingroup\$

In a racing game, I have set up waypoints for the player to follow.

I have added many waypoints to give an illusion of curved movement.

waypoints approximating a curve

However, the player car turns instantaneously when passing each point, which is especially jarring because the camera is following their rotation.

How can I make the player's movement a more natural curve?


I'm using C# in Unity.

\$\endgroup\$
2
  • \$\begingroup\$ You want to add a steering behavior to your vehicles. I suggest using Quaternion.Lerp for smooth rotation \$\endgroup\$ Sep 1, 2015 at 6:51
  • \$\begingroup\$ this is what I am using for rotation, Quaternion target = Quaternion.LookRotation(playerCOntroller.currentWayPoint.position - transform.position); transform.rotation = Quaternion.RotateTowards(transform.rotation, target, playerCOntroller.speed); \$\endgroup\$
    – idurvesh
    Sep 1, 2015 at 7:15

4 Answers 4

1
\$\begingroup\$

You basically have an ordered list of segments, making the segmented path you have described of that road. To smooth it up, you could simply take the centers of the segments and the points connecting them to create Bézeir curves from them.

Read here for a detailed explanation of how it's done.

Once you describe the path as connected Bézeir curves, it's already smooth. Now you just need to configure the vehicles to follow that path. The easiest way to do that is by generating enough points on the path at run time so you basically get many tiny segments. You can also do a kind of binary search on the curve with the t variable, by starting with a small increment and then doubling it until it's too far off and then doing a regular binary search over between the too far off value and half of it. Obviously, generating the spline is more cost efficient amortized.

\$\endgroup\$
0
\$\begingroup\$

Well I don't know much about way points but there is another way to rotate your objects on the circular track.

You can use unity iTween by which u will have to take few nodes and will be able to place them as u want and then one script is there for iTween which u will apply on the gameobject then I think it will work.

Here u go... http://itween.pixelplacement.com/index.php

\$\endgroup\$
2
  • \$\begingroup\$ yes I heard of iTween but was not sure it can be used for racing game ,can we use it flexibly for racing game? rank of players ,diffrent speed for players etc? \$\endgroup\$
    – idurvesh
    Sep 1, 2015 at 7:34
  • \$\begingroup\$ Yes we can... But for that u will have to give some reference points like rotation from a particular position on track and all. All I know is that iTween provides a path with the help of nodes. \$\endgroup\$ Sep 1, 2015 at 8:38
0
\$\begingroup\$

You can use iTween Visual Path editor. Its a nice tool to move object on a particular path. I usually use it for cinematic camera movement. Also many of the parameters regarding the path will be exposed to the user. You can start and end at any point on the path, need not be from start point to end point. Also can force the look at angle of the moving object according to the path nodes.

Link- http://pixelplacement.com/v2/2010/12/03/visual-editor-for-itween-motion-paths/

If you want to make a car racing game its more appropriate to make a Car AI system.

Here is a nice tutorial:- https://www.youtube.com/watch?v=HeQ89e27ehc

\$\endgroup\$
4
  • \$\begingroup\$ yes I heard of iTween but was not sure it can be used for racing game ,can we use it flexibly for racing game? rank of players ,diffrent speed for players etc? \$\endgroup\$
    – idurvesh
    Sep 1, 2015 at 7:34
  • \$\begingroup\$ edited the answer :) \$\endgroup\$
    – Hash Buoy
    Sep 1, 2015 at 7:45
  • \$\begingroup\$ thanks @Hash ,actually I am using moveTowards function to move players since player's positions are restricted on lanes.So not using physics \$\endgroup\$
    – idurvesh
    Sep 1, 2015 at 7:48
  • \$\begingroup\$ ohh in that case iTween is a good option :) You can try adding some tweaks to the code so that the amateur drivers don't follow the exact path , and the good drivers follow it thoroughly and yea also the speed parameter. \$\endgroup\$
    – Hash Buoy
    Sep 1, 2015 at 7:52
0
\$\begingroup\$

As solution, without other tools, you can consider to start (smoothely) turn to next waypoint before you reach the current target waypoint.

Hope the image clarify my idea. When you reach the green circles (the size can depend on waypoints distances) start to turn versus next waypoint

enter image description here

\$\endgroup\$
2
  • \$\begingroup\$ thats pretty good solution, will implement it and let you know \$\endgroup\$
    – idurvesh
    Sep 1, 2015 at 12:30
  • \$\begingroup\$ If I've understood correctly, that would look like the vehicle is sliding awkwardly because it will rotate without changing it's velocity. \$\endgroup\$
    – AturSams
    Sep 20, 2015 at 23:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .