Jump to content

How to speed up a homing missile?


Swimer

Recommended Posts

I created rockets (type 20) using the createProjectile function. But the force in this function only affects throwable objects. Setting velocity at launch or during flight is also useless. Perhaps it makes sense to set the velocity forcibly when calling the function (the last 3 arguments, before the last), but in this case, you need to somehow calculate the velocity for x, y and z. If my version is the best, then you can tell me how to calculate the velocity relative to 2 points. I suppose that I need to get the direction (for example, up: 0, 0, 1, left: 1, 0, 0, etc.) and this direction will be the desired velocity, but I tried this option, although it did not work:

local x1,y1,z1 = 1, 2, 3 -- for example
local x2,y2,z3 = getElementPosition(object)

local directionX, directionY, directionZ = x1 - x2, y1 - y2, z1 - z2

createProjectile(localPlayer, 20, x1, y1, z1, 1, object, 0,0,0, directionX, directionY, directionZ)

When using this method, the rocket simply flew somewhere (with the inversion of direction, roughly speaking, the same thing)

 

There is an option to simply launch a regular missile (NOT homing) at the player's position (or a little further), but such a missile is incredibly easy to dodge by gaining the height of the fighter. POSSIBLY, I could implement this if I could change the flight path (for example, a callback when flying each unit up, with the ability to change the trajectory, but if I'm not mistaken, such a callback cannot be done)

 

Let me remind you, I just need to increase the speed of the rocket

Edited by Swimer
Link to comment

Setting their initial velocity appears to work mostly, however, missiles gain speed very quickly on their own, try spawning one with 0 initial velocity, to a speed between 0.5 to 2 greater than target speed - I've tested with the target aircraft at default max speed of 1.5, the missiles follow with just around 2.8 speed. If the target aircraft is at speed 3, missiles follow it with velocity of up to 4.5.

If you want to target a missile at a particular location, you can, as you said yourself, calculate that from two positions:

local initialPosition = Vector3(0, 0, 0)
local targetPosition = Vector(300, 300, 0)
local differenceVector = targetPosition-initialPosition
local directionVector = differenceVector.normalized
local missileInitialSpeed = 1
local missileDirectionVector = directionVector * missileInitialSpeed
21 hours ago, Swimer said:

(for example, a callback when flying each unit up, with the ability to change the trajectory, but if I'm not mistaken, such a callback cannot be done)

You do not necessarily need any callbacks, you can change any element's velocity at any point. If you want to implement your own guidance system, you can adjust missile positions on the client side every frame, every 2 frames, etc. with onClientRender and either a loop of all missiles, a loop of missiles in a table, or just selecting a particular missile with single variable. Projectiles can also store element data if necessary.

Edited by Addlibs
  • Like 1
Link to comment
54 minutes ago, Addlibs said:

Setting their initial velocity appears to work mostly, however, missiles gain speed very quickly on their own, try spawning one with 0 initial velocity, to a speed between 0.5 to 2 greater than target speed - I've tested with the target aircraft at default max speed of 1.5, the missiles follow with just around 2.8 speed. If the target aircraft is at speed 3, missiles follow it with velocity of up to 4.5.

If you want to target a missile at a particular location, you can, as you said yourself, calculate that from two positions:

local initialPosition = Vector3(0, 0, 0)
local targetPosition = Vector(300, 300, 0)
local differenceVector = targetPosition-initialPosition
local directionVector = differenceVector.normalized
local missileInitialSpeed = 1
local missileDirectionVector = directionVector * missileInitialSpeed

You do not necessarily need any callbacks, you can change any element's velocity at any point. If you want to implement your own guidance system, you can adjust missile positions on the client side every frame, every 2 frames, etc. with onClientRender and either a loop of all missiles, a loop of missiles in a table, or just selecting a particular missile with single variable. Projectiles can also store element data if necessary.

I give you a BIG thank you! I've been struggling with this problem for 4 days now! You helped me a lot, I thank you!

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...