- Home /
How do I get the 2.5d platformer's rigidbody physics to follow a path?
Hi,
I'm using itween's PutOnPath function to place the character on a path but I'm not sure how I can get collision detection working for the character and restrict physics to a path. Is that possible?
Example of problem:
http://www.atomk.com/twofived/twofived.html (boxes have rigidbodies attached, but only travel on the X axis)
Should I just raycast from the character to detect collisions instead? I am not sure what's an adequate approach to this problem.
Answer by pixelplacement · Jan 31, 2011 at 12:46 AM
I'd recommend the raycast route on this one. I really like the way this works - it's inspiring to see your work evolve and I appreciate you sharing this. If you can't figure out a suitable solution to this let me know and maybe I'll take another look.
Thank you so much! Your comments mean a lot to me. I appreciate it :) Yeah, I will go with the raycasting approach for the character collision detection.
For restricting the physics to the path, I tried locking the Z of the objects to the path, but I am stuck trying to figure out how to calculate the percentage that the object is on the path. Do the percentages match if I just choose the point that is closest to the object and try to figure out the percentage from that?
Answer by Aurelio Provedo · Apr 07, 2011 at 10:01 AM
Hello there
Did you find a solution for this? It looks like I'm making just the same type of game you are, and stumbled upon this question.
I have also thought about finding out the closest point on the spline for the point that the rigidbody is at, and then setting its pointOnPath to that amount. Then on every FixedUpdate set the body's position to that PointOnPath. I might have the ClosestPointOnPath method done by this evening.
I also considered overriding OnCollisionEnter. But with only the contacts list and the relativeVelocity information, it would be too difficult for me to implement a collision constraint to the path.
So, any progress? Anything you can share?
Ahhh wow. I have never found a solid solution for this, so I just worked around it. I thought about it and if I took this route, the physics would still look "jerky" because of it trying to correct itself. If you found a solution though then that's awesome!
I was doing some tests yesterday. In FixedUpdate, I do the following: Get the body's velocity magnitude on the XZ plane - movement in Y axis is not affected by the path in my game. Get the world position of the point on the path at the body's position + the XZ velocity magnitude. * $$anonymous$$ake the body's velocity point towards that world position.
This seems to work better than expected. I didn't have time to make many tests, though, particularly not collisions.
Is there any way you could show me your code for this. I have been trying to do exactly the same thing for the last few days and only realised I could use the iTween method today. I would really appreciate any help and will do all I can to help in return.
Your answer
Follow this Question
Related Questions
Strange physics, rigidbody, iTween activity 1 Answer
Kinematic rigidbody with interpolation issue 0 Answers
Prevent rigidbody being affected by character controller 2 Answers
Prevent player from "Running Over Top Of" specific colliders. 0 Answers
Rigidbodies won't collide if mass difference is too high 0 Answers