Shoots to the moon

Posted By: mschoenhals

Shoots to the moon - 09/09/15 13:49

I'm having an issue where when my player pushes into another model, it sends the player up (to the moon) and out of the game play area. Any ideas on how I can stop this?
Posted By: Anonymous

Re: Shoots to the moon - 09/09/15 14:18

In your gravity code, you may be using the flag USE_BOX.

Don't!

But to be of any help you will need to post the players action, Also check the BBOX size. Last this can happen with unchecked frame rates like windowed at 300. It could also be that your gravity code is actually doing the pushing.
Posted By: Ch40zzC0d3r

Re: Shoots to the moon - 09/09/15 14:59

Check the height difference before setting it, Im sure the trace is hitting something wrong.
Posted By: mschoenhals

Re: Shoots to the moon - 09/09/15 16:39

I took the flag out USE_BOX and it did work; however, now my doors aren't working. I'm using AUM's example RPG code:

Code:
my.z -= c_trace(my.x, temp.x, IGNORE_ME | IGNORE_PASSABLE) - my.dist_to_ground;

Posted By: Anonymous

Re: Shoots to the moon - 09/09/15 17:40

Yuck template code... I'd be happy to look at the door action, if I had any clue where in the template stack it is.

Let me dig
Posted By: Anonymous

Re: Shoots to the moon - 09/09/15 17:45

Code:
// skill1: speed 4
// skill2: key 0
// skill3: offset_x 0
// skill4: offset_y 0
// skill5: offset_z 200
// skill6: swing 0
// skill7: angle 90
// skill8: open_manually 0
action t_door()
{	
	while (!player) {wait (1);} // wait until the player is loaded
	vec_set (my.skill61, my.x); // store the xyz initial position of the door inside skill61... 63
	my.skill64 = my.pan; // store the initial pan angle
	if (my.speed == 0)
		my.speed = 4;
	if (my.offset_z == 0)
		my.offset_z = 200;
	if (my.angle == 0)
		my.angle = 90;		
	while (1)
	{
		c_scan(my.x, my.pan, vector(360, 180, t_door_range), IGNORE_ME | SCAN_ENTS); // each door scans around it, trying to detect the player
  		if (you) // detected an entity?
		{
			if (you == player) // and that entity is the player?
			{
				if (my.open_manually) // need to press a key in order to open the doors?
				{
					if(key_pressed(key_for_str(key_open))) // the "open" key was pressed?
					{
						if (my.skill2 > 0) // this door needs a key?
						{
							if (player.skill70 == my.skill2) // the player has got the proper key? then let's open the door!
							{
								t_open_doors(); // this function opens the doors
								return;
							}
							else // the player doesn't have the needed key?
							{
								wait (1); // don't do anything
							}
						}
						else // the door doesn't need a key
						{
							t_open_doors(); // this function opens the doors
							return; // the action stops afterwards							
						}
					}
				}
				else // the door opens automatically
				{
					if (my.skill2 > 0) // this door needs a key?
					{
						if (player.skill70 == my.skill2) // the player has got the proper key? then let's open the door!
						{
							t_open_doors(); // this function opens the doors
							return; // the action stops afterwards
  						}
		  			}	
		  			else // this door doesn't need a key
	  				{
	  					t_open_doors(); // this function opens the doors
	  					return; // the action stops afterwards
  					}
  				}
  			}
		}
  		wait (1);
  	}		
}


Please explain, should the door open auto or on keypress? I not sure I can help as I never use template code.
Posted By: mschoenhals

Re: Shoots to the moon - 09/09/15 20:35

I created the door code from another tutorial as the one in the RPG didn't have one. The player can open doors, but ejection to the moon takes place. Here's my door code:

Code:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Template rpg doors and keys
// Written by Mike Schoenhals, May 11th, 2015.
// based on the Tutorial code by Bandicam, Devon Lively

//DOOR MUST HAVE BOUNDING BOX FLAG ENABLED!!!!!!!

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#define key skill1
#define key skill2

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

var door_range = 120;  //scan distance of door to player
var key_rotating_speed = 5; //how fast should the key rotate when visible

STRING* got_key_wav = "gotkey.wav";  //sets the file name for getting a key
STRING* door_opens_wav = "dooropens.wav";  //sets the file name for opening the door

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function key_collision()
{
	if (you == player)
	{
		my.skill67 = 1;
	}
}

//Below is a define skill statement needed for the customizable window in WED.  Note how they are commented out.

// skill1: key 0
action keys()
{
	set (my, PASSABLE); // the key is passable
	while (!player) {wait (1);} // wait until the player model is loaded
	while (vec_dist (player.x, my.x) > 50) // wait until the player comes close to the key
	{
		my.pan += 5 * time_step; // rotate while waiting for the player
		wait (1);	
	}
	player.skill70 = my.skill1; // now pass the value set inside the key's skill1 using Wed to player's skill70
	
	SND_CREATE_STATIC(got_the_key, got_key_wav); 
	snd_play(got_the_key, 80, 0); // play the "got the key" sound
	set (my, INVISIBLE); // make the key invisible
	wait (-1);
	ent_remove(my); // and then remove it after a second
}



function open_doors() // this function is called by each door
{

	set(me, POLYGON | SHADOW);
	
	var door_swing_speed = 5;
	var closed_pan = my.pan;
	var OPEN_OR_CLOSED = 0;
	//	if (is(my.FLAG1)) {OPEN_OR_CLOSED = 1;my.pan+=90;closed_pan = my.pan-90;}
	
	VECTOR door_handle;
	vec_for_vertex(door_handle, me, 1);
	
	while(1){wait(1);
		
		if(vec_dist(door_handle.x, player.x) < 100 && my.pan == closed_pan){
			set(me, PASSABLE);
			while(my.pan < closed_pan+90){wait(1);my.pan+=door_swing_speed;}
			SND_CREATE_STATIC(door_opens, door_opens_wav); // play the "door opens" sound
			snd_play(door_opens, 100, 0);
			//			door_sounds();  //runs the function for sounds below.
			reset(me, PASSABLE);
			while(key_enter){wait(1);}
		}
		
	}
	
}

// skill2: key 0
action door()
{
	while (!player) {wait (1);} // wait until the player is loaded
	vec_set (my.skill61, my.x); // store the xyz initial position of the door inside skill61... 63
	my.skill64 = my.pan; // store the initial pan angle

	while (1)
	
	{
		c_scan(my.x, my.pan, vector(360, 180, door_range), IGNORE_ME | SCAN_ENTS); // each door scans around it, trying to detect the player
		if (you) // detected an entity?
		
		{
			if (my.skill2 > 0) // this door needs a key?
			{
				if (player.skill70 == my.skill2) // the player has got the proper key? then let's open the door!
				{
					open_doors(); // this function opens the doors
					return; // the action stops afterwards
				}
			}	
			else // this door doesn't need a key
			{
				open_doors(); // this function opens the doors
				return; // the action stops afterwards
			}
		}
		
		wait (1);
	}
}

Posted By: mschoenhals

Re: Shoots to the moon - 09/09/15 21:02

I've had it open automatically using c_scan and also where the player has to hit enter. Both ways the player can shoot upwards by running into the door frame. I also have to have the BBox FLAG enabled for the player(or the door won't work).
Posted By: Anonymous

Re: Shoots to the moon - 09/09/15 21:10

Quote:
//DOOR MUST HAVE BOUNDING BOX FLAG ENABLED!!!!!!!


Your door is actually using the POLYGON flag not a bounding box.
Both player and doors should not use POLYGON but actual BBoxs

Quote:
my.dist_to_ground


What and where is this skill set? If you know?

