3d Player Controls

Started by
7 comments, last by TAlchemist 18 years, 10 months ago
ok i have a test program i am developing in C++ with D3D 8.0 for now since i have some experience with it. Currently the player is the center of the screen the camera follows behind and the player can go forward or backward < absolutely + or - to Z location > and rotate left or right. The problem is i cant seem to figure how to get the player to go relatively forward or back based on which way he is facing. The camera follows even when i manual set the player position left or right < like a side step > but i cant even find how to get the acceleration to be applied in the orientation of the player. any help or links will be apretiated.
Advertisement
can someone please help me with this? this is my first posting here but i have been looking for some time. i just need some assistance getting the player to move cause once i have that i have motion for all objects.
1. Generate direction vector from the rotation in y axis of the player by

D3DXVector3 vecDir = D3DXVector3( cos(fRotY), 0, -sin(fRoty) );

2. Update the position according to the direction

posPlayer += vecDir * fSpeed;

you will find your player moving in that direction

Hope this helps u
alok
How do i get a 3d vector from a yaw and pitch angle?
i tried adapting this same 2d system using a -sin for the y axis but
the player only gets 90 degrees of accuracy bcause they
never stop moving forward
Quote:How do i get a 3d vector from a yaw and pitch angle?
i tried adapting this same 2d system using a -sin for the y axis but
the player only gets 90 degrees of accuracy bcause they
never stop moving forward
In addition to using sin(pitch) for the y component, try multiplying the x and z components by cos(pitch). (This is assuming that you want the player to be able to move up and down rather than only in the xz plane.)
I actually got xz movement.
change in x = speedZ * sin( yaw )
change in z = speedZ * cos( yaw )

i can now move anywhere in my map and turn and everything. So far i dont know how to do the change in y. I even managed to get my camera to follow in a cirlce around the player using the same formula to get the x,z coords based on the players movement and the camera's distance and yaw.
I have separate rotation and translation matrices for the player to position them in the world. What I do is take a vector for a point straight ahead of the player that is the distance away that I wish to move them, then apply the rotation matrix to that vector to get the movement component.

In my game world, the X axis points east-west, the Z axis is north-south, and the Y axis is up/down. This code is for Managed DirectX with C#:

// rotation of playerMatrix rotationMatrix = Matrix.RotationY(angle); // speed is in units/sec, elapsedSeconds is for this framefloat distance = speed * elapsedSeconds;// player starts off facing north, positive ZVector3 moveVector = new Vector3(0f, 0f, distance);// apply rotation matrix to distance calcmoveVector.TransformCoordinate(rotationMatrix);// move player position (plus sign doesn't show for some reason// so I wrote out <plus>)playerPosition = playerPosition <plus> moveVector;
I like that, let me work that over in my head and on paper a bit. I am, gooing to be rewriting my object and mesh code soon so i prolly will implement it like that since it is much easier than what i am doing now i think.

But now i have a new problem. I have x,z movement and have y <height> clamping to the terrain for simplicity < you can fly and hover and jump but still are clamped > but i need a smooth way to rotate the character to face his target location.

I can get him to move to a target location but i cannot get him to turn there first.

like i want to be able to select a spot on the ground and have him turn then run there.

[Edited by - TAlchemist on June 10, 2005 11:57:39 AM]
Hey jgoemat, i understand how you position and move yourself in space but how do you control player orientation for rendering. right now i have a vector i call rotation and i use the x,y, and z components as the radians for a rotation matrix

This topic is closed to new replies.

Advertisement