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
  Spline Shape not centering around Spline Path tfunitydev 3 121 05-13-2021, 08:50 AM
Last Post: _Aka_
  Activate Curvy Generator After Scene Load jdkirk1 7 281 05-07-2021, 02:14 PM
Last Post: _Aka_
  Is it possible to generate an output spline after the conform path module? 3 277 03-21-2021, 06:37 PM
Last Post: _Aka_
  Error while making prefab having curvy Generator script User2200 3 352 03-15-2021, 07:16 PM
Last Post: _Aka_

Forum Jump: