4

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.

Anko
  • 13,393
  • 10
  • 54
  • 82
idurvesh
  • 530
  • 5
  • 21
  • You want to add a steering behavior to your vehicles. I suggest using Quaternion.Lerp for smooth rotation – Daniel Holst Sep 01 '15 at 06:51
  • 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);
    – idurvesh Sep 01 '15 at 07:15

4 Answers4

1

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.

AturSams
  • 10,517
  • 1
  • 32
  • 58
0

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

Shraddha Patel
  • 175
  • 1
  • 8
  • 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? – idurvesh Sep 01 '15 at 07:34
  • 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. – Shraddha Patel Sep 01 '15 at 08:38
0

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

Hash Buoy
  • 1,479
  • 1
  • 9
  • 17
  • 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? – idurvesh Sep 01 '15 at 07:34
  • edited the answer :) – Hash Buoy Sep 01 '15 at 07:45
  • thanks @Hash ,actually I am using moveTowards function to move players since player's positions are restricted on lanes.So not using physics – idurvesh Sep 01 '15 at 07:48
  • 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. – Hash Buoy Sep 01 '15 at 07:52
0

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

dnk drone.vs.drones
  • 3,460
  • 1
  • 14
  • 26
  • thats pretty good solution, will implement it and let you know – idurvesh Sep 01 '15 at 12:30
  • If I've understood correctly, that would look like the vehicle is sliding awkwardly because it will rotate without changing it's velocity. – AturSams Sep 20 '15 at 23:55