Jump to content
  • Advertisement

Archived

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

Kris2456

Rotating Player

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 position

void CPlayer::SetPlayerPosition(double X, double Y, double Z)
{

vPos = CVector3(X, Y, Z);
}

//Move Player

void CPlayer::MovePlayer(float speed)
{
vPos.x += vView.x*speed;
vPos.z -= vView.z*speed;

}

//Set View Vector

void 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 Player

void 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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!