Collisions with Entites and Planes

Blitz3D Forums/Blitz3D Programming/Collisions with Entites and Planes

Nexinarus(Posted 2011) [#1]
hi i need a bit of help. I keep on having my characters falling through the plane (infinite groud) rather than stopping when they hit it.
I did do a cop out. Here is the code below. I would like to remove the cop out and do it properly.
PS: I did 2 player movements and 2 different screen modes.



Any other tips and stuff would be helpful too on projectiles and laserbeams. I didnt try those yet since type may have to be used. I am not comfortable with those yet. Images for those will be created with this code too.

Last edited 2011

Last edited 2011


Matty(Posted 2011) [#2]
clsn_Plane - is never given a value.


Nexinarus(Posted 2011) [#3]
Oops. I guess i did miss that. Ill fix that right now and let u know what happened.

fixed the clsn_Plane
;Collision Types
Const clsn_plyrs=1,clsn_Cube=2,clsn_Plane=3

;Set collisions
Collisions clsn_plyrs,clsn_plyrs,1,2
Collisions clsn_plyrs,clsn_Plane,2,2 ;ive tried other combinations as well not just 2,2
Collisions clsn_plyrs,clsn_Cube,2,2

i removed the following
	If EntityY(player1)<0.5 Then PositionEntity player1,EntityX(player1),.5,EntityZ(player1)
	If EntityY(player2)<0.5 Then PositionEntity player2,EntityX(player2),.5,EntityZ(player2)


now my characters sink 1/2 way through the floor. I tried different combinations but I still dont get why it still does that. I am seriously debating whether or not to just use a giant cube for my ground. Because with the code i did for the Cube works fine.

Thnx Matty

Last edited 2011


GfK(Posted 2011) [#4]
Its probably sinking half way into the floor because that's where the axis of the player object is. All collisions in Blitz3D are sphere-to-something - you need to move that sphere to correspond with the player's feet, or wheels, or whatever the player is.


_PJ_(Posted 2011) [#5]
. // no matter - ignore this.

Last edited 2011


Nexinarus(Posted 2011) [#6]
@ Gfk

ya i tried the HandleSprite etc... 0,-1. It fixed the sprite but not my radius. What i got was my character was in mid air during collision on the cube but perfect on the ground. Im not sure what to do about that. I removed it when i kept on getting the same results. To solve my problem, i created an invisible plane for the ground collision and positioned it 1/2 way up the body. That seems to work. I wonder y the collision for the cube surface and a plane didnt work the same way? I followed the same steps. O well. @ least now i got something to work. Thnx.

Now for the next part.. Jumping. YIKES


Nexinarus(Posted 2011) [#7]
Ya i know i posed about 20-30min. ago but i was fixing my sinking problem and now my jumping problem. My character Jumps great. But i dont need him to do jumps in mid air. and i cant seem to detect collisions with entitycollided(Player1,cube) the way my code is.

Can someone plz run the code and tweak it (the jumping part that is) Run it first then tweak then u will see what i mean. I am almost there. I even looked at the Castle.BB in the samples folder to help me with this a bit. I look at, and my head spins. well here is the new code.




PS: Y cant i detect collisions between my Player1 and Cube?
Run code then check. Anyone plz. I have no idea what i am doing wrong.


Yasha(Posted 2011) [#8]
That's not what EntityCollided does. It takes a collision type as the second parameter, and if a collision occured, returns the entity handle of that type. To convert the handle into a true/false, do a comparison check of the result against the object you want to test (line 219):

Text 9,248,"Ent.Coll - Player1,Cube:"+(EntityCollided(Player1,clsn_Cube)=cube)


I like the aesthetic by the way.

Last edited 2011


Nexinarus(Posted 2011) [#9]
Thanx Yasha. I guess i didnt fully understand the help documents.

Have u done jumping b4? If so what would u recommend to stop jumping in mid air? Just out of curiosity?

I have dl a few jumping examples as well. Im gonna look through them, but every bit of info helps.

Oh, I glad u like the aesthetic part. BTW which part is that? Sorry I have never heard that term in programming b4.

Last edited 2011


Nexinarus(Posted 2011) [#10]
well.. I can get my char to jump. no matter what i do, I cant get him to not being able to jump in mid air. I am totally stumpped. Not sure what to do to fix the problem.


Yasha(Posted 2011) [#11]
You've got a variable Plyr1jmp that is set to 1 when the player jumps. If you set this to 0 when it lands again, you can disallow jumping as long as Plyr1jmp is true.

That's the simple part; the harder part is determining when to set the variable back to "jump permitted". If you have a simple collision between the player and the environment, it could jump again when it hits the underside of a ceiling or scrapes a wall on the way down, which may not be what you want.

There are two common solutions to this problem. If you have a very simple world or level design, you can have more than one collision surface for the world. Upward-facing surfaces would have a different collision type from vertical and downward-facing surfaces. Both collision types stop the player's movement, but only the upward-facing surface resets the jump variable.

If you have a more complex world, you might instead do something different with the player. One common styrategy is to give the player a second collision pivot, with a very small radius, parented to the player at its feet. The main collision radius still does the work of stopping the character's movement, but checking for collisions between the "foot pivot" and the world is the only way to reset the jump variable, again preventing side or top collisions from letting it jump again.

I'm sure this must be a fairly common issue as many games have jumping, so there must be some helpful stuff in past posts and the code archive (you can search the code archive with this tool: http://www.blitzbasic.com/Community/posts.php?topic=88773 ).

The aesthetic... I just meant I like the retro look.


Nexinarus(Posted 2011) [#12]
Hm... I never thought of using a pivot. Then agian I just began to understand them. I guess part of me is still used to 2d prgming. Im gonna give that a try. thnx again.


Nexinarus(Posted 2011) [#13]
Well I tried using a pivot. Applied a sphere to it so i knewwhere it was, and anther radius but it seem to separate from the player.

The parent was the player the pivot the child. The child tended to move away from the parent when colliding. the radius type never stays with the pivot anyway.

I am getting so frustrated. I may have to say "forget about the jumping" for now I have been fighting with the jumping for too long. I just dont know how to fix it at this time.


BTW can anyone tell me what TranslateEntity does? Ive looked at the documents and a few jumping examples and i still dont get it.

Last edited 2011


Warner(Posted 2011) [#14]
TranslateEntity = MoveEntity without rotations. Up=allways up, no matter how the entity is turned.

If you have a child object with collisions that is connected to a parent, collisions could cause it to 'stay behind' when the parent moves. You have to position it back into the right place every frame. It serves as a 'sensor': it shouldn't matter where it is after a collision, you just use it to find out if it collided with something.

Anyway, here is a very basic jump/control example:



Drak(Posted 2011) [#15]
TranslateEntity() will always move the object in global XYZ coordinates, regardless of the orientation of the object.


Nexinarus(Posted 2011) [#16]
thanx.. All of you guys have been awesome. This is the best site for help i have ever came too. Thankyou for giving me some tips, tricks, and ideas to try to get the jumping to work properly. I gotta say jumping in 2d is way easier than this.

Now that is said. I have given it one more try b4 i just set it aside and work on projectiles... and i gotta ask "what is a Normal?" Because honestly i dont see the difference between CollisionY and CollisionNY except the 'Normal' bit.

BTW i really got wide eyed when i saw this

world = CreateWorld()
EntityType world, 2, True


When i looked at the function "Create World". I didnt realize that was even possible. To call a function like that just because the world was loaded there. I have been prgming for a long time, and im still learning...
NEways... heres the new code... (again).



If anyone has time i would love to get some feed back from everyone who took their time and shared their knowledge to help me. And of course everyone who just want to take a look too.


Nexinarus(Posted 2012) [#17]
ok I have been playing around with jumping & collisions. again.

the first routine does what it did in the previous code. you hold down the jump button and the charcter bounces around like a rabbit. At least he dont stick to walls.
the second routine if u press the jump button and he jumps. hold jump and then release... charged jump. but im having problems with getting stuck on the sides of the cubes (or sliding down).

What i would like to do is have the character do charged jumping like routine 2 but does not get stuck/slide down on the walls like routine 1

can anyone help?

here is my code.



BTW there is still no projectiles in this example. I am working on that now. while i wait for a reply

ps: you'll have to save the code for it to work.

Last edited 2012


Nexinarus(Posted 2012) [#18]
Technically this thread needs no more replies.
Originally this thread was all about collisions. Then collisions when jumping.

To get working code of jumping look at the thread "Almost Perfect Jumping" or go to the "code archives/Miscellaneous/Basic & Charged Jumping in 3D". I posted the code there too.
Eventually it will be updated to allow charge jumping. Who knows, it may be there now. It depends on whether or not i can get the code tested by others.

Well have fun coding!

Last edited 2012