blenderNetwork patreon blender-logos d heart user th book photo pencil map-marker chevron-right comment comments twitter facebook rss chain navicon google-plus envelope linkedin calendar-o tumblr reddit stumbleupon share-alt blogger flattr flag

Blender Game Engine - Track To

Blender 3d tutorial

The author releases permissions for this tutorial to Dark Scarab to distribute this tutorial as desired. Go to www.darkscarab.com to acquire authorizations. Also, join the community!

If you are a beginner to the Blender Game Engine, it is recommended that you download with the link above. It is not necessary if you believe that you can understand the concept of this tutorial without it. This tutorial will show you how to make objects track to other objects. Simply, it makes one object follow another object in the Blender Game Engine. Note: This tutorial was written with Blender 2.48a.

Our goal is to get the security camera following ("watching") wherever the camera (that's you) goes. To do that, we will use a BGE built-in function - track to via the edit object actuator. No python required! The image below is the scene we will be working with.

001.jpg

This tutorial will take the following steps to get to that goal:

  • Change objects to the appropriate actor types.
  • Set camera controls.
  • Change the "centers" of objects so that they can pivot more accurately.
  • Use the "track to" function to render camera tracking.

If you already know how to accomplish some of these, feel free to skip ahead of sections.

Setting the Controls

For our purpose, we do not want our camera to fall to the ground. This time, we'll just make it static. By default, it should already be 'static', but you might want to check anyways.

  • Right click on our view camera (NOT to be mixed up with the security camera - mesh)
  • Click on the logic tab or just hit 'F4'.
  • Make sure the actor type is 'static'. If not, click on the box on the top-left corner andselect 'static'.
002.jpg

Next, under Sensors, hit 'add' 4 times. Do that for the Controllers and Actuators columns as well. Recreate what I have done in the picture below:

003.jpg

That's all that's to it for the controls. Turn on 'NumLock', hit 'Numpad 0', and then press 'p' to run the game engine thus far. If the controls seem too slow for your liking, play around with the numbers!

Working with Track To

In order for the surveillance camera to follow our camera, we have to use Track To. There are some prerequisites before using Track To, so we will have to set up the security camera properly.

Get yourself into wireframe mode: click on the button right of "Object Mode" and click on wireframe. Alternately, just push 'z'. In the building, you will see that I have hidden a mesh (the security camera) inside. Right click on the security camera and go into edit mode (tab). For our purpose, we would like it so that the camera swivels on its end, not in the middle and especially not on its lens (the back of the security camera would then point at our camera). Select the center vertex on the end side.

004.jpg

After that, push shift+s. A menu will pop up, select 'cursor->selection'. Get out of edit mode (tab). You should now be in object Mode. Go to editing (F9) and click on 'center cursor' in the 'mesh' tab. Our surveillance camera should now have a center on its end. Select the security camera and push 'r' twice. Move your cursor around and you will find that the surveillance camera pivots on its end. This is what we want. Right click to get out of trackball mode.

Now comes the part where we get to use Track To. Select the security camera and click on the Logic button (F4). This camera should be already set to 'static'. Set it to 'static' if it's not. Click add once for each of the Sensors, Controllers, and Actuators columns. Enter in the following information:

005.jpg

I will now explain what the parameters of Track To are.

  • OB: -Sets exactly what object is to be tracked to.
  • Time: -How long it takes for the object to track to. The bigger the number, the slower it takes for the object to track.
  • 3D -If you didn't set this, the object would track the other object on a 2D plane. This would not allow the camera to bend up or down. Selecting 3D enables it to do just that.

You should now hop into the camera and run the game (numpad 0, p). Notice that the camera follows your location! (If you see red, that's supposed to be the lens of the camera. I didn't make the camera graphical enough for you to really make out the lens) It follows it a bit slowly, but you can change that if you'd like. That's all there is to Track To.

006.jpg

Variations

I encourage you to play around with the BGE to get to know it. Things are MUCH easier and obvious when you just fiddle around a bit. That said, here's some variations you could try with Track-To.

  1. Try to make it more realistic by having the security camera only track while you are near it.
  2. Try to make the camera only track when a certain key is pressed.
  3. Make another surveillance camera; this time, set up the security camera without looking at instructions.

BONUS Challenge: Make a scene where you can pick up a gun. Make the gun track to a target automatically like the auto aim feature on a lot of first person shooter games. Hint: You will want to check out the other tutorials on Darkscarab.com

That's all for now. Keep practicing with the BGE. If you find something awesome and would like to write a tutorial, I encourage you to do so. You can post and find more great tutorials at www.Darkscarab.com. Join the community!

Popular Now

Comments