I have a turret model with a rotating weapon. The weapon is rotated with pose-parameters to set it's Pitch and Yaw respectively.
The following code works when the entity is flat on the ground however if you rotate the entity and place it upside down on the ceiling or sideways on the wall the rotation is no longer accurate.
function ENT:PointToTarget()
local BaseAng = self:GetAngles()
local HeadPos, _ = self:GetBonePosition( 3 )
local TargetPos = self:GetTarget():GetPos() + Vector(0,0,36)
local TargetAng = ( HeadPos - TargetPos ):Angle()
local DiffP = math.AngleDifference( TargetAng.p, BaseAng.p )
self:SetPoseParameter( "Aim_Yaw", (TargetAng.y-BaseAng.y)+180 )
self:SetPoseParameter( "Aim_Pitch", DiffP )
end
I'm not sure how to manipulate the value passed to Aim_Yaw to account for the entity itself having the pitch and or roll changed due to players placing the entity upside down on the ceiling or sideways on the wall. I would like the weapon to rotate properly no matter what position players place the turret in.
I know how. One second.
Oh and just edit it to divide by 2, i didn't see that in your explanation.
Convert the TargetAng, using Entity:WorldToLocalAngles( Angle ).
Mine uses less cpu >v>
Mine can be smoothed too.
function ENT:PointToTarget()
local HeadPos = self:GetBonePosition( self:LookupBone( "bone_base" ) )
local TargetPos = self.Target:GetBonePosition( self.Target:LookupBone("ValveBiped.Bip01_Pelvis") )
local TargetAng = self:GetPhysicsObject():WorldToLocalVector( TargetPos - HeadPos ):Angle()
local pitch = TargetAng.p*0.75 + (self.Last_Pitch or 0)*0.25
local yaw = TargetAng.y*0.75 + (self.Last_Yaw or 0)*0.25
self.Last_Pitch = pitch
self.Last_Yaw = yaw
self:SetPoseParameter( "Aim_Pitch", pitch/2 )
self:SetPoseParameter( "Aim_Yaw", math.AngleDifference( yaw - 90 )/2 ) --Subtract 90 to account for model compiled 90 degrees rotated
end
Smoother than lerpangle. or just use lerpangle TargetAng if u wanna.
Unfortunately I have looked at all the tf2 turrets and their aim_yaw parameter does not go around in 360 degrees, it's limited to about -44 and +44 degrees.
I know the turret has a full 360 range of yaw rotation though. Are you sure you didn't look at the pitch?
No I'm not 100% positive since I used a tool inside gmod to show me the pose parameters and their values.
I did figure out though that my twitching issue is due to the fact that i'm having to divide the yaw value by 2. Dividing by 2 means, when I set the pose-parameter, the value never has the chance to pass from -180 over to 179 or vise versa. I'm only ever sending -90/+90 and when i move from +90 over to say -89 it has to snap though half of the animation resulting in that twitch.
Sadly, I don't know why the model is forcing me to divide and multiply the parameters by 2 for the rotations to work properly. Inside HLMV everything seems to look fine however inside gmod the turret head spins around 2 full revolutions when we run around it in a circle.
https://youtu.be/Sh5fm8F8siE
Here you can see in-game 2 revolutions and inside HLMV 1 revolution. Not sure where the disconnect here is..
Post the .qc? Maybe it is the the mdlstudio compiler version you're using
$modelname "kklouzal/cannons/floor"
$scale 0.7
$body Tripod "floor_tripod_base"
$surfaceprop metal
$origin 0 0 0
$cdmaterials "models/kklouzal/cannons"
$poseparameter "Aim_Pitch" -180180 loop 0
$poseparameter "Aim_Yaw" -180 180 loop 360
$animation Delta "floor_animations.smd"
$animation Idle "floor_animations.smd" {
subtract Delta 0
frames 0 0
fps 30
}
$animation Aim_Left "floor_animations.smd" {
subtract Delta 0
frames 8 8
fps 30
}
$animation Aim_Back "floor_animations.smd" {
subtract Delta 0
frames 9 9
fps 30
}
$animation Aim_Right "floor_animations.smd" {
subtract Delta 0
frames 10 10
fps 30
}
$animation Aim_Down "floor_animations.smd" {
subtract Delta 0
frames 11 11
fps 30
}
$animation Aim_Up "floor_animations.smd" {
subtract Delta 0
frames 12 12
fps 30
}
$sequence Aim_Yaw {
blendwidth 5
blend Aim_Yaw -180 180
delta
autoplay
Idle Aim_Left Aim_Back Aim_Right Idle
}
$sequence Aim_Pitch {
blendwidth 3
blend Aim_Pitch -180 180
delta
autoplay
Aim_Down Idle Aim_Up
}
$bodygroup Head
{
studio "floor_head_cannon.smd"
studio "floor_head_shock.smd"
studio "floor_head_minigun.smd"
studio "floor_head_flamethrower.smd"
}
$Sequence Fire {
"floor_animations.smd"
fadein 0.2
fadeout 0.2
fps 30
frames 0 7
}
$attachment "muzzle" "bone_flash" 0 0 0 rotate 0 0 0
$collisionmodel "cannon_floor_phys2"
{
$mass 100
$concave
}
Don't mind these lines like "blend Aim_Pitch -180180" the code tag removes the space between -180 and 180 making it appear as -180180. I assure you the space is there.
Looks like you modeled if after the example on valve developer wiki, which doesn't look right. I'll look at the tf2 turret .qc one when I get home and correct the wiki if it it is wrong.
Looks like tf2 turret uses
$controller 0 "Dummy02" YR 0 360
$controller 1 "Dummy05" ZR -90 15
Maybe that would work better
Sorry, you need to Log In to post a reply to this thread.