SRB2 Message Board  

Go Back   SRB2 Message Board > Sonic Robo Blast 2 > Editing > Editing Help

Reply
 
Thread Tools Search this Thread
Old 06-25-2019   #1
WellDoneSnake
Formerly "TSDude"
 
WellDoneSnake's Avatar
Default Teleporting Player to Object Issue

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:
Spoiler: Script
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.
	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
	rocket.angle = mo.angle
	
	//Defining what happens when you press up or down.
	//Rocket's momz influences the player's z-position
	if player.cmd.forwardmove > 0
		rocket.momz = $1 + FRACUNIT
	elseif player.cmd.forwardmove < 0
		rocket.momz = $1 - FRACUNIT
	end
	//Cap the rocket's vertical momentum
	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
	//Player sticks to rocket during flight
	P_TeleportMove(mo, rocket.x, rocket.y, rocket.z-40*FRACUNIT+rocket.momz)
	
	//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
__________________
Hmmm~ So tasty!

Last edited by WellDoneSnake; 06-25-2019 at 08:04 PM. Reason: Problem Solved
WellDoneSnake is offline   Reply With Quote
Old 06-25-2019   #2
Monster Iestyn
Friendly Neighbour-Hood
Moderator
 
Monster Iestyn's Avatar
Default

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
__________________
My page stuffed full of MIDI goodness!
The Hitchhiker's Guide to the Robo-Hoodiverse
Timeline of Sonic Robo Blast History!

That's an uppercase i, not a lowercase L, for the record. Also, it's pronounced "Yes-tin".
Monster Iestyn is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:26 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.