- Home /
Path Controlled Character and Working With Physics on iTween
edited:
I'm completely re-wording the same question. Below, there's the original question.
Now the title is pretty self explanatory and it's basically pointed towards iTween and Bob Berkebile:
Can we mix both Path Controlled Character and Working With Physics at same time?
The result should be something similar to what I did in my portfolio (in case the first link ever breaks, this second should have one updated) but except not using any hacks like I did and once it's applied to the character (like it is) it would be applied to every other rigidbody (yes, Lerpz is a rigidbody there).
original:
physics objects in a curved 2d plane
Imagine a 2D platform game, with objects interacting physically. You would usually constrain it, making every transform.z = 0, just like the 2D Platform Demo.
Now imagine that 2D plane distorted, like a paper. There's no fixed axis and rigidbody objects are still stuck in one line, but it's curved rather than straight. Their rotation should follow that curve. It's just a twist on the platform, in the Z axis.
What would be the best way to do this in Unity? Could I build a path for them to follow? How? I still couldn't figure any way! And I believe this might be a simple answer.
( tags I couldn't create: physics curved plane path line )
edit: here are some pictures from the forums.
Here's something that illustrates almost exactly what I needed back then, except picture it with physics for both player and objects. - Too bad I still couldn't find time to give it a shot: http://www.pixelplacement.com/itween/examples.php look for Path-constrained Characters.
Answer by Horsman · Jan 30, 2010 at 01:23 AM
I misinterpreted your question the first time. I think you want the following:
The XY plane is now a curved surface, not on the groud, but the plane itself. You want objects to follow this curve.
There are two good ways of doing this: take the curve data from a model, or take the data from a spline.
If you are using a mesh, just create a single triangle strip in the shape of the curve, with the faces pointing towards the camera. Use the normal of the triangles in the strip to set the objects positions. Of course, the curve will need to have high resolutions or teh curve will look jagged as the characters move forward. You could interpolate the normals to get a smoother appearance of movement.
if you use a spline, you'll need to know a little about splines first.
http://www.unifycommunity.com/wiki/index.php?title=Interpolate
is a good way to generate some catmull rom splines. From there, use the forward direction of any point you generate on the spline as the new forward direction of your character. You might want to squash the up vector of each of those points first.
Yes, that is precisely the two ideas I've been trying. I actually started with a mix of both: http://www.unifycommunity.com/wiki/index.php?title=Spline_Controller
But I was hoping for some completely different approach.
Because the problem here is how to not affect the physics. On a 2D plane just setting the Z axis to zero works fine, but on this curved I'm still trying to figure it out.
I just know it will need to both get the point direction AND adjust the position. To do so, I need to know how find out which "any" point to use. That's when I got stuck.
Ins$$anonymous$$d of parameterizing the object's position based on x and y coordinates, use the y coordinate and the ud coordiante.
The ud coord is the distance in units travelled on the spline in the forward direction. To do this, the spline you have must be parameterized by distance since most splines do not trace equal distance for equal spline parameter. Search for arc-length parameterization for 3-d curves to get the jist of it.
A functional way to build a arc-length parameterization is by integrating the distance along the curves in small chunks and them perfor$$anonymous$$g a lookup and using a bit of interpolation to make it smooth.
I couldn't manage to use those Interpolation functions to solve this, and I'm no maths graduate to go too deep into that stuff... I don't want the curves or edges to have more weight (of dots) than the lines. They should be all equally distributed and the curves should be just a little bit smooth - so it won't disrupt the physics and it will look like it's linear. It's just a visual effect of deepness. Right now I'm trying to adapt the spline-controller to do that.
Your answer
Follow this Question
Related Questions
Implement 2D movement in a 3D environment while retaining physics 2 Answers
iTween Path 2D rotation, orientToPath issue. 1 Answer
Using Itween with Unity 2D, sprite flips over while using orienttopath 1 Answer
[SCREENSHOTS] itween Path, orientToPath and gameObject rotation, 2D game 3 Answers
HOW DO I USE RAYCASTHIT 2D???? 1 Answer