camera screwup?

Blitz3D Forums/Blitz3D Programming/camera screwup?

Guy Fawkes(Posted 2009) [#1]
what is wrong with this code? i simply want it to follow my player, and move when my character moves. it does everything but move with my character..

code:



thanks!


GfK(Posted 2009) [#2]
Nothing wrong with it. Need more code.


Midimaster(Posted 2009) [#3]
best solution:

Player=CreateCube()
Camera=CreateCamera(Player)


or (...I think..) also possible:


Player=CreateCube()
Camera=CreateCamera()
EntityParent Camera, Player,False




do you know this link:

http://www.blitzbasic.com/b3ddocs/docs.php


Guy Fawkes(Posted 2009) [#4]
didnt work.....


GfK(Posted 2009) [#5]
didnt work....
You might need to supply a little more (i.e. ANY) information....


Guy Fawkes(Posted 2009) [#6]



GfK(Posted 2009) [#7]
Take EntityParent out of your while/wend loop. You only need it once (BEFORE the loop).

That will probably do it.

Oh, by the way - if you aren't doing any collisions or animations, then UpdateWorld() is not required.


Guy Fawkes(Posted 2009) [#8]
still didnt work....

the camera looks like it moves instead of moving WITH the object...


GfK(Posted 2009) [#9]
Hang on a minute....
  MoveEntity Player, 0, 0, (KeyDown(200)-KeyDown(208))*1
   TurnEntity Player, 0, (KeyDown(203)-KeyDown(205))*1, 0
...the hell is that all about?!

You can't use KeyDown like that. [edit] Well, you can, but you really shouldn't.


Guy Fawkes(Posted 2009) [#10]
um, it assumes that both keys are 1 when pressed, so 1*1 is 1 :P

is that the problem? and how can i fix it?


GfK(Posted 2009) [#11]
No, it was just a passing comment. I don't have BB3D on here any more so I can't really test it, and its been years since I used it anyway.

Are you sure you have the EntityParent parameters the right way around?


Guy Fawkes(Posted 2009) [#12]
yes?


Guy Fawkes(Posted 2009) [#13]
id love if there was a WORKING 3rd person camera code


GfK(Posted 2009) [#14]
The code above cannot be the actual code you're using.

I just installed BB3D to test this, and there's a parameter missing from CameraRange, and after I fixed that, all I get is a black screen. So I fixed that too by moving the cube infront of the camera instead of above it (?!), and when I press the cursor keys, the cube stays right where it should, relative to the camera.


Guy Fawkes(Posted 2009) [#15]
woops. i typed it out but didnt test it. sorry lol. im in a hurry. i did it from memory of what's in my REAL project, which just so happens to fire a nasa rocket 3d model into space that im working on, BUT in order to make THAT work, i need this camera to work.


GfK(Posted 2009) [#16]
Well, for what its worth, with the two mentioned errors fixed, your code (above) works perfectly. You must be doing something different in your project but its impossible to say without seeing it.

It should be quite easy to spot simply by comparing it to the above code.


Guy Fawkes(Posted 2009) [#17]
u wanna see it?

ill turn the model into a cone, and comment out the texture


Guy Fawkes(Posted 2009) [#18]
here:




GfK(Posted 2009) [#19]
  If inair = 0 And inspace = 0 Then PositionEntity Camera, EntityX(player), EntityY(player), EntityZ(player)-10
There's your problem - or at least a huge part of it. You're repeatedly repositioning the camera 10 units behind the player along the Z axis. Depending which way the camera is facing, the global Z axis could be any direction.

What I'd recommend that you do, is set your camera positions ONCE at the start. Use multiple cameras (one for player, one for rocket, etc) and hideEntity all but the one you want the user to 'see' through. There's no overhead involved in doing this.


Guy Fawkes(Posted 2009) [#20]
so what should i change it to?

i have to have the camera be positioned on the player or the rocket depending on what those variables are = to of course


GfK(Posted 2009) [#21]
Just edited my last post with a suggestion.


Guy Fawkes(Posted 2009) [#22]
im not sure how to use 2 cameras. i find it easier to use 1 camera.


Guy Fawkes(Posted 2009) [#23]
that line WAS the problem. now. i got the player to camera to work. how can i get it when positioned on the rocket to rotate with the rocket, like it does the player?


GfK(Posted 2009) [#24]
Multiple cameras are easy.

Camera1 = CreateCamera()
Camera2 = CreateCamera()

Position camera 1 near your player, and camera 2 near the rocket, and parent them as normal.

When you want to use the players camera:
ShowEntity Camera1
HideEntity Camera2

...and when you want to see the rocket:
HideEntity Camera1
ShowEntity Camera2
That's generally all there is to it. If you make both cameras visible at the same time, then one will render over the top of the other (which can be used for effects such as a HUD overlay etc - see CameraClsMode() for more info).

As a footnote, you can also use CameraProjMode() to turn cameras on or off but personally I've always done it this way and I think its faster anyway.

[edit] Set up the rocket camera in the same way as the player camera. This should work even if the rocket has been moved:
PositionEntity Camera,entityx(rocket),entityy(rocket),entityz(rocket) ;place cam at same coords as rocket
RotateEntity Camera,entityPitch(rocket),entityYaw(rocket),entityRoll(rocket) ;align camera with rocket
MoveEntity Camera,0,0,-2 'move camera back a bit so we can see rocket
EntityParent Camera,rocket



Guy Fawkes(Posted 2009) [#25]
FIXED! THANK you!


Guy Fawkes(Posted 2009) [#26]
EDIT: when i redid the code, it somehow fixed itself

thanks anyway


Guy Fawkes(Posted 2009) [#27]
EDIT: ignore this