Another Collision Question.

Blitz3D Forums/Blitz3D Beginners Area/Another Collision Question.

Maximus Primal(Posted 2005) [#1]
I need my ship to physically stop moving when it hits certain objects. I have tried setting the collision mode like this:
Collisions BODY,WALL,2,1


But that doesn't work or isn't enough. So I am thinking that the EntityCollision command is the way to go. But I am a little confused. The command help says it has two parameters - entity and type. But there is no example on how to use it. Can someone explain what the "Type" is for me please.

I assume it is used like this:

If EntityCollided (cube,type) Then
...code...
EndIf


If I know what the type value should be then hopefully I can use this to test things out properly.

Thanks

Max


RiverRatt(Posted 2005) [#2]
This is a collision set up I use in one of my games. Insodently it is a spaceship shooter.

; Set collision type values 
type_player1=1 ;the player ship
type_bullet=2 
type_scenery=3 ;the skysphere
type_enimy=5
type_e_bullet=6
type_waypoint=7
;type_shieldpower=8

;set up for collision checking
Collisions type_player1,type_enimy,3,2
;Collisions type_player1,type_player1,1,1
Collisions type_bullet,type_enimy,1,1
Collisions type_bullet,type_scenery,2,1
Collisions type_player1,type_scenery,2,1
Collisions type_enimy,type_enimy,1,3
Collisions type_enimy,type_scenery,2,1
Collisions type_e_bullet,type_player1,1,1
Collisions type_e_bullet,type_scenery,2,1
Collisions type_player1,type_waypoint,2,2


I like to set up for all 3 kinds of collisions so where you create you playership you put something like this. Note you don't have to declare both entitybox and entityradius, but I do at first at least that way I can go for the best efect.
But you do have to declare an entitytype like so...

 p_ship.player = New player 
 p_ship\p_pivot = pivot
 EntityType p_ship\p_pivot,1
 EntityRadius p_ship\p_pivot,10
 EntityBox p_ship\p_pivot,-3,-3,-3,6,6,6



That might be a hard example here is another.




jfk EO-11110(Posted 2005) [#3]
RiverRatt is right. Basicly it's:
each entity needs to have a type definition:

entitytype player,1 ; you may use a Variable too, But YOU have to define the numbers. it may also be 1234 or 77 or any other int number, it only needs to be individual for each type.
entittype wall,2

then you need to tell Blitz how to handle collisions when these types collide:

eg:
Collisions 1,2,2,2 ; that is collsions typesource,typetarget,coll_method, feature

finally in the main loop you need to call UpdateWorld to process Collision handling at all.

So
EntityCollided(player,2)
would return the handle of wall since wall if of type 2 (if the player collided with the wall at all), or it would return zero if the player didn't collide with an entity of type 2.


Maximus Primal(Posted 2005) [#4]
Thanks for that. I feel a little stupid asking so many questions at the moment. But things like this are pretty fundimental to doing anything in Blitz so I need to understand it properly. I had a feeling I was missing something and looking at some example code today (which I printed out) I had a feeling it was these entitytype and entitycollided commands that where the key to what I needed to know.

Both answers are extremely helpful (if a little hard to follow) but I think I understand what I need to know now. I will go and have a play and see what I can come up with. I am sure with a little work I will get the hang of it shortly.

Thanks again.

Max


Ross C(Posted 2005) [#5]
Remember, reduce your speed variable in your code, don't rely on the collisions to actually stop you ship. Maybe knock the speed down, but don't make it zero. Looks kind of crap when the ship just stops. You could also increase the part of your code that reduces the speed when the no keys are pressed. Check for collisions, and set the force of friction to something much greater, so you ship slows right down, but smoothly.


Maximus Primal(Posted 2005) [#6]
At the moment I have got it to stop the ship dead, which as you rightly say looks pretty crap. But at least I got the collision working which is the main thing.

Also found out about the EntityRadius command which has helped out a lot in doing this. I will alter that later on, but for now the main thing is to get the basics of the racing in there. I need to implement a couple of other things and once there I can take a better look at making things like this look neater.

I mean it took me about 4 attempts and 3 days to get a banking system working so the ship banks as it turns and then re-rights itself when the joystick is let go (and even getting my Joypad working as I wanted wasn't simple and there is work on that yet to do (variable speed / turning control). I have no doubt these will get sorted out in the same manner - a few days and about 4-5 (or more) ideas/attempts...

I already have a few ideas how make this part of the code look and feel a lot nicer than it currently is. But it will take me time as I only get maybe an hour a day at this under normal circumstances.

Thanks again.

Max