View Full Version : Following Camera

05-06-2014, 11:37 AM
How do I code the camera to follow a certain model from a set distance, but also be able to rotate as the model rotates?

05-06-2014, 02:37 PM
Thankfully, this is an easy problem to fix. Click the "properties" tab for the camera, and click "vehicle" and set it to that object. You can also drag and drop it into your code to switch the object's vehicle during your program. Experiment around with this!


05-06-2014, 03:42 PM
Good advice JRR-
Another option, is to position the camera to known locations that you will need tor the animation, drop a Dummy on the Camera, and set the Camera's point-of-view to the Dummy when you need it.
You might also want to experiment with telling the Camera to turn as seen by the object it's currently looking at.

The link below is to a thread in the Lounge where I posted a short video that uses these techniques. It's zipped, so click and open to do the Mummy :)


05-06-2014, 03:49 PM
Ha, That's a really funny animation! Do you still have the a2w file for it? It looks like it was supposed to be a game or something... Anyway, yes, that's another way you can do it... changing the vehicle is easier, though! :p

-Jrr ;)

05-06-2014, 03:54 PM
Yeah, It's a treasure Hunt- I used all the discussed techniques in that scene. Look for the Multiple Camera Position and Vehicle changes. He Can't get to Act 2 until He gets the key ;)

Moves on from There to multiple levels.

05-07-2014, 11:29 AM
I went into myFirstMethod, and made a code that says while true is true, the camera should be a set vehicle to the model, but when I run the program, it doesn't move anywhere.

05-07-2014, 11:55 AM
Well, maybe true is false :p The model needs to move, too. It works just fine for me. Try initially having the vehicle be the model you are going to move. I added an example. Tell if this works! If it doesn't please try attaching your Alice program to a post and we can review it. :)


05-09-2014, 11:28 AM
Are you using Alice 3.1? This file you sent me can't be read from my Alice 3.1 program, and I don't know how to move it into the Alice saved projects folder(assuming there is one). Also, I don't know how to set the camera to a vehicle, because I can't select the camera, and I can't change the model into a vehicle, because I can only change it between green and brown.

05-09-2014, 11:50 AM
No I have Alice 2. Alice 3 doesn't run on my machine. Sorry, but I don't think I can be much help on Alice 3 worlds :(


05-09-2014, 11:51 AM
Do you know any place I might look to get help, then? Or should I download Alice 2? It seems Alice 2 is a bit better than Alice 3.

05-09-2014, 11:54 AM
Oh, think I know what your problem is. Select it in the objects pane, and select the properties tab in the bottom-left area. It should have a vehicle option. It does in Alice 2, and I don't know why they would change THAT in a new version. tell me if that works or not!


05-09-2014, 01:18 PM
Try this code to see what happens

Just drag in an Alien, and pull in the code

05-12-2014, 11:39 AM
This is a picture of the Alice 3.1 menu screen.

It seems a properties tab is open, but I can't select the camera, and I think it may be because it's made as a constant, but I don't know how to make a camera that isn't a constant.

I have some code that moves a model when keys are pressed, and I want it to be like a game, which is why I want the camera to follow the model despite where it goes, or which direction it's turned, and stays at a set distance that allows a player to see what the model is doing, and what's going on around the model.

05-12-2014, 11:55 AM
Here is how it works and what it looks like in Alice 2. I don't know what it is like in Alice 3:

05-13-2014, 09:18 PM
Once you go back to "edit" mode, click on the "myFirstMethod" tab.
There should be a dropdown pane under the scene that lists the objects.
Just pick the one you want, and drag in the Procedures or Functions you need.

05-14-2014, 08:56 AM
As I said, I really know nothing about how Alice 3 runs or looks like. ;) I hope some of my tips have been useful, though!


Game master
05-15-2014, 09:53 AM
YOU CAN SELCT THE CAMERA IN ALICE 3 by going into the code view and the drop down menu allows you to use the camera, and scrolling down you should see set vehicle. You can add a new event of the scene starting and put that code in there for it to be done right at the beginning

