Camera above/behind ship

Blitz3D Forums/Blitz3D Beginners Area/Camera above/behind ship

Farflame(Posted 2005) [#1]
I know this is fairly basic, and I knew how to do it once but I've forgotten again.

How do I position my camera directly above, or behind my spaceship, so that it follows it and retains that position even when the ship moves?

Also, would it be fairly simple to smoothly switch between the two? E.g if you're looking from above, you press a key and it moves smoothy down to the rear view, instead of instantly switching?


Matty(Posted 2005) [#2]
Number of ways of doing this. A really simple method would be to create the spaceship model, create a camera, (both at the same coordinates and pointing the same wa) then move the camera a certain distance backwards and up before using the aligntovector command to point the camera at the ship and then making the camera a child of the ship using the entityparent command.

Or you can do the whole thing without parenting the camera to the ship by simply updating the camera's position and orientation each frame. If you want it to move smoothly from one point to another a method like this may work:

as some basic 'pseudocode' it is here:

translateentity camera,smallvalue#*(desiredcamerax#-entityx(camera)),smallvalue#*(desiredcameray#-entityy(camera)),smallvalue#*(desiredcameraz#-entityz(camera))

aligntovector camera,desiredcameraviewpointx#-entityx(camera),desiredcameraviewpointy#-entityy(camera),desiredcameraviewpointz#-entityz(camera),3,smallvalue#


some code similar to the stuff above called each frame should work...


IPete2(Posted 2005) [#3]
FarFlame,

go to the Code Archives and find "Supercam" - it works really well and is simple to use.

IPete2.


Farflame(Posted 2005) [#4]
Ok, thanks guys, that's got me there, and I learnt a few tricks while I was doing it.

One other question now, which I think is a similar problem. How would I create a bullet, fired from the spaceship, that travels in the direction the ship was travelling when it fired? Once again, I think the answer is something to do with tpoint.. whatever, but I can't remember how to do it. Any ideas?


Matty(Posted 2005) [#5]
Tformnormal 0,0,1,spaceshipmodel,0
velocityofbulletinxdirection#=bulletspeed#*tformedx()
velocityofbulletinydirection#=bulletspeed#*tformedy()
velocityofbulletinzdirection#=bulletspeed#*tformedz()



-transforms a unit vector pointing in the 'forwards' direction (ie z directoin) from the spaceship entity space to the world space.