Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Moving object along spline close to player
#1
Wink 
Hi all! 
Apologies if this is a dumb question I'm still relatively new to Unity. I'd like to move a cube along the spline close to the player so it follows the player as they walk around the spline

Trying to basically copy this
https://www.youtube.com/watch?v=6Yb9kWqYbz0&t=130s

Any help would be much appreciated! I tried my best, messing about with the position slider in the default Spline Controller and that seems to move it around the track perfectly like I want but I'm just struggling with the actually moving it towards the player part. Also tried to extend the SplneController class to make my own but I was having a hard time digging through everything to try to figure out how to even move the cube.

Thank you very much!
Reply
#2
Hi
Take a look at the example scene 05_NearestPoint, I believe it does what you are asking for.
Have a nice day
Please consider leaving a review for Curvy Splines, this helps immensely. Thank you.
Reply
#3
Wink 
(12-23-2021, 10:33 AM)_Aka_ Wrote: Hi
Take a look at the example scene 05_NearestPoint, I believe it does what you are asking for.
Have a nice day

Thank you very much! I was digging through the example scenes but I somehow missed that one
Reply
#4
(12-23-2021, 10:33 AM)_Aka_ Wrote: Hi
Take a look at the example scene 05_NearestPoint, I believe it does what you are asking for.
Have a nice day

Yay! thank you so much I got it working! Now I just have to figure out the rotation and I'll be good any help or even a nudge in the right direction would be appreciated~
https://imgur.com/a/tT5o2Dt
Reply
#5
You can use CurvySpline.GetOrientationFast
Other usefull methods: GetOrientationUpFast and GetTangentFast. Take a look also on the other similarly named methods

I hope this helped
If and when you feel like it, please leave a review for the asset, that helps a lot.
Have a nice day
Please consider leaving a review for Curvy Splines, this helps immensely. Thank you.
Reply
#6
(12-24-2021, 10:21 AM)_Aka_ Wrote: You can use CurvySpline.GetOrientationFast
Other usefull methods: GetOrientationUpFast and GetTangentFast. Take a look also on the other similarly named methods

I hope this helped
If and when you feel like it, please leave a review for the asset, that helps a lot.
Have a nice day

Will definitely! Much appreciate the assistance
Reply
#7
Hiya again!

Sorry for the bother but I'm running into a weird issue with GetNextSegment and GetPreviousSegment I'm at the point where I'm trying to get the player attached to the box and I want to rotate them around the ledge by being attached to the box. 

Currently if I use GetPreviousSegment it works fine and my character spins around the box at light speed in the reverse direction, skipping CP0
If I do GetNextSegment however, they make it to CP0 and then it just stalls and the character won't move around anymore.

I tried using GetNextControlPointUsingFollowUp as well but it still got hung up on the same spot

Apologies for the spaghetti code I was planning on cleaning it up much more once I got it actually working haha

Code:
IEnumerator ShuffleLeft(float waitTime){     var lookPos = transform.position - player.transform.position;     lookPos.y = 0; //lock     if (lookPos != Vector3.zero){ //need this to fix an error being spammed     var rotation = Quaternion.LookRotation(lookPos);         }     nearestTF = Spline.GetNearestPointTF(transform.position, Space.World);                  nearestTFSegment =  Spline.TFToSegment(nearestTF);     CurvySplineSegment nextSegment = Spline.GetPreviousSegment(nearestTFSegment);     float nextTF = Spline.SegmentToTF(nextSegment);     Debug.Log(Spline.GetNextControlPoint(nextSegment));         Quaternion nearestOrientation = Spline.GetOrientationFast(nextTF, false,Space.World);         transform.rotation = nearestOrientation;             ledgeHitBoxPosition = Spline.Interpolate(nextTF, Space.World);         transform.position = ledgeHitBoxPosition;       player.transform.position = new Vector3(ledgeHitBoxPosition.x,ledgeHitBoxPosition.y-1.185749f,ledgeHitBoxPosition.z);// moves the player vertically into place     playerNearestOrientation.Set(player.transform.rotation.x,nearestOrientation.y,player.transform.rotation.z,1);     lookPos = transform.position - player.transform.position;             rotation = Quaternion.LookRotation(lookPos);             player.transform.rotation = Quaternion.Slerp(transform.rotation,rotation,0f);             player.transform.Rotate(11,-90,-180); //rotation offset             yield return new WaitForSecondsRealtime(waitTime);             shuffling = false; }

--Edit-- nevermind sorry for the bother but I managed to get it working in a very silly way by taking use of the built in spline controller to handle smoothly moving it works now! if you have a better way that i should have done it i still would like to hear tho
Reply
#8
Hi
Glad that you solved the issue.
Spline Controller is the best fit for most use cases where you want an object to follow a spline.
If you have any specific question, and that looking at the documentation and example codes did not answer that question, feel free to ask me about it.
Please consider leaving a review for Curvy Splines, this helps immensely. Thank you.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Spline Issue Leading to Unity Freeze Pankaj09 1 518 08-24-2026, 11:28 PM
Last Post: _Aka_
  Connecting Multiple Spline Nodes Issue Ritesh Kadam 1 476 08-22-2026, 11:24 PM
Last Post: _Aka_
  Spline Spots from 2 samples. BitBlit 8 1,811 06-30-2026, 11:49 AM
Last Post: _Aka_
  Best way to duplicate a spline with an offset Kapistijn 8 3,209 04-12-2026, 03:18 PM
Last Post: _Aka_

Forum Jump: