Colliding camera with mesh

Blitz3D Forums/Blitz3D Beginners Area/Colliding camera with mesh

spriteman(Posted 2008) [#1]
Hi There,

Once 2 objects have collided i.e in my case the Camera being the player and the mesh being a gun, I would like to display on the screen that the player can use the gun by pressing a key.

However the collision will only hold true for as long as I hold the move up key down.

Is there a way of coliding with an object and holding the condition true untill the camera(player) moves away from it...i.e keep the option to choose a gun while standing near it.

I use the code below to detect the collision. The guns are types as there is more than 1 gun dotted around the map.

For g.gun = Each gun

If EntityCollided ( camera,col_gun )
Text 0,0, "Press 'Enter' key to use gun"
End If

Next


Matty(Posted 2008) [#2]
For something like that surely simply using entitydistance would be sufficient, and not checking for an actual collision with the gun.

For g.gun  = each gun
     IF EntityDistance(player,g\entityhandle) <= SomeSmallDistanceSpecifiedInYourCode then 
          ;Perform whatevery step you wish for when close to the gun.
     endif 
next



spriteman(Posted 2008) [#3]
Matty,

Great advice buddy. So I understand that what happens is that when the player is in the proximity of the gun, they will be able to pick it up when EntityDistance(camera,G\GMESH) <= dist. This works a treat.

A second little question - About collisions. I would like to detect collision with the gun only when in proximity of it so, I am using the function below but cannot see how to check the clearcollisions function has worked when outside of the gun proximity. Any Ideas on how to check the collision list has been cleared...Thanks,

Function neargun()

If guncol=0
ClearCollisions;Clear all collisions
End If

For g.gun = Each gun

If EntityDistance(camera,G\GMESH) <= dist Then
Collisions col_character,col_gun,2,2
Text 0,10, "Press enter to use the " +G\GNAME$
If KeyHit( 28 ) Then gogun=1-gogun
Else
guncol=0
End If

Next

End Function


Matty(Posted 2008) [#4]
Hello spriteman,

The ClearCollisions command, and the Collisions commands are not used in that manner.

Usually you will set up the collision responses between different 'types' of entity outside your main loop, usually just before it and should never, as far as I know, need to use the ClearCollisions command - which simply removes all collision response relationships between all your different entity types.

I still believe you only need to use the entitydistance to pick up a gun, mainly because the collision commands are usually used to set a relationship between different entity 'types' in regards to their response, whether the first entity will 'stop' 'slide' or 'slide upwards' upon contacting the second, as well as setting the mode of collision detection - sphere to sphere (which is no different than entitydistance to a small extent), or sphere to box or sphere to polygon - with sphere to polygon being overkill for a collision detection between a player and an item to pick up.


spriteman(Posted 2008) [#5]
Hi Matty,

Thanks for the reply. Just to elaborate a little, I am walking up to a gun and when I say gun I mean a big field gun(mesh) sitting on the terrain. So the entitydistance will detect when I am in close proximity and say 'press blah blah to use gun. At this point (within proximity) I am looking to enable the collision detection between the Gun and the player only.

What I mean is if by enabling collisions at this point btween gun/player, it will only check against the entity that is in range and not all the other entitys on the map. Then if I am out of range of entity(s) then clearcollisions

I thought this to be an efficient way of handling collision detection thinking that checking for all collisions on the map all the time may be a little more loading on the CPU.

Regds,


Matty(Posted 2008) [#6]
Simply set the 'entitytype' of the gun to zero whilst you don't want to check for collisions and then set the entitytype to whatever value you use for detecting collisions as normal when within 'range'.