Hi
i'm trying to build an RPG game. Till now i've managed the RPG camera view. when i click on the screen my character runs to that location. i've kept my character as the parent of camera so as to follow my character
my problem is how to rotate my character to run towards its destination without affecting my camera. i've understood that by what angle my character will rotate its negative my camera will rotate so as not to disturb the camera. but i've no idea how to calculate this angle n how to implement to rotate my character no matter from where camera is looking from
thanx
character rotation
-
- Posts: 29
- Joined: Wed Oct 12, 2005 9:09 am
I'm not sure I understand your problem.
In general though, I wouldn't set your character as the parent of the camera. I take it that your camera is movable/rotatable by the player. In that case, just set your camera's Target to the player?
This is the line I don't understand. Rephrase?i've understood that by what angle my character will rotate its negative my camera will rotate so as not to disturb the camera.
In general though, I wouldn't set your character as the parent of the camera. I take it that your camera is movable/rotatable by the player. In that case, just set your camera's Target to the player?
-
- Posts: 206
- Joined: Thu Sep 01, 2005 9:26 pm
- Location: France
-
- Posts: 7
- Joined: Wed Sep 14, 2005 12:20 pm
my problem is with the character. when i click somewhere on the screen my character must rotate and face that direction and then translate to that position. but as my character rotates so does my camera.
only my character should rotate. for that by what angle my character is rotated so should my camera rotate in the opposite direction. thus making the user believe that only the character has rotated. i've no idea how to calculate this angle n how to implement it.
can anyone plz help?
thanx
only my character should rotate. for that by what angle my character is rotated so should my camera rotate in the opposite direction. thus making the user believe that only the character has rotated. i've no idea how to calculate this angle n how to implement it.
can anyone plz help?
thanx
-
- Posts: 10
- Joined: Thu Dec 29, 2005 2:42 pm
dont need to make your camera a child of the camera node... do something like this in your render loop
basically it uses trigonometry to position the camera a certain distance behind the playernode at all times while also making the playernode the target
to handle keyboard input use bool keys method and use something like this for forward:
reverse:
strafe left:
strafe right:
turn left:
turn right:
of course, you wouldn't put the rotation and postion declaration in each case but i did to show the readers where each value is coming from
Code: Select all
int cOffset = 0; // change this to rotate the camera around the character
int cZoom = 200; // radius.. decrease to zoom in, increase to zoom out
core::vector3df r = playernode->getRotation();
core::vector3df p = playernode->getPosition();
camera->setTarget( core::vector3df( playernode->getPosition() ) );
camera->setPosition(
core::vector3df(
( -1 * cZoom * cos( -1 * ( r.Y + cOffset ) * 3.14159265/180 ) ) + p.X,
p.Y+50,
( -1 * cZoom * sin( -1 * ( r.Y + cOffset ) * 3.14159265/180 ) ) + p.Z
)
);
to handle keyboard input use bool keys method and use something like this for forward:
Code: Select all
float speed = 4.0;
core::vector3df r = playernode->getRotation();
core::vector3df v = playernode->getPosition();
v.X = v.X + ( cos(r.Y * 3.14159265/180)*speed );
v.Z = v.Z - ( sin(r.Y * 3.14159265/180)*speed );
playernode->setPosition(v);
Code: Select all
float speed = 4.0;
core::vector3df r = playernode->getRotation();
core::vector3df v = playernode->getPosition();
v.X = v.X - ( cos(r.Y * 3.14159265/180)*speed );
v.Z = v.Z + ( sin(r.Y * 3.14159265/180)*speed );
playernode->setPosition(v);
Code: Select all
float speed = 4.0;
core::vector3df r = playernode->getRotation();
core::vector3df v = playernode->getPosition();
v.X = v.X + ( cos((r.Y-90) * 3.14159265/180)*speed );
v.Z = v.Z - ( sin((r.Y-90) * 3.14159265/180)*speed );
playernode->setPosition(v);
Code: Select all
float speed = 4.0;
core::vector3df r = playernode->getRotation();
core::vector3df v = playernode->getPosition();
v.X = v.X + ( cos((r.Y+90) * 3.14159265/180)*speed );
v.Z = v.Z - ( sin((r.Y+90) * 3.14159265/180)*speed );
playernode->setPosition(v);
Code: Select all
core::vector3df r = playernode->getRotation();
r.Y = r.Y - 4.0f;
playernode->setRotation(r);
Code: Select all
core::vector3df r = playernode->getRotation();
r.Y = r.Y + 4.0f;
playernode->setRotation(r);