How to get position of a projectile?

Place to get help with not working mods / modding interface.
Post Reply
Kiplacon
Burner Inserter
Burner Inserter
Posts: 10
Joined: Tue Jan 16, 2018 8:14 pm
Contact:

How to get position of a projectile?

Post by Kiplacon »

I have a stream projectile (like spitter acid and flamethrower fire), and when I call for its location with ProjectileName.position it gives me the location where the projectile spawned, no matter where the flying projectile currently is in its arc. Is there a way to get the position of the projectile itself?

PyroFire
Filter Inserter
Filter Inserter
Posts: 356
Joined: Tue Mar 08, 2016 8:18 am
Contact:

Re: How to get position of a projectile?

Post by PyroFire »

How are you getting the projectile to begin with?
There's no on_weapon_fired event.

Also what are you trying to do?

Kiplacon
Burner Inserter
Burner Inserter
Posts: 10
Joined: Tue Jan 16, 2018 8:14 pm
Contact:

Re: How to get position of a projectile?

Post by Kiplacon »

I give the projectile a name when I spawn it like:
global.rock = create_entity ({projectile details})

Then in a different script I want to repeatedly teleport the player to that projectile to simulate motion like:
if (global.rock.valid) then
game.get_player(1).teleport(global.rock.position)
end

But when I run this, it just repeatedly teleports the player to the location where the projectile was spawned instead of to the projectile itself, so the player gets stuck there until the projectile finishes its course.

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5151
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: How to get position of a projectile?

Post by Klonan »

Kiplacon wrote:
Sat May 09, 2020 4:58 pm
I give the projectile a name when I spawn it like:
global.rock = create_entity ({projectile details})

Then in a different script I want to repeatedly teleport the player to that projectile to simulate motion like:
if (global.rock.valid) then
game.get_player(1).teleport(global.rock.position)
end

But when I run this, it just repeatedly teleports the player to the location where the projectile was spawned instead of to the projectile itself, so the player gets stuck there until the projectile finishes its course.
Streams don't have a 'projectile', that is a visual only thing.

You probably want to just calculate the tranjectory on your own:
https://en.wikipedia.org/wiki/Projectile_motion

Post Reply

Return to “Modding help”