#calculate life_time of projectile based on initial speed and range?

1 messages · Page 1 of 1 (latest)

fierce edge
#

Does anybody know how to calculate a timeout time from a distance and a velocity?

bullet.velocity        = player.velocity + Vector2.RIGHT.rotated(player.global_rotation) * weapon.get_stat_speed()
bullet.life_time       = weapon.get_stat_range() / (bullet.velocity.length() * get_physics_process_delta_time())```
vast garnet
#

velocity = distance / time, so time = distance / velocity

fierce edge
#

ty

#

wait isn't that what I am doing?

#

weapon speed is 50 and range is 80

vast garnet
#

should be 1.6 seconds then

fierce edge
#

so if I remove delta time it kinda works but the bullet travels less when I am flying at high speeds

candid obsidian
#

perceived, probably

#

do you mean to extend the range when player velocity is added to the bullet's?

fierce edge
#

no it should fly at the same speed and range relative to the player regardless of the players velocity

#

even I reach max velocity it still is shorter

#

unless I am not combining the velocities correctly

candid obsidian
#

what i think is happening is that if the player is moving fast, the bullet will move faster
meaning that it will have reached its max range sooner (in shorter amount of time)
this isn't necessarily wrong

#

depends on what you want

vast garnet
#

the lifetime should be constant, right? bullet velocity relative to the player is constant

fierce edge
#

idk

#

just a sec let me test it again

vast garnet
#

try lifetime = weapon range / weapon speed

fierce edge
#

I think that worked

#

odd

candid obsidian
#

the effective range will be larger than the range stat like this, if you add the player's velocity to the bullet

#

as-in the actual distance between spawn and despawn will be larger

vast garnet
#

in global terms, yes. but that's how it should be

candid obsidian
#

in global terms, yes

fierce edge
#

like when I am moving at full speed or stopped, this way the bullet gets extra velocity from the player and travels the same range

#

so I think this is good

candid obsidian
#

depends on your game if this makes sense
this could be easily exploited by just tapping a direction before firing to extend the effective range without the player really moving

vast garnet
#

if the player isn't really moving then the additional velocity would be low

fierce edge
#

oh I see what you mean

vast garnet
#

does the player get to full speed instantly?

fierce edge
#

pretty close

#

so I have to choose whether the player can shoot the same range regardless of speed or disallow bullet boosting

vast garnet
#

maybe just accelerate to full speed over a short time

fierce edge
#

that wouldn't work in my game

#

it's action 4 player vs

vast garnet
#

why wouldn't that work?

fierce edge
#

ships would be too slow

#

and boring

vast garnet
#

I mean like 0.1 seconds

#

just so you don't have full speed in the next frame

fierce edge
#

it already takes a whole second to accelerate to max speed

vast garnet
#

ahh okay. then the bullet boosting thing isn't a problem

fierce edge
#

it was still too exploitable

#

I can play test it later

candid obsidian
#

you can maybe sufficiently nerf it by adding recoil

fierce edge
#

oh

#

I will probably do that

candid obsidian
#

i can already picture players going backwards at super speed 😂

fierce edge
#

ik its going to be cool