Raised This Month: $ Target: $400
 0% 

Home projectiles to target


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kNowo
Senior Member
Join Date: Apr 2011
Location: Malaysia
Old 03-02-2015 , 13:07   Home projectiles to target
Reply With Quote #1

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?
kNowo is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 03-03-2015 , 01:13   Re: Home projectiles to target
Reply With Quote #2

Um. I would be thinking the angle at which the rocket can turn while tracking needs to be smaller.

Really not sure.
__________________
Neuro Toxin is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:10.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode