Problem with Mario Kart-like respawn code

Posted By: tolu619

Problem with Mario Kart-like respawn code - 07/05/14 11:11

My game has a lot of 3D platforming sections. When the player falls off the path into an abyss, I want him to respawn at the nearest checkpoint (checkpoints aren't visible). I don't want to check whether player.z has dropped below a certain height because I'll need to use the respawn function in some other instances. For example, when a flying character starts to fly off into the distance away from the path, he should also respawn at the nearest check point. So I decided to use invisible walls that trigger the respawn function on collision. I'm certain I'm not doing the collision event right because my invisible walls are showing absolutely no sign of collision at all.
Code:
//THIS IS ATTACHED TO INVISIBLE WALLS/FLOORS
action RespawnFallenMonSurface()
{
	my.emask |= (ENABLE_IMPACT | ENABLE_ENTITY | ENABLE_PUSH); 
	my.event = RespawnFallenMon;	
}

//YOU CAN SEE I'VE ENDED UP COMMENTING OUT MOST OF THE FUNCTION. JUST TRYING TO GET IT TO SHOW ANY SIGN THAT IT DETECTED A COLLISION
function RespawnFallenMon()
{
	if(event_type == EVENT_ENTITY)
	{
		beep();
	    printf("Touchdown!");
	}
//	beep();
//	printf("Touchdown!");
//	if(your.skill45 != 5555) //not a monster
//	{beep(); wait(-1); return;}
	
//	var test = 0;
//	wait(1); //avoid engine errors
//	if(test == 0)
//	printf("Touchdown!");
	
//	test = 1;
//	vec_set(vector(your.x,your.y,your.z), LastSolidGround);
}



Do I need to add the following line to my player action? It seems to make absolutely no difference at all.
Code:
my.emask |= (ENABLE_IMPACT | ENABLE_ENTITY | ENABLE_PUSH);


Also, if the invisible floor is already in contact with level structures such as terrain or pillars, will it affect its detection of collision with the player?
Posted By: Reconnoiter

Re: Problem with Mario Kart-like respawn code - 07/05/14 11:20

Are your walls moving? Otherwise you can set POLYGON flag for them so they have better collision. Tapping f11 twice with #include <default.c> included will allow you to check collision. Also where do you set the invisible flag for the wall? One more thing, you are not using WED invisible blocks for your walls right , but just models right? Cause for when you want to make WED blocks invisible but still have collision you will have to set their surfaces to not shaded (instead of marking the invisible flag for them).
Posted By: tolu619

Re: Problem with Mario Kart-like respawn code - 07/05/14 12:10

They aren't moving. I'm using a flat plate created in WED and compiled so that actions can be attached to it. When I intentionally fall off the edge, my character reaches the invisible floor and then appears to be standing on thin air, and is able to run around on the invisible floor, but the code
Code:
if(event_type == EVENT_ENTITY)
	{
		beep();
	    printf("Touchdown!");
	}

doesn't seem to be running at all. I've set the polygon flag in WED now but I don't see any "not shaded" flag. I saw a "nofilter" flag so I checked that and unchecked the invisible flag. I've recompiled the level but the plate is still invisible! frown
Posted By: Superku

Re: Problem with Mario Kart-like respawn code - 07/05/14 12:25

EVENT_ENTITY is the wrong event as the obstacle is not moving, the player is. EVENT_IMPACT thus is the right choice.
Apart from that on a solid movement code the player('s bounding box) will never touch the floor but hover above it, so your event should not get triggered. What you can do in the gravity code is to use c_ignore and ignore the obstacle's group (assign one) or use IGNORE_FLAG2 and set FLAG2 for those obstacles/ trigger boxes.

Alternatively, a much nicer way probably is to use regions and region_check.
Posted By: tolu619

Re: Problem with Mario Kart-like respawn code - 07/05/14 12:30

While I implement your suggestions, can you enlighten me on that last sentence? I mean, why is it nicer? It looks as if I used region_check, I'll have to be checking for quite a few regions per level. However, if I can get the respawn surfaces to work right, then I can simply re-use that code by attaching it to any object I want to in WED.
Posted By: Superku

Re: Problem with Mario Kart-like respawn code - 07/05/14 13:43

When you want to use models instead of regions you have more objects for the renderer/ tree and especially for c_move to process. Other objects (such as effects/ exploding and falling chunks, enemies, birds, ...) will all need to ignore those models too resulting in more work for you. Then, on collision your player will stop mid-air immediately, depending on what you want to achieve this may look bad. In my sidescroller there are bottomless pits and when the player falls from the platform he should not stop for one frame or more mid-aid but just continue falling to his doom while playing the death animation. You could try and use IGNORE_PUSH and a low push value for your obstacle objects, too.

When using regions you can just move and scale them to any size that you want. Checking for all regions can be somehow circumvented when you just use region_find instead and then compare the result. You can call the regions for example "abyssXYZ" and compare for "abyss", then, if necessary, use the number XYZ to determine a spawning position easily.
Posted By: tolu619

Re: Problem with Mario Kart-like respawn code - 07/05/14 22:11

Ok thanks. I'll toy around with the region thing. A little help here, anybody?
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=442872
It's been unanswered for over a day
© 2024 lite-C Forums