3rd person camera?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
SARIN
Posts: 139
Joined: Fri Oct 29, 2004 3:53 am

3rd person camera?

Post by SARIN »

how do you do a 3rd person cam? I no u have to use angles and all those things im not good at. also, i would like to know how to move a simple player forward. I dont mean by the flystraight animator or anyhting, but by calculating movement and angle, and the adding in a camera behind the player. can anyone help?
Flatline
Posts: 49
Joined: Fri Sep 03, 2004 7:46 am
Location: England

Post by Flatline »

There are about a dozen threads on this topic on the forum, if only people would look.
SARIN
Posts: 139
Joined: Fri Oct 29, 2004 3:53 am

Post by SARIN »

i looked, but i didnt find wat i wanted.

I think i solved my problem tho. can any1 answer if this can work or not?
take the sin of angley(of ur object), times it by howver much you want to move, and add it to the x position, then take the cos of angle y, times it by the same #, add it to ur z position.(assuming you want 0 degrees to equal facing forward on the z axis)
for the camera, you do the same, except for each (x,z), take away as many as u want(like if u want the camera to be 200 away, -200).
it might look something like this in the device run main loop, basing it off the examples:
(node is object,cam is camera, and ay is angle y)


if(keys[KEY_UP])
{
vector3df v = node->getPosition();
v.X = v.X+20sin(ay);
v.Z = v.Z+20cos(ay);
node->setPosition(v);
}

vector3df cv = node->getPosition();
cv.X = cv.X-200sin(ay);
cv.Z = cv.Z-200cos(ay);
cam->setPosition(cv);

is this close to being right? i only want to move based on the values, not on any special irrlicht things like the animators.
Eight

Post by Eight »

Well... I'll answer this out of gratitude to previous posters whose comments helped me out when I was struggling with the same thing.

If you search then somewhere in there you'll find a post with some sample code for a camera animator. I used that as a basis/learning tool.

I created two animators to be attached to my camera - a watch animator and a follow animator. The first sets the target of the camera to be the location of the player mesh. Because the OnEvent method runs so regularly then this works smoothly.

The second takes the rotation and position of the player, and puts the camera a little bit behind him (on the same line of rotation).

Add both animators to a camera and you get a pretty regular sort of 3rd person camera.

This is just a little overview of what I did to point you in a possible direction. I found updating the camera location and target within the main game loop caused hideous flickering and distortion; whereas an animator kept it all looking sweet.

E
SARIN
Posts: 139
Joined: Fri Oct 29, 2004 3:53 am

Post by SARIN »

ya, i no it can be done with animators, but i mean with simple math. if i wanted to use animators, then i would have found it with the search prob, but i want math angles and stuff.
but nvm, i think i solved my prob. ill post again if it works(same solution as above)
Post Reply