collisions and gravity

Blitz3D Forums/Blitz3D Beginners Area/collisions and gravity

Prym(Posted 2014) [#1]
Is there somebody who can tells simple things
about collisions and gravity in BlitzBasic3d ?
I read the forums ,
I try a lot of xeperimental codes ,
but I can't manage with that in my project .

My player (FPS) seeks in the ground or move "jerkily"
(not so sure of this term ...)

Can you give some simple rules , at least for the order of the applyable commands . ( before updateworld and renderworld )

Thank you for helping a french beginner ( english hard reader )

apry241
apry241@...


RemiD(Posted 2014) [#2]
Salut :)

From my tests, for moving characters who can jump fall land, it is better to use a combination of one linepick to detect the ground and one collider sphere to detect the obstacles at front, at back, at left, at right.

You also need to use several states to know when to apply some forces or not.
In my tests i use :
PositionState (OnGround or OnAir) ->to know when to apply the gravity force
JumpState (Yes or No) ->to know when to apply the jump force
MovementState (WalkForward, WalkBackWard, WalkLeft, WalkRight, Run Forward, SprintForward) ->to know in which direction the movement force need to be applied

As mentionned before, i use linepick to detect the ground. Please note that sometimes linepick fails on terrain as demonstrated here :
http://blitzbasic.com/Community/posts.php?topic=101836
But it does not seem to fail on others meshes.

In the case a linepick from above the terrain to below fails, and you are sure that the character is above the terrain, you can use TerrainY(Terrain,CharacterX,0,CharacterZ) to find the terrainY at CharacterX,CharacterZ

If the character is falling (OnAir), and after you have applied the movement force and the gravity force, you can use linepick to find the groundY and depending if the characterY is below or above the groundY, you know if you want to continue to apply the gravity force or to reposition the character at the groundy level and change his PositionState.
If the character is not falling (OnGround), you can simply position the character at the groundY level.


Prym(Posted 2014) [#3]
Hello RemiD ,
and thank you very much for your reply .

I want to say that gravity works , I presume , frequently with the ground , isn't it ?
With your advise , I will try the linepick ( It seems that I have already read this notion , without good attention , in the forums ) .

I attached the ground (terrain) and the other meshes of scenery to the same collision indice . ( because of the "EntityCollided ( entity,type )" command .
And I have tried "CollisionNY# ( entity,index )" to stay with local parent (faster than world ?...)

And so , I can't use "TerrainY" everywhere .
Am I definitely wrong ? Else how to do for best results ?

And I would want to ask if repositioning the player is better done with a "Translate" command ( - gravity Y ) or with the "PositionEntity" command . I have seen both in examples .

Now , I have to read all solutions and examples around linepick command .

Thank you RemiD , for all this indications .
If you want to reply to my last interrogations ?

Apry241


RemiD(Posted 2014) [#4]
To give you a better idea of what i mean, my mainloop looks like this (simplified version) :



The turn, move is applied with TurnEntity(), MoveEntity()
The gravity is applied with TranslateEntity()
The repositioning is applied with PositionEntity()

If you use only custom made meshes, you can use linepick to detect the ground.
But if you use a blitz3d terrain, sometimes you will need to use TerrainY() because sometimes linepick fails on terrain, see my code example above.

From my tests, it is better to turn move the character (apply gravity if necessary), then to use linepick to detect the ground, then to decide to reposition the character or to let the character fall.


Prym(Posted 2014) [#5]
Thank you RemiD , a lot of things very clear , now .
Your mainloop is instructive .

Long life to BB