[Closed] direction based on position cahnges
suppose we have an object at pos [10,50,0] in frame 0 and in next frame it moved to [20,60,0]
how can i get the direction of that position change so i can orient the object to it ( as in path constraint)
i want to do this in my car rig so as the aimator moves the car body from frame to another the body auto orient itself
i used the formula of (atan (delta x/delt y)) to get the angle from frame to another it worked fine but it produced flipping at some points , so any clues?
ok when i put it on single one axis i got flipping coz i had to transform it into eulerangles so u=i had to have it on scripted rotation controller and assign the object into another object rather than the actual object i want to work on and that object should be the parent of the object i want to work on lets say more clearly :
i want the object A to redirect according the position change so i link it to object B and i put on A scripted rotation controller and fill it with the following code
curr=at time (currenttime) objc.pos
prev=at time (currenttime-1) objc.pos
up=objc.dir
vec=curr-prev
thrd=cross up vec
mtrx=matrix3 up vec thrd curr
rot=(mtrx).rotationpart
where objc here is objc B it works fine except two things
first:the object A is inverted NOT FLIPPED
second :i have to change the position of object B not A as suuposed so any guidence?
What if objc.dir value is in the same direction as its vector from its (currentTime-PreviousTime)?
Also after you derive the cross product from the vec and objc, your not orthogonalezing it. You need to ratify that the dir value is perpendicular to the vec.
z = normalize (currentVal - previousVal)
x = <node>.dir
y = cross z x
x = cross y z
(orthogonalize (matrix3 x y z)).rotation
i didnt normalize the vector up ther in the code posted , however i did normmalized it and still have troubles
thats so reasonable eek but it seems not to work u may follw with me via this procedures :
1-create teapost
2-freeze transform
3-select z track in second rotation layer
4-apply script controller
5-enter that
curr=at time (currenttime) objc.pos
prev=at time (currenttime-1) objc.pos
up=normalize objc.dir
vec=normalize (curr-prev)
thrd=normalize (cross up vec)
sec=normalize (cross thrd vec )
mtrx=matrix3 sec thrd vec curr
rot=(orthogonalize mtrx).rotationpart
rot.z
where objc is the teapot itself
6-with animation button turned on make little animation based on positions not rotations
7-turn on trajectory display and watch
it doesnt follow the direction of the line (rotationally) and i take that from the spout of the teapot direction
so wat could be else the solution
BTW i tried to reorder vectors in matrix creation line and didnt work either
ok now i have something that worked for me so far
i did the procedures i mentioned earlier and put the expression on z-track of rotaion the following expression
curr=at time (currenttime)in coordsys world objc.pos
prev=at time (currenttime-1) in coordsys world objc.pos
up=normalize (in coordsys world objc.dir)
vec=normalize (curr-prev)
thrd=normalize (cross up vec)
sec=normalize (cross thrd vec )
mtrx=matrix3 thrd sec vec curr
rot=(orthogonalize mtrx).rotationpart as eulerangles
degtorad (90+rot.z )
it worked very fine with my teapot test thing i have my car set up completed and i will try to add this to it by tomorrow as i get to the work and i think that will be helpful in auto steering , but if smebody knows anything better it would be great
it works fine in “inbetween” animation other than this the starting and end points i get flipping any help? im reaaly tired of trials