Hi all,
Basically I have my waypoints all setup and working, however my gameobject slows down as it reaches a waypoint, this means that my gameobject does not travel at a constant speed around all my waypoints.
I have read lots of forum topics on this subject, and I have tried a fair few waypoint implementations to get this to work, I did manage to get the gameobject to travel at a constant speed using Sam at FPS waypoint solution.
http://forum.unity3d.com/viewtopic.php?t=31412
However, I need my waypoint solution to work with a player controlled variable speed gameobject.
And Sam’s example calculates the waypoint bezier curve based on time to complete the waypoints layout, prior to moving the gameobject.
I have had this working using Darkbasic Professional, see video below:
http://www.alabsoft.com/vSlot/vSlot%20-%20Work%20in%20progress/vSlot%20-%20Work%20in%20progress.html
However, I want to code this project in Unity now, as Unity is so much more powerful, and with cross-browser support etc.
In Darkbasic Professinal there is a command called CurveAngle.
Function CurveAngle(fA As Single, fDa As Single, fSp As Single) As Single
This command will return an auto-interpolated angle based on a given speed. This command will gradually move a number from its current value to a destination value at a certain speed.
I have found a similar command in the MathFX class from the Unify Wiki called Clerp.
But I cannot get it to work? here is my pseudo code, I know the transform.eulerAngles.y does not work? all I want to do is get the current y angle of the gameobject that my script is attached too.
if(Vector3.Distance(transform.position,waypoints[currentWaypoint])<=damping) {
//Debug.Log("Collided with waypoint");
currentWaypoint++;
currentHeading = waypoints[currentWaypoint];
}
// Get players current/old y angle
oldangle = transform.eulerAngles.y;
// Point player in direction of current waypoint
//transform.LookAt(currentHeading);
// Get players new y angle
newangle = transform.eulerAngles.y;
// Now interpolate (create a smooth curve) the angle based on the speed and new and old angles
//finalangle = Mathfx.Clerp(oldangle, newangle, speed);
// Rotate player
transform.eulerAngles = Vector3(0, finalangle, 0);
// Move player forwards
transform.Translate(0, 0, speed * Time.deltaTime);
Here are some screenshots of my app in Unity.
This shows how the layout is constructed at runtime using Instantiate command, and the placement of the waypoints for each lane.
This shows the Hierarchy view with the cloned track sections.
This final image shows the layout with the waypoints hidden.
I have big plans for this project, multi-player, huge layouts, fastest lap competitions etc, etc, so any help with getting the basics working will be greatly appreciated!
[/img]