I fixed during some hours this..... but at last I could run my programm using Code::Blocks but the character stayed at the ground and it's not possible to make it move...... has anybody out there a solution for this problem.... please...... I will very grateful about this........
Thanks in advance.......
3rd Person Camera
-
- Posts: 1
- Joined: Tue Feb 02, 2010 1:00 pm
luvcraft,I tried to use your code in my own game. It's successfully compiled, but when I start program, it doesn't work. In Debug mode yellow arrow appears on this
What can I do to avoid it?
Code: Select all
core::vector3df sonic_movedir = sonic_target->getAbsolutePosition() - sonic->getPosition();
if(moving) {
sonic->setPosition(sonic->getPosition()+(sonic_movedir*moving));
moving=0;
}
/*
That's it for moving the player. Now here's the stuff for moving the camera.
While we want to camera to look directly at p1, we want its movement to be based on
a point HEIGHT above p1.
*/
camera->setTarget(sonic->getPosition());
f64 distance = camera->getPosition().getDistanceFrom(camera->getTarget()+core::vector3df(0,HEIGHT,0));
core::vector3df cam_movedir = (camera->getTarget()+core::vector3df(0,HEIGHT,0))-camera->getPosition();
cam_movedir.normalize();
/*
The camera tries to stay between 50.0f and 50.0f+MOVESPEED from HEIGHT above p1;
if it tried to stay at exactly 50.0f, it would freak out and jiggle too much.
*/
if(distance>(50.0f+MOVESPEED))
camera->setPosition(camera->getPosition()+(cam_movedir*MOVESPEED));
else if(distance<50.0f)
camera->setPosition(camera->getPosition()-(cam_movedir*MOVESPEED));
/*
The camera rotation stuff cheats a little, because instead of rotating it perfectly
around p1, it just moves the camera left or right relatively, and lets the camera
automatically adjust to the right distance.
*/
if(cam_rotate) {
core::vector3df crossy = (camera->getTarget()-camera->getPosition()).crossProduct(camera->getUpVector());
crossy.normalize();
camera->setPosition(camera->getPosition()-crossy*cam_rotate);
cam_rotate=0;