Forums > Jitter

object moves, always looking to direction of movement?!

Mar 25 2011 | 12:24 pm


I have an object moving along a curved path. []
Now i want that object always looking in the direction of movement.

I use:
[cartopol] –> [expr ($f1 / 3.1415926) * 180.] –> (shapeorient $1 $2 0.) –> []

Only X and Y change Z axis stays 0.

I can’t get it working properly.
What am i missing here?

-- Pasted Max Patch, click to expand. --

Mar 30 2011 | 6:24 pm

Nobody can help me out, point me to the good direction to look?

Mar 31 2011 | 3:59 pm

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…

-- Pasted Max Patch, click to expand. --

Mar 31 2011 | 4:01 pm

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().

Mar 31 2011 | 5:20 pm

For this kind of thing, I have had excellent results using the Cosm objects.

Apr 02 2011 | 9:23 am

@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.

Apr 03 2011 | 4:07 pm

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!

Viewing 7 posts - 1 through 7 (of 7 total)

Forums > Jitter