Camera collisions
Blitz3D Forums/Blitz3D Beginners Area/Camera collisions
| ||
I was doing a test program to practice collisions. The player is the camera entity. However, I noticed that collisions don't work on cameras. Is there any way to use collisions on cameras? Maybe I was doing something wrong... |
| ||
You can create the player... player=CreateSphere() EntityAlpha sphere,0 cam=CreateCamera(player) ...and now you can test collisions between player(sphere) and world. |
| ||
Collisions work on Cameras.Graphics3D 1024, 768 SetBuffer BackBuffer() cam = CreateCamera() EntityType cam, 1 plane = CreatePlane() EntityColor plane, 50, 200, 40 PositionEntity plane, 0, -50, 0 EntityType plane, 2 Collisions 1, 2, 2, 1 While Not KeyHit(1) MoveEntity cam, 0, (-.5), 0 UpdateWorld() RenderWorld() If EntityCollided(cam, 2) Then Text 0, 0, "Collision occured" Flip Wend End Any time you aren't sure about something, write a test program, as I just did. |
| ||
You're right... I wonder why I couldn't get collisions working between a camera and a terrain. I tried using a cube as the player entity and it worked perfectly. Anyway, I have a question about the EntityCollided and CollisionEntity commands. How does Blitz determine which entity collided and which was the "collided with" entity? |
| ||
The documentation tells you: EntityCollided ( entity,type ) Parameters entity - entity handle type - type of entity Description Returns the handle of the entity of the specified type that collided with the specified entity. CollisionEntity ( entity,index ) Parameters entity - entity handle index - index of collision Description Returns the other entity involved in a particular collision. Index should be in the range 1...CountCollisions( entity ), inclusive. It just depends on how you use the command. |
| ||
However, check out this odd behavior: In this example: Graphics3D 1024, 768 SetBuffer BackBuffer() cam = CreateCamera() EntityType cam, 1 plane = CreatePlane() EntityColor plane, 50, 200, 40 PositionEntity plane, 0, -50, 0 EntityType plane, 2 Collisions 1, 2, 2, 1 Collisions 2, 1, 1, 1 While Not KeyHit(1) MoveEntity cam, 0, -.5, 0 ;MoveEntity plane, 0, .5, 0 UpdateWorld() RenderWorld() If EntityCollided(cam, 2) Then Text 0, 0, "Cam collided with plane" If EntityCollided(plane, 1) Then Text 0, 20, "Plane collided with cam" Flip Wend Endmoving the camera into the plane, only one collision is noted. but if we move the plane instead of the camera: (reverse commented code) ;MoveEntity cam, 0, -.5, 0 MoveEntity plane, 0, .5, 0both collisions are noted. Something to watch out for... |
| ||
I don't know, mabe your problem is already solved, but I decided to post anyway. I have had problems with camera/terrain collisions also, and I solved it useing a method similar to Mikele, except instead of making a sphere as the player, I think it is better to make a pivot. (then the computer does not have to calculate all of the triangles in the sphere) Hope I was of some use! |
| ||
Good point about the pivot versus sphere. The load of a sphere is a needless load. Why waste computing cycles when you don't have to? |
| ||
Well, the computer wouldn't calculate the triangles in the sphere, if you used sphere to poly collisions. Since the colliding mesh must be a sphere, no actually checks are done on the geometry of the mesh. |
| ||
But it still would occupy some ram. BTW EntityCollided will return an entity handle, not only true or false. |
| ||
Why would it occupy more RAM? If you using a pivot for the collisions + the player mesh. As opposed to just using the player mesh? |