Code:
if(vec_dist(door_handle.x, player.x) < 100 && my.pan == closed_pan){
			set(me, PASSABLE);



Your setting the door passable, is the gravity trace using IGNORE_PASSABLE flag? You actually should not set the door passable. What might be happening is a timing error. You set the door passable, then walk in to it, the reset passable - making it solid. That will cause the player bbox to be in the door as well as the gravity trace to be in the door. Gravity trace hitting inside a door will cause a negative trace return, which would cause the player to fly upward.

Code:
c_scan(my.x, my.pan, vector(360, 180, door_range), IGNORE_ME | SCAN_ENTS); // each door scans around it, trying to detect the player
		if (you) // detected an entity?



This scan should also IGNORE_PASSABLE or IGNORE_PASSENTS
Also after the '''if(you)''' you need to do another check for either the '''player''' pointer or some or id var, otherwise the scan can be trigger by others. - Although that is a potential problem not a real one at the moment.

Code:
while(key_enter){wait(1);}


not sure why the nested loop to wait.

EDITED HEAVILY
Mal
Posted By: mschoenhals

Re: Shoots to the moon - 09/09/15 21:17

Sorry, it's the player who has to have the Bound Box flag enabled. I am using IGNORE_PASSABLE on the player. Are you saying that the c_scan should include the IGNORE_PASSABLE flag?

Code:
c_scan(my.x, my.pan, vector(360, 180, door_range), IGNORE_ME | IGNORE PASSABLE | SCAN_ENTS); // each door scans around it, trying to detect the player
		if (you) // detected an entity?

Posted By: mschoenhals

Re: Shoots to the moon - 09/09/15 21:22

Quote:

Your setting the door passable, is the gravity trace using IGNORE_PASSABLE flag? You actually should not set the door passable. What might be happening is a timing error. You set the door passable, then walk in to it, the reset passable - making it solid. That will cause the player bbox to be in the door as well as the gravity trace to be in the door. Gravity trace hitting inside a door will cause a negative trace return, which would cause the player to fly upward.

This looks like the most likely issue. The flying off is done once the player enters the door. Once the door is open, should it be set as passable then?
Posted By: Anonymous

Re: Shoots to the moon - 09/09/15 21:22

Yes because it's faster. and no passable ent would interact with a door.

Please read my above edits
Posted By: Anonymous

Re: Shoots to the moon - 09/09/15 21:25

No actually the door should never be passable. The player should fit the door and way.

Also increasing the trigger range can help.

You have a choice,
make it passable and leave it passable.
Don't ever make it passable
make it passable and then change back before the player ever reaches the door.
Posted By: mschoenhals

Re: Shoots to the moon - 09/09/15 21:29

So I tried this to make the door passable when opened but it didn't solve the issue.

Code:
function open_doors() // this function is called by each door
{
	//	t_door_sounds();
	if (my.swing)
	{
		if (my.angle > 0)
		{
			while (my.pan < my.skill64 + my.angle) // rotate the door
			{
				my.pan += my.speed * time_step;
					set (my, PASSABLE); // the key is passable
				wait (1);	
			}
		}		
		if (my.angle < 0)
		{
			while (my.pan > my.skill64 + my.angle) // rotate the door
			{
				my.pan -= my.speed * time_step;
					set (my, PASSABLE); // the key is passable
				wait (1);	
			}
		}		
	}
}

Posted By: Anonymous

Re: Shoots to the moon - 09/09/15 21:30

If you view the code I posted from t_doors.c in the include folder, which can be include in your project setting and give you the actual template door, you will see at NO point is the door ever made passable.

I would only do this if the door has to ---- No actually I would never do this.

Don't make a door passable.
Posted By: Anonymous

Re: Shoots to the moon - 09/09/15 21:31

No your problem is the reset

Code:
act door open

if(vec_dist(door_handle.x, player.x) < 100 && my.pan == closed_pan){
			set(me, PASSABLE);
			while(my.pan < closed_pan+90){wait(1);my.pan+=door_swing_speed;}
			SND_CREATE_STATIC(door_opens, door_opens_wav); // play the "door opens" sound
			snd_play(door_opens, 100, 0);
			//			door_sounds();  //runs the function for sounds below.
			reset(me, PASSABLE);
			while(key_enter){wait(1);}



Remove either the reset or both the set(passable) and reset(passable)
Posted By: mschoenhals

Re: Shoots to the moon - 09/09/15 21:39

Even when the door is open, if I run into the hinge, the player flies up. What should the reset do then? Should I take it out?
Posted By: Anonymous

Re: Shoots to the moon - 09/09/15 21:40

REMOVE for action open_doors ALL SET(me,PASSABLE) AND ALL RESET(me,PASSABLE).

Please
Posted By: Anonymous

Re: Shoots to the moon - 09/09/15 21:42

Also please make sure there are no other passable or water like blocks in the door way-opening
Posted By: Anonymous

Re: Shoots to the moon - 09/09/15 21:46

Also BOTH OF THESE in the door action need to be changed.
Code:
return; // the action stops afterwards



It's not a return it needs a break to work this way.
You do not terminate the main action of a ent.

Now I have to look up if break kills a infinite loop. Keep a eye out for another edit.

EDIT- I'm not even sure you can break that loop. Because the while() should have a condition. like while(my.skill88)
then instead you can set skill88 in the if/else and use a break.

Posted By: mschoenhals

Re: Shoots to the moon - 09/09/15 21:58

so I've made these changes and its better. However, if I press into the door hinge, I go skyward still.

Code:
function open_doors() // this function is called by each door
{

	set(me, POLYGON | SHADOW);
	
	var door_swing_speed = 5;
	var closed_pan = my.pan;
	var OPEN_OR_CLOSED = 0;
	//	if (is(my.FLAG1)) {OPEN_OR_CLOSED = 1;my.pan+=90;closed_pan = my.pan-90;}
	
	VECTOR door_handle;
	vec_for_vertex(door_handle, me, 5);
	
	while(1){wait(1);
		
		if(vec_dist(door_handle.x, player.x) < 300 && my.pan == closed_pan){
//			set(me, PASSABLE);
			while(my.pan < closed_pan+90){wait(1);my.pan+=door_swing_speed;}
			SND_CREATE_STATIC(door_opens, door_opens_wav); // play the "door opens" sound
			snd_play(door_opens, 100, 0);
			//			door_sounds();  //runs the function for sounds below.
//			reset(me, PASSABLE);
			while(key_enter){wait(1);}
		}
		
	}
	
}

Posted By: Anonymous

Re: Shoots to the moon - 09/09/15 22:05

You are literally ignoring what I am saying.

Code:
function open_doors() // this function is called by each door
{

	set(me, POLYGON | SHADOW);
	
	var door_swing_speed = 5;
	var closed_pan = my.pan;
	var OPEN_OR_CLOSED = 0;
	//	if (is(my.FLAG1)) {OPEN_OR_CLOSED = 1;my.pan+=90;closed_pan = my.pan-90;}
	
	VECTOR door_handle;
	vec_for_vertex(door_handle, me, 5);
	
	while(1){wait(1);
		
		if(vec_dist(door_handle.x, player.x) < 300 && my.pan == closed_pan){
//			// REMOVED A SET
			while(my.pan < closed_pan+90){wait(1);my.pan+=door_swing_speed;}
			SND_CREATE_STATIC(door_opens, door_opens_wav); // play the "door opens" sound
			snd_play(door_opens, 100, 0);
			//			door_sounds();  //runs the function for sounds below.
//			// REMOVED A RESET
			while(key_enter){wait(1);}
		}
		
	}
	
}

Posted By: mschoenhals

Re: Shoots to the moon - 09/09/15 22:19

Sorry, I didn`t remove it, I commented it out. Still the same issue.
Posted By: Anonymous

Re: Shoots to the moon - 09/09/15 22:22

Have you now gone back and fixed the RETURNS in the action like I said a few post ago.


Tell you what, I'm just going to write this for you.

Give me a minute.
Posted By: Anonymous

Re: Shoots to the moon - 09/09/15 22:37

Code:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Template rpg doors and keys
// Written by Mike Schoenhals, May 11th, 2015.
// based on the Tutorial code by Bandicam, Devon Lively
// HACKED by Malice
//DOOR MUST HAVE BOUNDING BOX FLAG ENABLED!!!!!!!

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#define key skill1
#define key skill2

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

var door_range = 120;  //scan distance of door to player
var key_rotating_speed = 5; //how fast should the key rotate when visible

STRING* got_key_wav = "gotkey.wav";  //sets the file name for getting a key
STRING* door_opens_wav = "dooropens.wav";  //sets the file name for opening the door

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function key_collision()
{
	if (you == player)
	{
		my.skill67 = 1;
	}
}

//Below is a define skill statement needed for the customizable window in WED.  Note how they are commented out.

// skill1: key 0
action keys()
{
	set (my, PASSABLE); // the key is passable
	while (!player) {wait (1);} // wait until the player model is loaded
	while (vec_dist (player.x, my.x) > 50) // wait until the player comes close to the key
	{
		my.pan += 5 * time_step; // rotate while waiting for the player
		wait (1);	
	}
	player.skill70 = my.skill1; // now pass the value set inside the key's skill1 using Wed to player's skill70
	
	SND_CREATE_STATIC(got_the_key, got_key_wav); 
	snd_play(got_the_key, 80, 0); // play the "got the key" sound
	set (my, INVISIBLE); // make the key invisible
	wait (-1);
	ent_remove(my); // and then remove it after a second
}



function open_doors() // this function is called by each door
{

	set(me, POLYGON | SHADOW);
	
	var door_swing_speed = 5;
	var closed_pan = my.pan;
	var OPEN_OR_CLOSED = 0;
	//	if (is(my.FLAG1)) 
	{
		OPEN_OR_CLOSED = 1;
		my.pan+=90;
		closed_pan = my.pan-90;
		}
	
	VECTOR door_handle;
	//vec_for_vertex(door_handle, me, 1); // Not needed at all
	
	while(1){
		
		if(vec_dist(my.x, player.x) < 100 && my.pan == closed_pan)
		{
			
			if(!key_enter && my.skill88)
			{
				my.skill88=0;
			}
			if(key_enter && !my.skill88)
			{
				my.skill88 = 1;
				my.skill89 = 1;
			}
			if(my.pan < closed_pan+90 && my.skill89)
			{
			my.pan+=door_swing_speed;
			
			SND_CREATE_STATIC(door_opens, door_opens_wav); // play the "door opens" sound
			snd_play(door_opens, 100, 0);
			//			door_sounds();  //runs the function for sounds below.
			}
			}
			wait(1); // wait goes at the end....
		}
		
	}
	


// skill2: key 0
action door()
{
	while (!player) {wait (1);} // wait until the player is loaded
	vec_set (my.skill61, my.x); // store the xyz initial position of the door inside skill61... 63
	my.skill64 = my.pan; // store the initial pan angle

	while (!my.skill89)
	
	{
		c_scan(my.x, my.pan, vector(360, 180, door_range), IGNORE_ME | SCAN_ENTS); // each door scans around it, trying to detect the player
		if (you) // detected an entity?
		
		{
			if (my.skill2 > 0) // this door needs a key?
			{
				if (player.skill70 == my.skill2) // the player has got the proper key? then let's open the door!
				{
					open_doors(); // this function opens the doors
					break; // the action stops afterwards
				}
			}	
			else // this door doesn't need a key
			{
				open_doors(); // this function opens the doors
				break; // the action stops afterwards
			}
		}
		
		wait (1);
	}
}



Please test this code for issues.

You may be noticing a sound issue by now. I'll leave that little bit to you. MOVE the snd_play() into the brackets with my.skill89 =1; in them...
Posted By: Anonymous

Re: Shoots to the moon - 09/10/15 00:02

While it either doesn't work or it works and your busy on something else.

Have fun and code on.
Posted By: Anonymous

Re: Shoots to the moon - 09/10/15 16:33

I would like to thank you for engaging in this problem, having me work hard to communicate, having me write actual code and then simple going silent.

Good luck, but I will not be taking my time again to help you.

Mal
© 2024 lite-C Forums