A Camera that follows/sticks/stays behind an object

Hello everyone!

I was working on a script that makes the camera follow an object.
I searched on this forum, and I googled, but I keep getting results where people explain how a camera TRACKS an object. I want the camera to follow it, meaning it stays on the same place relative to the object.

My second idea was to check out games that have the camera like I want it, and I found one of those games right on the top of this forum. Problem is: It’s so complicated, I could use a little help…

If someone has a tutorial or knows one, or could help me with the basics, that would be very much appreciated. I think many people would profit from that if they search this forum.

I found: http://blenderartists.org/forum/showthread.php?t=191623
I would like the camera to behave like in this movie from around 0:20:

Thanks in advance!
Jos van Schijndel :smiley:

P.S. How can I check if the camera script works within Blender, instead of having to save it as Runtime and then having to run the script. That takes a lot of effort if you have to test each little change this way. (Now when I press P, it will use the current camera view).

I’m pretty sure that no script is necessary for this. Just place your camera where you want it looking at the object it will follow, then hold shift, select the second object and press Control P. This will parent the camera to the other object, and it will maintain the same location and rotation relative to the Parent.

Well, it is possible the way you say it, but it doesn’t give a good game feeling.
The object you follow will not rotate at all… I like the bit where it rotates a little so you can see which direction you will be going (which can be seen in the youtube-link). Like in a real dogfighter-airplane game =)

I was thinking two things. While parenting the camera to the object:

  1. I could make an animation that makes the object rotate, and bind this animation to the keys. For example: When I press Left-arrow, the airplane gets a force to the left and I use an animation to rotate it a little to the left. (Problem when going up and left at the same time I guess)
  2. I could make a block in front of the airplane and move that, and make it so that the airplane’s front direction always points to that block. (Is harder to script?)

Or what do you guys think?

i’m not sure i understand what you mean by “the object you follow will not rotate at all”, but i agree that using Parenting is kinda lame. i have two other ideas, dependent on if you want the player to be able to look around with the camera, or just have it dynamically follow the plane.

if you just want to have the camera look at the plane, but moving around a little to give perspective, you want to use the Always>and>Camera Actuator. enter your main object and adjust the settings a little. now your camera will always stay near and look at the object.

my second suggestion (which is a little harder, but still very little scripting) would be to download a first person Mouselook demo, and import it into your game. place the main camera object inside your ship object. now add another camera, place it where you actually want to be looking and parent it to the first camera. set the second camera as the active camera, then you will have controllable third person mouselook over the plane.

hope one of those works!

With “the object you follow will not rotate at all”, I mean relative to the camera, so from your point of view, the object won’t rotate at all.

The Camera Actuator is way too slow and will not stay behind the object, so the object will be faced from the front when you turn around. This is not what I want.

Your second suggestion with the template, I will investigate that tomorrow, I’m too tired right now =)
If someone has another suggestion, let them coming!

P.S. I like to only use the keyboard, not the mouse, to move around. I want a quick paced game in the end =)

What if you stored the rotation/location data in a list (say, 20 long) and every frame you added data to it (popping the oldest one). Then, tell the camera to set its position/rotation relative to the oldest value in the list. That will cause a slight delay. If you want a longer delay then increase the length of the list.

You could enable slow parent. That let the camera smooth follow the parent.

@ Monster: Slow parenting works fine! Thanks for the suggestion!
For other people: Explanation of slow parenting can be found here:

@ TheDave: Looks like a good idea to me! Will try that when I come further with my “game”.
You say make a list with every “frame”. It there an GameLogic Sensor that activates a trigger each 0.05 seconds or something? Because when it depends on frames, it depends on how fast your computer is, right?

P.S. Anyone can tell me how to play the game without having to “save it as Runtime”? Problem I have is when I press P, I don’t see the game through the InGame camera.

The current view is used as camera of the current scene at startup from Blender.

You need to switch the view to the active camera <num0>. Then start the BGE <p>.

  • restart the scene (scene actuator)
  • explicit set the camera (scene actuator)

@josvschijndel: You could use a timer property to do that. You’re mostly right on the frames; usually your simulation is limited to 60 FPS. It is possible to make your simulations run faster than 60 FPS but I don’t know how.