Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Star Fox Style controls with Curvy Path
#1
Question 
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)

Code:
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.

Code:
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.

 
Reply
#2
Hi,

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

have you tried setting localRotation instead of rotation?


 

Thanks for the reply, you were right.

Changing 


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


Code:
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.

 

 
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Curvy Line Renderer for UI Spline? gekido 0 1 4 hours ago
Last Post: gekido
  snap to the curve created by the curvy splines segment points ShiroeYamamoto 0 1 9 hours ago
Last Post: ShiroeYamamoto
Exclamation Extending Curvy Generator for Advanced Lofting - Feasibility Check amutp 2 4 Yesterday, 07:25 AM
Last Post: amutp
  8.8.0 is live, and it improves Curvy Generator greatly _Aka_ 0 6 Yesterday, 03:23 AM
Last Post: _Aka_

Forum Jump: