Spawning object help

Status
Not open for further replies.

MotdSpork

Mafia? Zombies? Gold spork?
So im trying to spawn an object directly behind the player using Lua (regardless of the direction the player is facing) I'm using the function

P_SpawnMobj(player.mo.x, player.mo.y, player.mo.z + 15*FRACUNIT, MT_"insertobjectnamehere")

although...i dont know how to make is spawn..behind the player like i need it to, any help would be much appreciated.
 
To convert a desired angle and distance into x and y positions, use the formulae x = FixedMul(d, cos(a)) and y = FixedMul(d, sin(a)), where a is the angle in ANGLE_X format and d is the distance in FRACUNIT scale. In this case, you can write

local a = player.mo.angle + ANGLE_180
local d = <how far behind the player you want the object to spawn>
P_SpawnMobj(player.mo.x + FixedMul(d, cos(a)), player.mo.y + FixedMul(d, sin(a)), player.mo.z + 15*FRACUNIT, MT_"insertobjectnamehere")
 
Status
Not open for further replies.

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top