elevator problem

Posted By: xbox

elevator problem - 04/28/11 21:46

Hi all, I am trying to create a simple elevator to lift my player up to the next level. I have a mock up code to do this.
Code:
Entity* elev;
var operate = 0;
action elevator
{
	elev = my;
	while(1)
	{
		if(operate == 1)
		{
			while (my.z > -72)
			{
				my. z -= 2* time;
				wait(1);
			}
		}
		if(operate == 0)
		{
			while (my.z < 72)
			{
				my.z += 2 * time;
				wait(1);
			}
		}
		wait(1);
	}
}

What happens is, my elevator poses as a "wall", when I change variable to 1, it lowers to the ground, I walk onto it, change the variable to 0, and instead of taking the player up, the player just passes right through the block as it moves up leaving me still on the first floor.
If I hold down the space bar to continually jump however, I am able to ride the elevator up. How can I fix this so I don't have to jump?
Posted By: mireazma

Re: elevator problem - 04/28/11 23:45

I think that code has nothing to do with player/elev collision. Excuse me for modifying your code - still not solving your problem - but I'd avoid wait() as it's not fast at all and nested while loops are not necessary here.
Code:
Entity* elev;
var operate = 0;
action elevator
{
	elev = my;
	while(1)
	{
		if(operate == 1 && my.z > -72)
			my. z -= 2* time;
		else	
		if(operate == 0 && my.z < 72)
			my.z += 2 * time;
		
		wait(1);
	}
}


And elev pointer is not used grin

I don't understand: is there at least a situation when the player collides with the elevator?
when you say "I walk onto it" does it mean you are raising your z?
"I am able to ride the elevator up" you can stand on the elev. when you jump on it and it's in mid-air?
Posted By: xbox

Re: elevator problem - 04/28/11 23:52

yes the player is touching the elevator, by standing on it. Once standing on it, the elevator should start moving on the z axis upward. In doing so, the players z value should also rise with the elevator.
When I jump, while standing on the elevator, the player z value is also raised.
When I stop jumping, the player sinks through the elevator and falls to the bottom floor, and the elevator continues moving upward.
Posted By: Logan

Re: elevator problem - 04/29/11 03:54

I think you need to use c_move() instead. I've never written elevator code so I'm not sure exactly how it would work but try playing with c_move and the entities' push values.
Posted By: mireazma

Re: elevator problem - 04/29/11 11:42

So it seems that there's no collision implemented. Logan's right. You could try c_move for the player (make sure that elev PASSABLE is reset) or as alternatives handle the player z yourself:
1. use c_trace, determine if the underlying object is the elev.
Got it from the manual
Code:
c_trace(my.x,vector(my.x,my.y,my.z-1000),IGNORE_ME|IGNORE_SPRITES|IGNORE_CONTENT);
  my.z = hit.z - my.min_z;


or

2. find a way to define if the player is in the elev xy range and has z > elev.z.
In either case, all you have to do is use
Code:
player.z = elev.z + elevToPlayer //elevToPlayer is your adjustable var.


Don't forget to modify elevToPlayer in the jump code, if any.

Note that (1.) or (2.) should be handled by an event so as not to use c_trace or "if" respectively, all the time even when you're far away from the elev. If you're using c_trace anyway to handle player z in general, the better.
I'm a beginner myself and idk if you can define custom events.

You can also put the code in elev action:
A. make operate 0 for idle state.
B. if operate != 0
B. if c_trace (use USE_BOX to cover the whole elev area) hits an entity, set its z or check (2.) now, from here.

In either case note that you have to write the code for every entity that can be lifted by elev.
In my previously used SDK you could use inheritance and could make a parent class that contained the common entities coding.
No idea if you can with 3DGS but most chances are that you can

There may be easier ways and faster ones (not the same!) but I'm a 3DGS beginner and that's what I could come up with now.
Posted By: 3run

Re: elevator problem - 04/29/11 12:11

There is a good elevator example in AUM's shooter templates.
BTW, do you need this for our project? If yes, PM me.
© 2024 lite-C Forums