Collision help :P

Blitz3D Forums/Blitz3D Programming/Collision help :P

Regular K(Posted 2004) [#1]
im using the b3d demo to help me learn a bit of b3d before i buy it (if I do)
i want to see if its worth buying (for me at least)

im having problems with collision detecting, can someone please help me? it just doesnt detect collisions

AppTitle "Blitz Panzer"
Graphics3D 800,600,32,2
SetBuffer BackBuffer()

Global Pivot=CreatePivot()

Global Camera=CreateCamera(Pivot)
CameraRange Camera,1,5000
PositionEntity Camera,0,150,-250

Global Light=CreateLight()

Global Sherman_Hull=LoadMesh("models\sherman\hull.3ds",Pivot)
RotateEntity Sherman_Hull,270,270,0
EntityType Sherman_Hull,1
Global Sherman_Turret=LoadMesh("models\sherman\turret.3ds",Pivot)
RotateEntity Sherman_Turret,270,270,0

Global Terrain=LoadTerrain("hmap_1024.bmp")
EntityTexture Terrain,LoadTexture("lmap_256.bmp")
PositionEntity Terrain,-5000,-2000,-5000
ScaleEntity Terrain,160,6400,160
EntityType Terrain,2

Collisions 1,2,3,2

While Not KeyHit(1)
Update_Player()
UpdateWorld
RenderWorld
Text 0,0,CountCollisions(Sherman_Hull)
Flip
Wend
End

Function Update_Player()
If KeyDown(200)
MoveEntity Pivot,0,0,5
Else If KeyDown(208)
MoveEntity Pivot,0,0,-5
EndIf
If KeyDown(203)
TurnEntity Pivot,0,1,0
Else If KeyDown(205)
TurnEntity Pivot,0,-1,0
EndIf
If EntityCollided(Sherman_Hull,2)=False
MoveEntity Pivot,0,-25,0
EndIf
End Function

thank you :)


Erroneouss(Posted 2004) [#2]
first of all, doing:

If EntityCollided(Sherman_Hull,2)=False 
MoveEntity Pivot,0,-25,0 
EndIf


will make it do: "if its not collided with anything, it moves up", so the hull just flys up in the air

-you are probably going to want some gravity im guessing, so just make the tank go down if there arent any collisions
instead of up


Regular K(Posted 2004) [#3]
ya doesnt that code make it go down when nothing happens?

if it the hull doesnt collide with any entity types 2 then go down


Regular K(Posted 2004) [#4]
a negative y will make it go down, a positive y will make it go up

unless if i rotated my camera up-side down, its moving down


Sledge(Posted 2004) [#5]
You should translate it rather than move it. The direction of y25 will indeed alter depending the on the object's orientation; if you translate instead then it will always mean 25 units straight down.


shapeshifter(Posted 2004) [#6]
I'm totally new to this - bought Blitz3d just a few days ago.

I ran into this problem on the first day. I'd created a landscape, usin FLE, and was writing a program to move through it but my character/vehicle wouldn't stay on the ground when it reached the crest of a hill.

I figured that if the character/object wasn't colliding with anything else then it must be in mid-air so, when that was true, I moved it downwards until it collided with the ground.

I don't know if that's the best way to do it but it worked a treat. I'd be grateful for any advice on better methods.

How, for instance, do I alter the pitch, yaw and roll to give realistic effects when a vehicle is moving over the ground and how do I set up a camera to follow it?

Totally amazed at first results with Blitz3d and FLE and can't wait to learn more. Incidentally, I'm a 58-year-old newbie and I got into this with the intention of programming some amusements for my grandchildren. I had intended to populate a wee computer world with family members and things that they would recognise - favourite cartoon characters, etc. Now, after my first taste of B3D, I can't wait to learn more. I'm hooked!


John Blackledge(Posted 2004) [#7]
"I moved it downwards until it collided with the ground."
This is generally the method.
For good methods see the examples which came with Blitz, especially the castle demo. I keep referring to that.
BTW hi from a 52-yesr old (been programming 25 years now, and my excuse was always the same as yours :). I wonder how many oldies there are in the Blitz camp. Anyone know how old Mark is? He seems to have been around a while.


shapeshifter(Posted 2004) [#8]
Thanks John,

Well, maybe it was an excuse but we have to find our motivation where we can :)

I've been trying some simple things like mapping pics to objects and moving them around just to get an idea how things work. I was thinking of doing something that would allow them to search for things that they like, hidden around the landscape, and giving them a surprise/reward for finding them. Nothing flash, but it should help me to learn the basics on cameras, movement and collisions.

The gravity problem got me thinking about take-off, flight and landing so, as with most things, every problem offers a learning opportunity.

The potential is obvious but I've a way to go yet.


gpete(Posted 2004) [#9]
@shapeshifter...
regarding pitch, roll, yaw and a type of camera follow--
look at Mad Jacks Pitch and Roll code sample in the Code Archives. I am using it for a naval simulation..
(by the way, I'm 49 years old, and been programming for 24 years, in Basic, Cobol, Fortran, Pascal, C, Amos and now Blitz3d)

Oh, I forgot to mention the code is in the 3d Graphics/Math folder in the Code Archives


Jeremy Alessi(Posted 2004) [#10]
Usually, you don't check to see if the collision is false ... you just decrement an objects y velocity by gravity until a collision is true ... then you do a response. Follow the general law of physics an object reacts to a force ... don't check for the absence of the force ... just check for the presence of a force.

Also, you should store your CountCollisions() in a variable because you can only count them once per UpdateWorld().