Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Camera Rotation Does Not Match Spline Node Rotation
#1
Question 
FULL DISCLOSURE: I also posted this on the Unity forums prior to my account being activated. That post is here: http://forum.unity3d.com/threads/170355-...tion/page7

I'm using and loving Curvy, however I have an issue where moving a camera along the spline does not have accurate results.

What I am trying to do: I have a game where the camera is on rails. Player sits in chairs, stands up, walks around, etc.

After trying a number of systems, Curvy seemed like the best option. So I lay out my splines, put the camera on it, and hit play. Problem is, the camera moves along the spline - but the rotations are inaccurate.

To line things up properly, I put the Curvy spline node as a child of the camera, set its position and rotation to 0 / 0, then move and rotate the camera. When done, I move the Curvy spline back into the Spline object. This is working MOSTLY well - except for that final lineup.

Check out the following two images... the first image shows how the camera should be lined up. I confirm this by making the camera a child of the Curvy spline node, and zeroing out its position and transform.
[Image: curvy_proper.png]

Now this second image is from gameplay. You can see it's close... but not accurate.
[Image: curvy_offset.png]

I should add the following bulletpoints:
- The camera has no parent object (it's parent is the Scene itself)
- I am using PlayMaker to do the movement (with the CurvyMoveAlongSpline action)
- Set Orientation on the PlayMaker Action is set to True.
- Approximate Position on the PlayMaker Action is set to False.
- On the Spline itself, orientation is Tangent, Initial Up-Vector is ControlPoint, and Granularity is 360.

I've played around with a bunch of options but what you see in the second image is the closest I have come. What do I have to do to make the in-game transform properly match the actual node transform?

Thanks in advance!
Reply
#2
Ok,

I've had a look into your example scene.

First: A Granularity of 360 is insanely high, you won't need that usually. In your example I lowered it to 20 and can't see a difference. Keep in mind that Granularity means cache size (and cache calculation!). No big deal on a desktop, but for mobiles this could become an issue.

Am I right that you want the camera to end up upright (camera.transform.up==(0,1,0) ?

If this is the case, you'll need to ensure that the orientation of the spline (yellow line gizmos) is upright. What I did:

- set Spline.Orientation to "ControlPoint". By doing so you have full control over the spline's orientation by rotating the control points
- removed rotation from CP004

(Image attached)

As a result the camera ends up perfectly aligned.

Does this solve your issue?


Attached Files Image(s)
   
Reply
#3
(09-11-2013, 07:54 AM)Jake Wrote: Ok,

I've had a look into your example scene.

First: A Granularity of 360 is insanely high, you won't need that usually. In your example I lowered it to 20 and can't see a difference. Keep in mind that Granularity means cache size (and cache calculation!). No big deal on a desktop, but for mobiles this could become an issue.

Am I right that you want the camera to end up upright (camera.transform.up==(0,1,0) ?

If this is the case, you'll need to ensure that the orientation of the spline (yellow line gizmos) is upright. What I did:

- set Spline.Orientation to "ControlPoint". By doing so you have full control over the spline's orientation by rotating the control points
- removed rotation from CP004

(Image attached)

As a result the camera ends up perfectly aligned.

Does this solve your issue?

That does indeed look MUCH better, thank you!

Is there a good way that you know of to, in the editor, to easily build out a camera path that will look 1:1 in gameplay as it does in the editor? Because even this is slightly offset from how it looks in the editor (especially now that the final node has a rotation of 0/0/0).
Reply
#4
(09-11-2013, 08:04 AM)DCalabrese Wrote: Is there a good way that you know of to, in the editor, to easily build out a camera path that will look 1:1 in gameplay as it does in the editor? Because even this is slightly offset from how it looks in the editor (especially now that the final node has a rotation of 0/0/0).
If you attach a SplineWalker (or SplineAlign) script to the camera you can alter InitialF in the editor and immediately see the result. In fact I wonder why the rotation isn't completely facing up. I'll diving into this right now.
Reply
#5
The SplineWalker works great, as I can easily cycle through the InitialF, and will do the job for now. Thanks!

A possible future request I would have there would be a way to preview a basic 'object moving on path' within the editor in a smooth way... not sure offhand how to do that as Coroutines don't run in editor mode, but possibly could be done with an external DLL...
Reply
#6
Ok, I had a look.

The "Set Rotation" option of SplineWalker and MoveAlongSpline custom actions work by setting rotation to Spline.GetOrientation(). This in fact builds the rotation to match the plane defined by the tangent and the up-vector. So to mute a certain axis from rotation, you'll need to zero out that axis from the tangent vector. E.g. to prevent rotation along the x-axis (i.e. tilting camera down/up), just zero out the y magnitude of the tangent and feed the LookRotation then:

(inside CurvyMoveAlongSpline.cs):
Code:
if (SetOrientation) {
                Vector3 tan = mSpline.GetTangent(mTF,p);
                tan.y=0; // no up/down tilting
                go.transform.rotation = Quaternion.LookRotation(tan, mSpline.GetOrientationUpFast(mTF));
            }
Copy&Paste the action into a new custom action (change the class name of course) and use that.

It's always a good idea to roll your own versions of SplineWalker or custom actions for stuff like that. As a benefit you can remove everything you don't need and safe a lot of IF-THEN calls. Perhaps you want to smooth out tilting instead of removing it etc... creating a custom controller is always the best and most performant way (if you're able to code, of course, but most parts can be copy&pasted).

That's the reason I make most of the API public. If a curve related piece of information is there, give the user access to it, you'll never know what he wants to do with it Wink

Jake
Reply
#7
(09-11-2013, 10:14 AM)Jake Wrote: Ok, I had a look.

The "Set Rotation" option of SplineWalker and MoveAlongSpline custom actions work by setting rotation to Spline.GetOrientation(). This in fact builds the rotation to match the plane defined by the tangent and the up-vector. So to mute a certain axis from rotation, you'll need to zero out that axis from the tangent vector. E.g. to prevent rotation along the x-axis (i.e. tilting camera down/up), just zero out the y magnitude of the tangent and feed the LookRotation then:

(inside CurvyMoveAlongSpline.cs):
Code:
if (SetOrientation) {
                Vector3 tan = mSpline.GetTangent(mTF,p);
                tan.y=0; // no up/down tilting
                go.transform.rotation = Quaternion.LookRotation(tan, mSpline.GetOrientationUpFast(mTF));
            }
Copy&Paste the action into a new custom action (change the class name of course) and use that.


It's always a good idea to roll your own versions of SplineWalker or custom actions for stuff like that. As a benefit you can remove everything you don't need and safe a lot of IF-THEN calls. Perhaps you want to smooth out tilting instead of removing it etc... creating a custom controller is always the best and most performant way (if you're able to code, of course, but most parts can be copy&pasted).

That's the reason I make most of the API public. If a curve related piece of information is there, give the user access to it, you'll never know what he wants to do with it Wink

Jake

Awesome stuff - thanks Jake! Big Grin
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Generated mesh using bezier spline is not following the path accurately processor 3 144 08-25-2020, 04:39 PM
Last Post: _Aka_
  Best practice when Instantiating game object with spline GenericJoe 1 145 08-22-2020, 02:40 PM
Last Post: _Aka_
  How to calculate curvature of spline jh092 3 271 08-01-2020, 04:51 PM
Last Post: _Aka_
  Simple Spline Extrusion GelsonBieber 3 535 07-29-2020, 02:34 PM
Last Post: _Aka_

Forum Jump: