#### Archived

This topic is now archived and is closed to further replies.

# Rotating Player

This topic is 5248 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a player class which handles how my player model moves. What iw ant is for the player tobe able to control it, with the mouse. I have a crappy system which i made which uses fairly retarded vectors to make the player strafe. But itlooks rubish. I need an explenation of the maths behing making the player rotate and go down the view vector. PS.Im not talking bout the camera, imusing a model, so no gluLookAt please! ------------ "Here lies a toppled God, His fall was not a small one, We but built his pedastle, A narrow, and a tall one" Frank Herbert (Dune:Messiah)

##### Share on other sites
ok, i know it has something to o with PosX += sin(angle)* speed.
But its no working, and im not sure if im doing it right..

##### Share on other sites
to move forward:
posx += sin(angleY)*speed
posz -= cos(angleY)*speed
to strafe:
posx += sin(angleY+90)*speed //90 in degrees
posz -= cos(angleY+90)*speed

then in your idle statement or whatever:
capture your mouse position
subdivide mouse position with your previous captured mouse position
set angleY = mouseposX
set angleX = mouseposY

##### Share on other sites
Nope, it does just not work atall. Do u think u cudpost me some code, i excpect ill see it better then.

##### Share on other sites
There is no reason for JSoftware''s code not to work.Except that sin,cos takes radians as arguments.Maybe the problem is there.If you use degrees,convert them to radians first and then pass them to sin() or cos().

##### Share on other sites
I tried this but it dosnt work. Im sure im doing something wrong, here is my code:
CPlayer::CPlayer(){    double PlayerX = 0;    double PlayerY = 0;    double PlayerZ = 0;        double PlayerRX = 0;    double PlayerRY = 0;    double PlayerRZ = 0;        CVector3 vView = CVector3(0.0, 0.0, 1.0);    CVector3 vPos = CVector3(0, 0, 0);        float AngleX = 0;}//Set positionvoid CPlayer::SetPlayerPosition(double X, double Y, double Z){    vPos = CVector3(X, Y, Z);}//Move Playervoid CPlayer::MovePlayer(float speed){    vPos.x += vView.x*speed;    vPos.z -= vView.z*speed;    }//Set View Vectorvoid CPlayer::SetViewVector(){    POINT mouse;    GetCursorPos(&mouse);    float AngleX = mouse.x*(PI/180);    float AngleY = mouse.y*(PI/180);        vView.x = cos(AngleY);    vView.z = sin(AngleY);    //vView.z = sin(AngleX);}//Draw Playervoid CPlayer::DrawPlayer(){    glPushMatrix();     glTranslated(vPos.x,vPos.y,vPos.z);    glRotatef(PlayerRX,1,0,0);    glRotatef(PlayerRY,0,1,0);    glRotatef(PlayerRZ,0,0,1);    TieFighter();    glPopMatrix(); }

My Player does not turn, but merley strafes and it does not listen properly to mouse commands, and does the opposite to hat the mouse says, or sometimes it dosnt (IE. random).

[edited by - Kris2456 on June 9, 2004 3:56:08 PM]

##### Share on other sites
In the SetViewVector(),you get the mouse pos and build the view vector,but I don''t see anywhere to call RotatePlayer() to load
PlayerR* with the angle values.But you use PlayerR* to rotate the model.With this piece of code,PlayerR* are all zero all the time.Maybe that''s the problem.

##### Share on other sites
I have an idea. Ignore all i said before, thisis what i want to know how to do this:

            C      |    /      |   /      |  /      | /------o------      |      |      |      |[/CODE]i want my player "o" tomove along vector C, but i also want to change the direction of vector C so the player can rotate. This way theplayer can fly around,when i add Y.

##### Share on other sites
am i the only one who uses xy for the forward side, and z as height?

1. 1
Rutin
45
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632987
• Total Posts
3009729
• ### Who's Online (See full list)

There are no registered users currently online

×