I scraped this little snippet off other threads about homing projectiles. Everything works perfect except the fact that the rocket does not circle the target it's homing to. It just go straight towards the target.
Code:
Projectile_TurnToTarget(iEnt, iTarget)
{
new Float:flTargetPos[3], Float:flEntPos[3], Float:flEntVel[3], Float:flEntSpeed
GetClientAbsOrigin(iTarget, flTargetPos)
GetEntPropVector(iEnt, Prop_Send, "m_vecOrigin", flEntPos)
GetEntPropVector(iEnt, Prop_Data, "m_vecVelocity", flEntVel)
flEntSpeed = GetVectorLength(flEntVel)
flTargetPos[2] += 30 + Pow(GetVectorDistance(flTargetPos, flEntPos), 2.0) / 10000
new Float:flNewVel[3], Float:flNewAngle[3]
SubtractVectors(flTargetPos, flEntPos, flNewVel)
NormalizeVector(flNewVel, flNewVel)
GetVectorAngles(flNewVel, flNewAngle)
ScaleVector(flNewVel, flEntSpeed)
TeleportEntity(iEnt, NULL_VECTOR, flNewAngle, flNewVel)
}
This second code does make the rocket circle its target, but that's all it does. Even when the target stood still, the rocket is still circling and not hitting the target.
Code:
Projectile_TurnToTarget2(iEnt, iTarget)
{
new Float:flTargetPos[3], Float:flEntPos[3], Float:flEntVel[3], Float:flEntSpeed, Float:flTargetDirection[3]
GetClientAbsOrigin(iTarget, flTargetPos)
GetEntPropVector(iEnt, Prop_Data, "m_vecOrigin", flEntPos)
GetEntPropVector(iEnt, Prop_Data, "m_vecVelocity", flEntVel)
flEntSpeed = GetVectorLength(flEntVel)
flTargetPos[2] += 45
MakeVectorFromPoints(flEntPos, flTargetPos, flTargetDirection)
AddVectors(flEntVel, flTargetDirection, flEntVel)
NormalizeVector(flEntVel, flEntVel)
new Float:flEntAngle[3]
GetEntPropVector(iEnt, Prop_Data, "m_angRotation", flEntAngle)
GetVectorAngles(flEntVel, flEntAngle)
ScaleVector(flEntVel, flEntSpeed)
TeleportEntity(iEnt, NULL_VECTOR, flEntAngle, flEntVel)
}
Vectors and scalars have always been my weak point, so I can't do this. Can someone fix this for me?