Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Collision along spline
#1
I need objects moving along the spline to be able to collide with things along the spline and stop.  However, the FollowSpline script hard-sets the position on each update rather than using Unity's translation, so objects simply phase through each other as if they weren't there.

Is there an easy way to implement this that I'm simply overlooking?  Any advice would be appreciated.
 
edit: I'm currently adjusting the UpdateAbsolutePrecise function to do translation the old-fashioned way (Translate(newposition-oldposition)), but it seems by doing it this way, certain essential variables like CurrentTF don't get updated.
Reply
#2
hi Keladinus,

In Refresh() you could do a raycast and set speed and/or position according to the collision result.

Does that help,

Jake
Reply
#3
After messing around with FollowSpline functions for the last few days, the solution I decided to resort to was a simple OnCollisionEnter flag in my custom controller that sets the speed to negative if blocked.  I'll probably experiment a bit further with it, but it seems to be working the way I need it to.  Thanks anyway!
Reply
#4
Okay, so I might need a little more help, and I suppose my situation requires some more explanation.

What I'm attempting to set up is a 2.5D Sidescroller controller which travels along a Curvy spline.  Like a sidescroller, the character can move only forwards and backwards, however, unlike traditional sidescrollers, this movement isn't simply restricted to two axes, but is rather constrained along a spline.  At least, that was the theory.  The camera moves along its own spline, and it travels along its spline relative to the player's position on his spline. (If that made any sense whatsoever.)

I've almost got it set up perfectly - it was easy enough to remove the restriction on the Y axis to allow the player to jump, and the camera is set up correctly.  Pressing forwards sets the followspline script's speed forwards, backwards backwards.

The only problem is, as I stated earlier, collisions don't seem to work along the spline.  The player can hit things above or below him, since that movement isn't handled by the Followspline script, but anything else the player just goes through.  I set up something of a solution by creating an onCollisionEnter flag, but rubbing against things feels glitchy, with the player twitching back and forward.  What I need is for the player simply to be stopped, the way he would be if it was a simpler 2D controller.

The trouble is, I don't understand why I'm able to phase through objects at all.  As far as I can tell, what I'm doing isn't much different from a simple transform.Translate() - the only difference is that the FollowSpline tracks the player's TF and CurrentSegment.  Sure, there's some fancy calculations in getting the target translation, but other than that...?
Reply
#5
Update:  After a lot of fiddling with ifs and elses, I've got the collision more or less replicating what normal 2D rigidbodies do.  I can no longer grind against objects like I could before.  However, I'd still like some help with understanding why this is necessary.  Why does the FollowSpline's functions allow objects to pass through one another, even if they have rigidbodies attached?
Reply
#6
The reason is simple: the FollowSpline component doesn't care about rigidbodies. It just sets the object's transform based on the given spline position and speed. Setting the transform of a physics controlled object breaks the physics simulation, so you'll have to either make it kinematic or apply forces.

You may want to skip the whole FollowSpline component and just add the relevant API calls to your physics controller script (the script where you handle input, collisions etc.). It's quite simple to get a spline's values (position, tangent, up-vector) or advance (i.e. move) a position using a certain speed, just simple API calls. See http://docs.fluffyunderware.com/curvy160/api.html for an overview.

For Curvy 2.0 I'll try to setup some more FollowSpline variants, but a custom solution is always better than a multi-use component (total control, less overhead).

Let me know if you need help with the API, but you really should give it a try - it's simple but powerful.
 
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Absolute distance along spline for Shape Extrusion Module amutp 3 203 10-31-2021, 10:26 AM
Last Post: _Aka_
Question Generating a path from selected point to the beginning of spline on a closed spline? Zendariel 5 314 10-29-2021, 01:57 PM
Last Post: _Aka_
  Controller/Spline flipping object topquarkone 4 284 10-28-2021, 05:02 PM
Last Post: _Aka_
  How to find out whether the spline is self-intersected. mydayz 1 184 10-19-2021, 12:08 PM
Last Post: _Aka_

Forum Jump: