multiple bomb drop code shenanigans

Everything about mods can be found here.

Moderator: Morax

multiple bomb drop code shenanigans

Postby Exotic_Retard » 17 Sep 2016, 19:48

ok soooooooo some IceCreamer asked me to make bombers drop multiple runs of bombs at once. cool. i did it.
Image
the code is even configurable from the unit blueprint so no messy script editing if its not needed
Image
however as you can see in the second picture, the bomb runs spread out. this means my code isnt working properly (


i would like to have some help with working out why this is the case. i suspect its something to do with sideways acceleration on the projectile somewhere but i dont know where that comes from, either that or my physics is failing me now (
https://github.com/FAForever/fa/pull/1513
you can view the code here, all for the glory of equilibrium of course.

i thought it might be useful to post this so that if and when this is fixed it should be flexible enough to use for a variety of bombing run weapons and whatnot. enjoy.

balance terrorists strike again!
User avatar
Exotic_Retard
Contributor
 
Posts: 1470
Joined: 21 Mar 2013, 22:51
Has liked: 557 times
Been liked: 626 times
FAF User Name: Exotic_Retard

Re: multiple bomb drop code shenanigans

Postby Resin_Smoker » 17 Sep 2016, 23:30

Can you link a pastebin as the Githhub link isnt working for me.

Resin
Resin_Smoker
Evaluator
 
Posts: 858
Joined: 14 Mar 2012, 17:58
Has liked: 54 times
Been liked: 106 times

Re: multiple bomb drop code shenanigans

Postby Resin_Smoker » 17 Sep 2016, 23:34

Off hand I'd look at the projectiles release speed. Too fast of a projectile means that its being tossed away from the bomber instead of dropped. Ideal drop speed should be 0 to 2 but never randomized as this would lead to uneven bomb runs.

Resin
Resin_Smoker
Evaluator
 
Posts: 858
Joined: 14 Mar 2012, 17:58
Has liked: 54 times
Been liked: 106 times

Re: multiple bomb drop code shenanigans

Postby KeyBlue » 17 Sep 2016, 23:49

Question: If the bombs spread out, why would the napalm lines, be parallel?
Don't the napalm lines just folow the direction the bombs are going?

I guess you should let the dispersion of the bombs on each line be along the original direction and not along your adjusted direction?

PS: looks nice. And liked your efficiency ;)
User avatar
KeyBlue
Priest
 
Posts: 403
Joined: 28 Jan 2016, 01:06
Has liked: 140 times
Been liked: 93 times
FAF User Name: KeyBlue

Re: multiple bomb drop code shenanigans

Postby Resin_Smoker » 17 Sep 2016, 23:56

KeyBlue wrote:Question: If the bombs spread out, why would the napalm lines, be parallel?
Don't the napalm lines just folow the direction the bombs are going?

I guess you should let the dispersion of the bombs on each line be along the original direction and not along your adjusted direction?

PS: looks nice. And liked your efficiency ;)


This could be the result of the bombs being fired rather then dropped. Now as the bombs that are created are launched in the direction of the weapons "bone" (part of the unit model) they apear to be thrown / ejected from the bomber rather then simply falling to the ground. Hence why they are spread out but remain roughly parallel. The problem will be known once i'm able to read the unit blueprint /script as well as any other modifications he's made. Also be aware that dropped bombs assume the forward momentum of the bomber dropping them. The spread is caused by motion along another vector in combination with the bombers flight motion. (both motion vectors are added together)

Now if i had made this script I'd of opt'd to edit the unit script instead of the blueprint. Thus i'd have the bomber drop extra bombs and offset their initial position and velocity to have more control over the effect.

Resin
Resin_Smoker
Evaluator
 
Posts: 858
Joined: 14 Mar 2012, 17:58
Has liked: 54 times
Been liked: 106 times

Re: multiple bomb drop code shenanigans

Postby KeyBlue » 18 Sep 2016, 01:41

Lol nvm my earlier question. I did not know what i was talking about.
After some coding and testing, i have found the solution to your problem!

The issue was with:
Code: Select all
local velocitychange = VMult(displacement, 1/time)

Due to time changing, this value also changes. But that is ofcourse not what you want. You want the same displacement each time.
So you only need to calculate this value once for each line. And then reuse it for later bombs.

Hope thats what you wanted.

I put my changes into the spoiler tag.
Spoiler: show
Code: Select all
    --add this line at the start somewhere
    --needed because somewhere bomb_data[id] gets set to nil before it reaches your code.
    local current_bd = bomb_data[id]

Spoiler: show
Code: Select all
   
    if bp.BombLineSpread and bp.BombingLines then
        if not current_bd.velocitychange then
            current_bd.velocitychange = {}
        end
        .
        .
        local adjvelocity = DisplaceTarget(proj.vel, (bp.BombLineSpread*i)-offset, time, current_bd, i)
        .

Spoiler: show
Code: Select all
DisplaceTarget = function(vel, disp, time, bomb_d, i)
    --here we will be adding a 2d displacement to our target position, for lots of interesting things.
    --we will be working in 2d, but our vector will be 3d so we can add it easily later.
    --for that we just set y to 0 and call it a day.
   
   
    local velocitychange
    if bomb_d.velocitychange[i] then
        velocitychange = bomb_d.velocitychange[i]
    else
        --local direction = Vector(vel[1], 0, vel[3])
        --[x][z] goes to [-z][x] for right hand and [z][-x] for left hand
        local perpendicular = Vector(vel[3], 0, -vel[1]) --we want to displace perpendicular to the direction our bomb is going in
        local dist = math.sqrt(perpendicular[1]*perpendicular[1] + perpendicular[3]*perpendicular[3]) --the length of our vector
       
        displacement = VMult(perpendicular, (disp/dist)) --obtain unit vector AND scale it in the same line! efficiency!
        --1/dist would be the unit vector, then we just multiply that by disp but we are being cool here.
        velocitychange = VMult(displacement, 1/time) --get the velocity we need to add so we get into the right place. probably.
        --since we are going perpendicular to the bomb path, this doesnt affect CalculateBallisticAcceleration and so we dont need to change the target position.
        bomb_d.velocitychange[i] = velocitychange
    end
   
    local velocity = VAdd(vel, velocitychange) --add our adjusted speed to our projectile speed.
   
    return velocity
end



I just thought about just giving you the file. So i'll add that aswell.
Attachments
CalcBallisticAcceleration.zip
changed file
(2.51 KiB) Downloaded 37 times
User avatar
KeyBlue
Priest
 
Posts: 403
Joined: 28 Jan 2016, 01:06
Has liked: 140 times
Been liked: 93 times
FAF User Name: KeyBlue

Re: multiple bomb drop code shenanigans

Postby KeyBlue » 18 Sep 2016, 11:57

Thinking about it some more, i guess, the real issue is that time wasn't properly calculated.
Its based on the position of the target and not on where you want your bomb to drop.
Time between these two positions can be quite substantial so thats why you see such a big effect.

So to properly fix it you probably have to calculate time differently. My solution was a mere patch job so to speak.
User avatar
KeyBlue
Priest
 
Posts: 403
Joined: 28 Jan 2016, 01:06
Has liked: 140 times
Been liked: 93 times
FAF User Name: KeyBlue

Re: multiple bomb drop code shenanigans

Postby Heaven » 23 Sep 2016, 14:12

Image
User avatar
Heaven
Avatar-of-War
 
Posts: 160
Joined: 20 Feb 2013, 21:27
Location: Gazath-Sonika
Has liked: 1 time
Been liked: 135 times
FAF User Name: Heaven


Return to Mods & Tools

Who is online

Users browsing this forum: No registered users and 1 guest