object refuses to stay attached to camera
Blitz3D Forums/Blitz3D Programming/object refuses to stay attached to camera
| ||
Hi, I have fixed one problem but found yet another problem. I have an example made out and my problem is that I am trying to make my sphere stay in front of the camera 24/7. My example code is listed below. Could someone please tell me why the sphere isn't staying in front of the camera? Graphics3D 800,600,32,2 Const ground_coll=1 Const player_coll=2 light=CreateLight() camera=CreateCamera() sphere=CreateSphere() EntityType sphere,player_coll terrain_A=LoadMesh("terrain_1.b3d") terrain_B=LoadMesh("terrain_2.b3d") PositionEntity terrain_A,0,-10,0 PositionEntity terrain_B,0,-10,0 AddMesh terrain_A,terrain_B AddMesh terrain_B,terrain_A EntityType terrain_A,ground_coll EntityType terrain_B,ground_coll PositionEntity sphere,1,0,5 PositionEntity sphere,EntityX(camera),EntityY(camera),EntityZ(camera)+5 MoveEntity sphere,EntityX(camera),EntityY(camera),EntityZ(camera) While Not KeyHit(1) Collisions player_coll,ground_coll,2,2 Collisions ground_coll,player_coll,2,2 If KeyDown(57) Then MoveEntity sphere,0,1,0 EndIf TranslateEntity sphere,0,-0.2,0 UpdateWorld RenderWorld Flip Wend EDIT: I think i've forgotten something but not sure what it is. Last edited 2012 |
| ||
Never Mind this post. I can create a third person camera instead. I'll go have a look into the archives. Sorry!! :/ |
| ||
Why don't you just parent the sphere to the camera. |
| ||
Why don't you just parent the sphere to the camera. Erm... Okay I'll give it a shot as the sphere needs to be a gun. I believe I should also have a look at the "scare" example in the bb3d samples folder and just see how that guy fixed that pistol the the camera. ;) |
| ||
That first example code only moves the sphere, not the camera. Since the camera isn't parented to anything or involved in any collisions... it's not interacting with anything in any way at all. What game or genre is similar to what you're trying to achieve? You want a standard FPS-style game with a gun at the bottom of the screen? If so, making the camera the parent of the gun/sphere and then moving the camera will result in the sphere being fixed relative to the camera, which is a decent start. Are you familiar with the parent/child system? (If not, it's very simple: children stay still relative to their parents, and when they move, their coordinate system is aligned to the parent's orientation and scale.) There are some nice examples of FPS gun systems in the archives, that will also give you a head start on solving other issues (an important one that will come up later is multipass rendering, because the gun usually can't be a part of the same 3D scene as the rest of the game). |
| ||
Just use the camera code i gave u from my fog code, and modify the speed parameter when calling it, to make the camera follow u quicker. the faster it is, the more "attached" it is :) |
| ||
More troubling is this...EntityType sphere,player_coll Which means that the sphere WILL get stuck on stuff in your level. If you're making first-person, thats a no-no. EDIT: to clarify, in a first-person-shooter, your gun should not be involved in collisions, the camera is your character, so all the movements/collisions etc. need to be applied to the camera itself. As was mentioned earlier,PARENTING is key and ridiculously simple.Just remember that any turns/moves/positionings will be relative to the parent. Last edited 2012 |