I need the player to fly around a track where he is only in control of the strafing, the craft needs to rotate by itself between specific waypoints.
Crude pic to illustrate:
I tried looking at some spline scripts, but it seemed more like a complete track solution instead of just rotation data.
How would I go about doing this?
Get your iTween on.
Check out his examples, you may see what your going for right here.
I would prefer some kind of free solution.
The example on the site with path following and jumping, but with strafing added as well, would be what I’m looking for.
"iTween is a free, open-source project. As such, it doesn’t require any purchase or licensing to be used on commercial projects or otherwise. "
I did, the example projects aren’t free.
It’s like ten bucks. iTween is such a solid investment. Support it.
Yeah that what I thought.
Use logic its not hard to figure how he achieved certain things in the examples…
It’s not the price but the concept that is putting me off, using something like iTween seems like a lazy way to solve a relatively simple problem.
Can I get an answer not involving iTween or is it an absolute necessity for this kind of thing?
Research how to calculate splines and the location and tangent of your player along those splines at a given time.
Or just use iTween.
How about create a strip down the center of the track and bake a nav mesh to it. Then have a parent obj follow the nav mesh down the middle while the child object strafes left to right.
If your aircraft is “on rails”, then you need define the function(s) that make the track.
The simplest way to write your own that I can think of is to make a piecewise function: a set of quadratics.
Give each quadratic a set of control points or modifier to change the shape and position of the curve.
You then will want a way to convert each quadratic equation into a parametric equation so you can do things like:
traverse the curve with ease, also differentiate each curve easily which will tell you how much you need to rotate your aircraft in the local up and local forward to approximate direction and roll.
Bare in mind even this method isnt as flexible as Beziers, or Splines (eg quadratics arent as curvy as cubics, modifiers for more complex functions are easier to manipulte).
This post should tell you that, your better off using iTween… lol
I don’t actually understand the question, Palai - since you mentioned splines, but for a manual setup of what I think you want…
Couldn’t you just make an array of empty gameObjects as the waypoints, and have the craft move through the waypoint appropriately - when in closest distance of a particular waypoint, or when at the position of a waypoint, to change rotation values to always face the correct way?
They aren’t supposed to follow the waypoints like a track, they should only rotate according to the direction of the track, everything else is controlled by the player.
At first I used a waypoint setup but I couldn’t find a method to get a smooth enough rotation. The best results I got from rotating according to the distance between the next waypoint and the player, but I still couldn’t get it to be smooth and accurate enough.
Solved it with this if anyone is interested, was more simple than I thought.
Quaternion lookRot = new Quaternion(
waypointRot.x / (dist / zVel),
waypointRot.y / (dist / zVel),
waypointRot.z / (dist / zVel),
waypointRot.w / (dist / zVel));
transform.rotation = Quaternion.Slerp(transform.rotation, lookRot, Time.deltaTime );
zVel is the Z velocity of the craft.
dist is the distance between the waypoint and the craft determined by a raycast.