3rd Person Camera

A forum to store posts deemed exceptionally wise and useful

What do you think of the camera?

Great!!
33
46%
Good
25
35%
Bad
7
10%
Terrible
7
10%
 
Total votes : 72

I could fix something wrong in the code but........

Postby Kiki » Mon Jan 04, 2010 3:30 am

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.......
Kiki
 
Posts: 2
Joined: Mon Jan 04, 2010 3:00 am

Postby TrafficMagician » Tue Feb 02, 2010 1:09 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
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;

What can I do to avoid it?
TrafficMagician
 
Posts: 1
Joined: Tue Feb 02, 2010 1:00 pm

Previous

Return to FAQs, Tutorials, Howtos, and external tool lists

Who is online

Users browsing this forum: Google Feedfetcher and 1 guest