elevators (how the heck do they work?)

Blitz3D Forums/Blitz3D Programming/elevators (how the heck do they work?)

Ben(t)(Posted 2007) [#1]
okay so I would like to have elevators available in my game, but currently if my player is on the elevator and it moves up my dude falls through! what the heck is goin' on?


_33(Posted 2007) [#2]
You need to set proper collision. Not only that, but you need to set your player's Y position in relation on the elevator's. I have managed to program elevators using a physics engine. You should try that out.

Also, not posting your code will make it harder for anyone to help you.


Gabriel(Posted 2007) [#3]
I bet no one ever says "TMI" to you, do they? :)

Seriously, how about some code to go with the question?


Naughty Alien(Posted 2007) [#4]
..use of physics engine is way to go...I figure out that as a most efficient and easy way to deal with it..


syntax(Posted 2007) [#5]
if the elevator is like an REAL elevator, then dont bother with a physics engine and just say that if the player's inside the elevator, then temporarily make the player a child of the elevator. you might be able to play with the idea of what is INSIDE the elevator to get it to work in other situations too.


smilertoo(Posted 2007) [#6]
couldnt you parent the player to the elevator while a collision is registered?


syntax(Posted 2007) [#7]
probably not since the collision fails once the elevator starts moving.


PowerPC603(Posted 2007) [#8]
Another thing you can try is not only to let the player collide with the elevator (which stops the player falling through the elevator if the elevator is not in motion), but also the other way around.

If your player gets in the elevator, he collides with the elevator-floor and your character will not fall through it.
If the elevator goes down, the player doesn't collide anymore and falls until it collides again with the elevator floor.

If the elevator is going up, it doesn't check if it collides with something and just goes up without taking collisions into account.
The floor just gets repositioned (upwards) while your character stays at the same height.
The your character doesn't collide anymore and will fall through the floor.

Set up collisions between the player and the elevator floor and vice versa.

A while back I was playing with that too, just have a box move forward and backward while I'm controlling the player (a box too).
When the box moved away from me, I could run against it, but when the box came to me, my playerbox ran through it.
Setting up collisions both ways did the trick for me.


Moraldi(Posted 2007) [#9]
http://www.blitzbasic.com/Community/posts.php?topic=66152#740940


Ben(t)(Posted 2007) [#10]
holey cow! lotsa responses to answer several of your posts I don't have any code, I dabbled with the elevators for a while but then gave up but now I'm trying again.

oh powerpc603 what did you mean set up collisions both ways? like this?

collisions player,wall,2,3
collisions wall,player,2,3

or am I totally lost there?


PowerPC603(Posted 2007) [#11]
Yep, that's it.
It's been a while since I've tested this, but IIRC, that's what I did to fix it.

EDIT:

I've just created some testcode to see if it works.

Graphics3D 800, 600, 0, 2

SetBuffer BackBuffer()

COLBOX = 1
COLPLAYER = 2

Collisions COLPLAYER, COLBOX, 2, 3
;Collisions COLBOX, COLPLAYER, 2, 3

box = CreateCube()
PositionEntity box, -10, 0, 0
EntityType box, COLBOX
EntityColor box, 255, 0, 0

player = CreateCube()
PositionEntity player, 10, 0, 0
EntityType player, COLPLAYER
EntityColor player, 0, 255, 0



camera = CreateCamera()
PositionEntity camera, 0, 50, 0
RotateEntity camera, 90, 0, 0

While Not KeyHit(1)
	MoveEntity box, -0.01, 0, 0
	MoveEntity player, -0.1, 0, 0

	UpdateWorld
	RenderWorld
	Flip
Wend

End

As you can see, the box would represent your elevator (the red cube) and the player (green cube) is your player.

The second collisions command is currently commented, so the player can collide with the box, but not the other way around.
You can also comment the "MoveEntity box" line in the main loop to let the box stay where it is.
You can see that the player moves towards the box and hits it, but doesn't get past it (it doesn't fall/walk through).
But when you change the direction of the box's movement (towards the player), the player walks through the box.

Now uncomment the second collisions command, which sets up collisions both ways.

Now when they hit eachother, they both come to a halt.
They are both colliding against eachother and it makes no difference if one object is faster than the other, they block eachother's movement.
I didn't remember this from my test a few years ago (I guess it happened there too).

So that's not an option if you want to keep your elevator going up, because it would collide against the player and stop moving.
This would only prevent your character to stop falling through the floor.

The best you can do is to check if your player is colliding with the elevator floor and then parent your character to the elevator.

When that's done, you can start moving the elevator.
When it stops, unparent the player and your player is free to leave the elevator.


PowerPC603(Posted 2007) [#12]
I've just got an idea:

Graphics3D 800, 600, 0, 2

SetBuffer BackBuffer()

COLBOX = 1
COLPLAYER = 2

Collisions COLPLAYER, COLBOX, 2, 3
Collisions COLBOX, COLPLAYER, 2, 3

box = CreateCube()
PositionEntity box, -10, 0, 0
EntityType box, COLBOX
EntityColor box, 255, 0, 0

player = CreateCube()
PositionEntity player, 10, 0, 0
EntityType player, COLPLAYER
EntityColor player, 0, 255, 0



camera = CreateCamera()
PositionEntity camera, 0, 50, 0
RotateEntity camera, 90, 0, 0

While Not KeyHit(1)
	MoveEntity box, 0.01, 0, 0
	MoveEntity player, -0.1, 0, 0

	UpdateWorld

	If EntityCollided(box, COLPLAYER) Then
		MoveEntity player, 0.01, 0, 0
		MoveEntity box, 0.01, 0, 0
	EndIf

	UpdateWorld
	RenderWorld
	Flip
Wend

End


Here you see that the player and the box move towards eachother.
Right after they both move, there is an UpdateWorld to check for collisions (this is needed for this to work).

Then it checks if the box (your elevator) has collided with the player.
If that's true, move both the player and the box in the direction where the elevator must go.
Then it works perfectly, just by setting up collisions both ways.
Your character won't fall through the floor, you don't need a physics-engine just for your elevator and it works.


Ross C(Posted 2007) [#13]
Linepick is your friend :o)

Constantly do a linepick downwards, and parent the player to the lift as long as the floor is detected directly below the player feet.


Ben(t)(Posted 2007) [#14]
parent entity is a problem because the move commands I use double in speed when the player is a child of anything

to powerpc does that work if the entity if being translated downward?


Ross C(Posted 2007) [#15]
Hmmm, why does your player move double speed when parented?


SLotman(Posted 2007) [#16]
Just do linepicks down, if the pick finds an elevator and player's Y is lower than PickedY(), make it higher, if it's higher then let the player fall.


Dreamora(Posted 2007) [#17]
And just to answer the upcomming question on how you know its an elevator:

You sure have a type TEntity or the like where you store information, right?
Store handle(TEntity) in the entity name
and if you pick it, get the type handle by using Object.TEntity(picked_entity_handle)


_33(Posted 2007) [#18]
I think what's fun with an FPS game often is that you are free to do whatever you want when you move. That means that in an elevator, or on a platform, that you can jump to it or from it. Also, that a platform can move in any direction, it doesn't matter, as the player is transported with it while it's on it but is free to move how he wants. I think those are very important. Only in a physics engine, have I managed to do this in a universal way.


Ben(t)(Posted 2007) [#19]
I noticed in halo 3 recently with large vehicles like the elephant that if you jump off and are in the air as the elephant turns you turn with it as though you were a child entity.

thank you all for the help with the elevators I think I know what to do now