05-17-2014, 09:13 AM
i would like t know a llitle bit more about how the veicle thing works too. what does it do an how does it work?

05-17-2014, 09:17 AM
Well, it basically changes the first object's x-y axis to that of the second object. Hence, if the second moves, the first moves according to the second's axis. The same thing with the turning and rolling. The same can be done temporarialy with the "as seen by" in the drop-down menu when you click "more" on a line of code.


05-18-2014, 11:11 AM
Well, it basically changes the first object's x-y axis to that of the second object. Hence, if the second moves, the first moves according to the second's axis. The same thing with the turning and rolling. The same can be done temporarialy with the "as seen by" in the drop-down menu when you click "more" on a line of code.


I don't believe it does anything to the first objects axis. it just changes the object in the same way as the vehicle moves, turns or rolls within the world. The easiest way to think about the vehicle property is to think about you and a car, if I set your vehicle to the car then where ever the car goes so will you. The difference is that, in Alice, you do not have to be in the car. You can be anywhere in the world and if the car move so will you.
As one example, every sub object has its object set to its parent. If you move a leg away from its parent, the leg will still move whenever the parent object does even though it is not "attached" to the body any more.
A more complex example would be a skateboard movie. In this case you want the camera to follow the skateboarder most of the time, but when the skateboarder is doing something like a spin this arrangement does not look right (the skateboarder seems to stay in one place while the world spins around her.) So before the spin you would set the camera's vehicle to the world and after you would set it back to the skateboarder.
One pitfall can be illustrated with another skateboard example, that of switching vehicles between two objects. Your program must ensure that the vehicle is never set such that two or more objects form a "loop." For instances most of the time you might want the skateboarder's vehicle set to the skateboarder, but when doing some tricks it is easier to have the skateboarder to be the vehicle for the skateboard (like when doing a flipkick.)
In this case you start out with:
Skateboarder's vehicle = Skateboard.
Skateboard's vehicle = World
and what you want to end up with is:
Skateboarder's vehicle = World.
Skateboard's vehicle = Skateboarder

Here the order matters. if you try setting the Skateboard's vehicle to the Skateboarder before changing the Skateboarder's vehicle to something other than the Skateboard, the movie will crash!
On last point, if the Skateboarder's vehicle is set to the Skateboard, the Skateboarder can move around any way you want him to while he continues to "follow" the Skateboard. So, jumping over and object while the board goes under it just becomes a matter of causing the skater to move up and down while the board (the skater's vehicle) continues forward.


05-19-2014, 01:36 PM
Mark says it all. I was going to say much the same, but got distracted working on a test.
Attached vid test asks the viewers to guess how many vehicles were set, and how many "as seen by" statements were invoked.

Watch carefully: requires a click and open to view the .wmf file.

Post your Guesses.

Will post the Alice3 proggie later :-)

05-19-2014, 02:28 PM
@MrMoke: Very funny video. I just noticed that you never seem to post your actual code, just a video. Is there a specific reason for this? Also, where did you get those characters? Did you model them yourself?

@chickentree: You make a good point, although that whole skateboard thing would be funny if you forgot to change the vehicle! ;) :p

Also, thanks for correcting me on this, both of you!

And have you ever tried telling an object to turn to face one of it's subobjects? It just spins around infinitely! :D


05-19-2014, 06:39 PM
I don't normally post the code because I tend to use them in lessons after I cobble them together, or submit them to the Alice Team for Debugging when something seems broken. Too easy for someone to copy and say "Hey Teacher, Look what I did!".

Giving someone the answer doesn't encourage them to use their brains.

05-19-2014, 07:32 PM
I figured you'd say something like that ;) It is a good reason.


05-22-2014, 09:59 PM
Had a few minutes, so I updated the video I posted earlier. It's in the post above now.:)

05-23-2014, 01:57 PM
Setting the camera's vehicle to the object you want to track is good if you want to mimic the way most first person and third person shooter games behave. If you want the camera to behave more like it's being carried by a human camera operator following your subject, take a look at how the Flight Simulator world in the Examples section of Alice 2 uses a simple distance check to keep the camera pointed at its target.