object moves, always looking to direction of movement?!
Hi
I have an object moving along a curved path. [jit.gl.sketch]
Now i want that object always looking in the direction of movement.
I use:
[cartopol] --> [expr ($f1 / 3.1415926) * 180.] --> (shapeorient $1 $2 0.) --> [jit.gl.sketch]
Only X and Y change Z axis stays 0.
I can't get it working properly.
What am i missing here?
Nobody can help me out, point me to the good direction to look?
Hey, so the problem you are trying to solve is to find direction between two points in 3D space (or in your case 2D space) as a (signed?) angle (is this the correct term? Angle of slope? Whatever...).
So basically you need atan2 (which is atan(q)x/y).
Pardon the rough patching... I spent way more time on this than I have free right now...
Sorry I didn't explain correctly, the issue is that first you need to find the slope angle from the last known point to the current point, not just from 0,0 (which I *think* is what cartpol is potentially doing in your patch().
For this kind of thing, I have had excellent results using the Cosm objects.
@cap10subtext: Thanks, it works now very well. I had already tried with [atan2] but had forgotten to inject the position A again to turn the object. Stupid me.
@Andrew Benson: I have checked the Cosm objects and sure i can do it with these objects, but i first want to find a solution with the original Max objects. Thanks.
Cosm = da bomb and Graham (and everyone else who's worked on them) has done AMAZING work with the example patches to help with this. But the principle is the same. I've always been rusty on the math so now, to understand what the patches are doing in Cosm I find I have to build it and work out the math myself once or twice so i can understand what's going on.
In this case, even I'd forgotten that you had to determine from the new position at first. So, not stupid. Now we both know!