Hello! I have a model of a turret on a bi-pod, the turret head is attached to a cleverly placed bone which will allow the head to rotate towards an entity of my choosing. I cannot for the life of me figure out the math behind this.
I have however been able to get to the point where the turret head will follow the player if they move around it, but it will not point towards the player if they move above or below, the turret head also moves in the opposite direction if the whole model is flipped upside down.
Here is a picture of the model to get an idea behind the description:
[img_thumb]http://i.imgur.com/pC9tcRC.jpg[/img_thumb]
This is what I've been able to muster up so far, trying to get it to track a position regardless of the current angle the model is at. Any attempts to set the Pitch & Yaw make the head move in precarious directions as I fly around it.
[code]local TargetPos = self.Target:GetPos()
local TurretPos = self:GetPos()
local TurretAng = self:GetAngles()
TargetPos:Sub(TurretPos)
local DeltaPos = TargetPos:GetNormalized()
local DeltaAng = DeltaPos:Angle()
local BoneAngle = Angle(DeltaAng.p-TurretAng.p,DeltaAng.y-TurretAng.y,DeltaAng.r-TurretAng.r)
print(DeltaPos:Angle())
self:ManipulateBoneAngles( 1, Angle(0,0,BoneAngle.y-90) )[/code]
It's crude and probably highly inefficient but I never was a math genius :<
Thank you for your time and any help is always greatly appreciated!
Many thanks in advance.
Hoffa1227 helped me with this much:
[code]local MyPos = self:GetPos()
local TargetPos = self.Target:GetPos()
local MyAng = self:GetAngles()
local TargetAng = ( MyPos - TargetPos ):Angle()
local AngDiff = math.AngleDifference( MyAng.y, TargetAng.y )
MyAng:RotateAroundAxis( self:GetUp(), (AngDiff - MyAng.y) - 90 )
self:ManipulateBoneAngles( 1, Angle(0,0,-MyAng.y) )[/code]
The turret head properly points towards the player as they move around it regardless of the model's rotation, if you flip the model upside down it works until you rotate it while it's upside down.
Does anyone know why rotating the model while it's upside down make the head no longer point to it's target?
Sorry, you need to Log In to post a reply to this thread.