Page 1 of 1

math.atan2

Posted: 31 Jul 2014, 12:17
by PicassoCT
Im tryint to y-turn a units leg towards a point..(both are in worldspace) .. so i assumed using math atan2 i could get the degree in rad where to turn the leg.
However this did not work out.
What was the magic dance one had to do, to get spring, to behave correct?
Did i miss out on one step?

Code: Select all

	
function resolveKinematics(x,y,z,  tPx,tPy,tPz, lorgx,lorgy,lorgz, number,targPoint)

	zvx,zvy,zvz=tPx-lorgx,tPy-lorgy,tPz-lorgz
			
		Norm=math.sqrt(zvx*zvx+ zvy*zvy)
		yaw=math.atan2(zvz, Norm)

		Turn(StriTable[number].UpLeg,y_axis,yaw,0,true)
Image

Re: math.atan2

Posted: 31 Jul 2014, 17:19
by Peet
atan2(dz, dx), assuming the leg is aligned with the x axis

Re: math.atan2

Posted: 31 Jul 2014, 18:53
by PicassoCT
Peet to the rescue.. unfortunatly its not working..

Is there something im missing.. some magic variable.. i m using rad.. so i thought everything was okay..

Image

Image

Image

Thanks to anybody investing his time.

Re: math.atan2

Posted: 03 Aug 2014, 11:08
by PicassoCT
Solved:

Scholars of a future far - in order to turn a leg perfect towards the worldcoords, you need thus:

Code: Select all

	Turn(Leg,y_axis,math.rad(180)-(math.rad(currentHeadingInDeg)+math.rad(-90)+yaw),..
The +90 is to get math.atan2 to line up with the world coord system...
- currentHeadingInDeg undos the rotation of the unit
- yaw = math.atan2(worldz,worldx) (thanks to Peet)
the 180 i dont know why those are needed, but it works... its a lapsus of faith..

Thanks to everyone helpin