Jump to content
  • Advertisement
Sign in to follow this  
TAlchemist

3d movement - not pathfinding

This topic is 4875 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 can get my guy to turn and go forward or backwards in any direction but now i wan t to add the ability to move him to a specific place. like make the player walk to location <0,0,0>. I think i can get him to move tothe right place but i want him to turn the correct direction then walk to seem more real. this is so that i can click the ground and have the player move there, or run up to a point to do something.

Share this post


Link to post
Share on other sites
Advertisement
There's a lot to do what you may be thinking. For example, making the walk seem more real is a whole big area of research in itself. As for turning-in-place to face a direction, you can do that by changing the orientation of the character over several frames until the character is facing the correct direction---a rigid rotation. Now, this won't be realistic, but its really damned easy, relatively speaking. A more realistic, but still reasonably easy approach, would be to build animation cycles specifically to turn the character, e.g., run the "turn-45-degrees-to-the-right" cycle and then walk along the path. As for coding up a way to turn-in-place realistically about an arbitrary angle, that's still being studied and developed at the research level. There are reasonable ways to do this if you aren't looking for super-realism, say with inverse kinematics, but it'd be a bit tedious.

Now, another thing you could do (which does actually deal with pathfinding) is to find a curved path to the destination point. Find a path that begins at the start point----with a tangent direction the faces the character's current direction, and then have the path end at the destination point with a tangent pointing parallel to the vector from the character start point to the end point, or perhaps a different direction if the character must be facing a panel or other character or something. Then have the character just walk the path. As long as the curvature of the path isn't too large, it can look good enough. Commercial games do a hybrid approach. They sometimes have custom turn-X-degrees animation cycles, but for many cases will just have a character walk a curved path that has endpoint tangents the have the character face the correct direction. Some games actually do the stupid rigid rotation thing I mentioned first. You can see this in Halo, for example, if you watch carefully.

Share this post


Link to post
Share on other sites
very intresting, i like that alot the curved path. i think i will play with that idea for a bit.

But my major problem is how to compute the degrees of rotation i need to get the player pointing in any direction other than the one he is currently facing.

I cant figure how to get the angle i need to get to the final facing i need from the players location to a target point in 3d.

Share this post


Link to post
Share on other sites
It's quite easy. plenty of threads on how to calculate angles from two directions.

To make it easy, for 3D, you can split it into an elevation angle, and a rotation angle.

the rotation angle is derived from the X and Z components of directional vectors.

These don't really have to be normalised but it helps.


to calculate the angular deviation for gun rotation, it's simply

Vector Diff = Target.Position - Gun.Position;

float dot = Diff.x * Gun.Dir.x + Diff.z * Gun.Dir.z;
float cross = Diff.x * Gun.Dir.z - Diff.z * Gun.Dir.x;

float rot_dev = atan2(cross, dot);

for the elevation, it's

Diff.Normalise();

float target_elev = asin(Diff.y);

float elev_dev = target_elev - Gun.ElevationAngle;

Share this post


Link to post
Share on other sites
this is weird. i kinda got it working. it is very close. i can get it to point at something that should be 90 degrees Yaw < y rotation y is up > and it gets 80 degrees for it. i am playing with it for now though. i had to change it some.

instead of gun.dir.x and z i had to use the forward.x and forward.z for the player.

i am looking into why it is 10 degrees off now and another problem if i enter the same location in again it rotates another 80 degrees i think.

if it isnt facing strait ahead it acts funny when trying to get the rotation. overturning alot and looping around.

[Edited by - TAlchemist on June 13, 2005 2:25:07 PM]

Share this post


Link to post
Share on other sites
now it will make a 90 degree turn to the right and if i repeat the target command it will only drift off maybe by 1 degree then go back to 90 next time. But more than 90 doesnt work?

infact no matter where i target the game always turns 90 degrees to the right < along +z >

[Edited by - TAlchemist on June 14, 2005 1:05:51 PM]

Share this post


Link to post
Share on other sites
Can anyone please help me or point me in the right direction i cannot seem to get this to work.

here is what i have.
Player with
location <vector>
3 rotation angles <yaw, pitch, and roll>

all i need to do is get the player from point A <0,0,0> with all angles = 0.0; to point B < 10,0,10 >. I dont want the player to slide to the location so i need it to turn and go there.

The player can currently turn left/right <yaw> with keyboard keys then go forward or backward in what ever direction he is facing. He accelerates and then slows with a fudged resistance.

i can automate his slide to the disired location but still cannot get him to turn and face it. i can make him do a 90 degree turn to the right but that is it.

Share this post


Link to post
Share on other sites
for now i have removed the turning code and simply used an absolute movement system < just incriment the x and z coords till you get to the target >

i am moving on to getting ray picking to work. once i can find some good code to handle finding the angle between 2 points so that i can go from 1 facing to the target facing i will add it back in.

i am willing to scrap anything in my current system to handle movement if anyone has any code on how to handle position, orientation, movement from point a to point b with facing before and after.

Share this post


Link to post
Share on other sites
i have ray picking working and can launch a particle emitter object from player to ray picked point in world or move there by just sliding toward the target.

i reallly need some way to handle making the player turn around and then shoot a fireball or turn around and then slide toward the target. i have tried many ways to get an angle of the turn and increment it till i face the right way but no luck.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!