Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Star Fox Style controls with Curvy Path
I'm tinkering with a rail-shooter prototype using Curvy to generate the rails. However I'm having a slight issue with the controller I'm building for the player's ship. At present I've setup, as shown in the image below, an empty GameObject to act as a tether using the example SplineWalker script to move everyhting along and follow the spline with the SetOrientation option to keep it orientated to the direction/rotation of the spline. I then have another GameObject as a child of this which has the player movement script attached to it, followed by another GameObject to control the banking of the player model and finally the actual player model.

[Image: Unity_Hierarchy_SF_Controls.png]

The issue I have is with my player movement script which uses the following code (taken from Cooking With Unity's StarFox tutorial)

void Update ()

float horizontal = Input.GetAxis("Horizontal")*movementSpeed.x;
float vertical = Input.GetAxis("Vertical")*movementSpeed.y;

Vector3 direction = new Vector3(horizontal,invert*vertical,0);
Vector3 finalDirection = new Vector3(horizontal,invert*vertical,1.0f);

transform.position += direction*Time.deltaTime;

transform.rotation = Quaternion.RotateTowards(transform.rotation,Quaternion.LookRotation(finalDirection),Mathf.Deg2Rad*angleChangeSpeed);

The code that I am trying to modify is.

transform.rotation = Quaternion.RotateTowards(transform.rotation,Quaternion.LookRotation(finalDirection),Mathf.Deg2Rad*angleChangeSpeed);

This line is used to rotate the player model slightly towards the direction of the input, however while the code works as expected in that the player model turns towards the direction of movement, the player model doesn't rotate relative to the spline, see the image below.

[Image: Unity_SF_Controls_01.png]

The effect I am after is for the player model to use this rotation while keeping the orientation of the spline as shown below (this image was taken with this line disabled in the script).

[Image: Unity_SF_Controls_02.png]

I'm guessing that the issue is with providing the orientation of the spline to replace the transform.rotation component in Quaternion.RotateTowards(transform.rotation,Quaternion.LookRotation(finalDirection),Mathf.Deg2Rad*angleChangeSpeed); however I'm not quite sure which CurvySpline function would be the suitable replacement here? Or is there a better way to achieve this with the Curvy API?

Any help/suggestions would be appreciated.


have you tried setting localRotation instead of rotation?
(01-17-2014, 07:30 AM)'Jake' Wrote: Hi,

have you tried setting localRotation instead of rotation?


Thanks for the reply, you were right.


transform.rotation = Quaternion.RotateTowards(transform.rotation,Quaternion.LookRotation(finalDirecti​on),Mathf.Deg2Rad*angleChangeSpeed);

transform.localRotation = Quaternion.RotateTowards(transform.localRotation,Quaternion.LookRotation(finalDirecti​on),Mathf.Deg2Rad*angleChangeSpeed);
has fixed the problem. I think I'd been trying to get too clever and thinking I somehow needed to get a rotation/position from the spline.

Thanks again for replying and helping me out.



Possibly Related Threads…
Thread Author Replies Views Last Post
  Rasterized Path Range issue proton 7 26 04-30-2024, 11:17 AM
Last Post: _Aka_
  Incorrect mesh alignment after extrusion on curved path Thinkurvy 10 21 04-17-2024, 10:57 AM
Last Post: _Aka_
  Curvy Line Renderer for UI Spline? gekido 3 6 04-04-2024, 12:56 PM
Last Post: _Aka_
  8.8.0 is live, and it improves Curvy Generator greatly _Aka_ 1 12 04-03-2024, 03:16 PM
Last Post: _Aka_

Forum Jump: