Teleporting Player to Object Issue

WellDoneSnake

Yoko Shimomura
Recently I've had a problem with teleporting the player to a moving rocket object.
Using P_TeleportMove, I would have the player teleport to the rocket's x, y and z position.

However, for some odd reason the player automatically begins to descend with the rocket at the start of the ride. Furthermore the rocket's capped z-momentum becomes inaccurate, you are able to move downwards faster than you would move upwards.

I've posted the script below, it is quite long so I highlighted the parts in BOLD that I know affects the rocket or player's momz:
Code:
local function RocketStart(rockspawn, mo)
	local player = mo.player
	//Player will be unable to pickup another rocket during their flight.
	if (player.pflags & PF_ROPEHANG) return end
	local rocket = P_SpawnMobj(rockspawn.x, rockspawn.y, rockspawn.z, MT_ROCKET)
	rocket.target = mo
	mo.cusval = 0
	P_ResetPlayer(player) -- Reset player, disabling any actions.
	player.pflags = $1 | PF_ROPEHANG
	mo.flags = $1 | MF_NOGRAVITY -- Player can stay airbourne
	mo.flags = $1 | MF_FLOAT -- PLayer can change their height
end
addHook("TouchSpecial", RocketStart, MT_ROCKETSPAWNER)

//Alter the player's custom value if they have jumped during flight
addHook("JumpSpecial", function(player)
	if (player.pflags & PF_ROPEHANG) and not (player.pflags & PF_JUMPDOWN)
		player.cusval = 1
	end
	return false
end)

local function RocketFlight(rocket)
	local mo = rocket.target
	local player = mo.player
	mo.state = S_PLAY_CARRY
	
	//Values relating to the rocket's momentum can be changed if you
	//desire a faster/slower rocket.
	//Boosting doubles the rocket's momentum.
		
	//Determine whether the rocket should have normal flight
	//or boost flight when the spin key is utilised or left untouched.
	[SIZE="4"][B]if not (player.pflags & PF_USEDOWN)
		P_InstaThrust(rocket, rocket.angle, 8*FRACUNIT)
		player.boost = false
	elseif (player.pflags & PF_USEDOWN)
		P_InstaThrust(rocket, rocket.angle, 16*FRACUNIT)
		player.boost = true
	end[/B][/SIZE]
	rocket.angle = mo.angle
	
	//Defining what happens when you press up or down.
	//Rocket's momz influences the player's z-position
	[SIZE="4"][B]if player.cmd.forwardmove > 0
		rocket.momz = $1 + FRACUNIT
	elseif player.cmd.forwardmove < 0
		rocket.momz = $1 - FRACUNIT
	end[/B][/SIZE]
	//Cap the rocket's vertical momentum
	[SIZE="4"][B]if not (player.boost)
		if rocket.momz > 8*FRACUNIT
			rocket.momz = 8*FRACUNIT
		elseif rocket.momz < -8*FRACUNIT
			rocket.momz = -8*FRACUNIT
		end
	elseif (player.boost)
		if rocket.momz > 16*FRACUNIT
			rocket.momz = 16*FRACUNIT
		elseif rocket.momz < -16*FRACUNIT
			rocket.momz = -16*FRACUNIT
		end
	end[/B][/SIZE]
	//Player sticks to rocket during flight
	[SIZE="4"][B]P_TeleportMove(mo, rocket.x, rocket.y, rocket.z-40*FRACUNIT+rocket.momz)[/B][/SIZE]
	
	//Rocket Particle Effects: changes depending on your environment
	//and whether or not you are boosting.
	if not P_IsObjectOnGround(rocket) and not (rocket.eflags & MFE_UNDERWATER)
	and not (player.boost)
		P_SpawnMobj(rocket.x-FixedMul(48*FRACUNIT, cos(rocket.angle)),
		rocket.y-FixedMul(48*FRACUNIT, sin(rocket.angle)), rocket.z+30*FRACUNIT, MT_ROCKETPARTICLE)
	elseif not P_IsObjectOnGround(rocket) and not (rocket.eflags & MFE_UNDERWATER)
	and (player.boost)
		P_SpawnMobj(rocket.x-FixedMul(40*FRACUNIT, cos(rocket.angle)),
		rocket.y-FixedMul(40*FRACUNIT, sin(rocket.angle)), rocket.z+30*FRACUNIT, MT_ROCKETFLAME)
	elseif not P_IsObjectOnGround(rocket) and (rocket.eflags & MFE_UNDERWATER)
	and not (player.boost)
		P_SpawnMobj(rocket.x-FixedMul(48*FRACUNIT, cos(rocket.angle)),
		rocket.y-FixedMul(48*FRACUNIT, sin(rocket.angle)), rocket.z+30*FRACUNIT, MT_SMALLBUBBLE)
	elseif not P_IsObjectOnGround(rocket) and (rocket.eflags & MFE_UNDERWATER)
	and (player.boost)
		P_SpawnMobj(rocket.x-FixedMul(40*FRACUNIT, cos(rocket.angle)),
		rocket.y-FixedMul(40*FRACUNIT, sin(rocket.angle)), rocket.z+30*FRACUNIT, MT_MEDIUMBUBBLE)
	end
	
	//Cancel rocket flight if any of the following occur.
	if player.cusval == 1 -- Player has jumped
	or P_IsObjectOnGround(mo)
	or (mo.eflags & MFE_SPRUNG)
	or P_PlayerInPain(player)
	or player.exiting == 1
	or (player.playerstate & PST_DEAD)
	or not P_TryMove(rocket, rocket.x+rocket.momx, rocket.y+rocket.momy, true)
		P_InstaThrust(mo, rocket.angle, 0)
		
		//Player will not get a jump boost, if they are in pain or dead.
		if not P_PlayerInPain(player) and not (player.playerstate & PST_DEAD)
			if not (player.boost)
				P_InstaThrust(mo, rocket.angle, 12*FRACUNIT)
			elseif (player.boost)
				P_InstaThrust(mo, rocket.angle, 24*FRACUNIT)
				player.boost = false
			end
		end
		
		//Destroy the rocket and reset the player's flags
		P_SpawnMobj(rocket.x, rocket.y, rocket.z+26*FRACUNIT, MT_DUMMYEXPLOSION)
		P_KillMobj(rocket, rocket, rocket)
		if (player.pflags & PF_ROPEHANG)
			player.pflags = $1 ^^ PF_ROPEHANG
			P_DoJump(player, true)
		end
		mo.flags = ~$1 | MF_NOGRAVITY
		mo.flags = ~$1 | MF_FLOAT
		player.cusval = 0
	end
end
addHook("MobjThinker", RocketFlight, MT_ROCKET)

I have an older version of this script is very similar to this one with the exception that and iterator for players was used at the top under the MobjThinker Hook. In this version I had no issue having the player teleport to the rocket's location.

EDIT: The Problem Has Been Solved
 
Last edited:
For those not on Discord, this problem turned out to be caused by the MF_FLOAT flag being used. It was probably floating down to the height of its target, the player.

Meanwhile, I've fixed the MF_FLOAT flag's description on the wiki so people know how that flag is actually supposed to work. =P
 

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

Back
Top