Jump to content

  • Log In with Google      Sign In   
  • Create Account


How to make a player look in a direction?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 newtechnology   Members   -  Reputation: 641

Like
0Likes
Like

Posted 16 June 2014 - 06:38 AM

I'm trying to achieve what he did : http://www.gamedev.net/topic/655859-rotate-character-spine-so-weapon-aims-at-target/
to be honest, I don't understand many things. How to make a character look and shoot at a particular direction? I know I should do at pick ray from the center of screen  then I would have the vector between weapon and picked point but how to use this vector to make player aim in a direction? I'm making a FPS game but I would need that because I would have to display other players in my game as 3D characters not just hands and gun since its multiplayer project. This screenshot explains it better :
cod4-21.jpg

As you can see that I can only see my hands and gun from my first person perspective but I can see the full body of other players and where they are looking so I must make other players in the game look where they're looking from their first person perspective on their PC. 


Edited by newtechnology, 16 June 2014 - 06:51 AM.


Sponsor:

#2 Buckeye   Crossbones+   -  Reputation: 4006

Like
0Likes
Like

Posted 16 June 2014 - 08:03 AM

Most commonly in FPS games, the user's weapons (as you've shown them) are always drawn in one position (center-screen). The user uses the mouse or keypresses to turn his character left/right/up/down, and, with either a mouse button or keypress, fires the weapon. The projectile then travels (in the 3D world) from the weapon position (at that moment) in the direction the user is facing (at that moment.) There's no picking needed, in that case. The player simply has, as attributes, a position and direction which the player manipulates.

 

If that's not what you'd like to happen, can you explain a bit more?


Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.


#3 newtechnology   Members   -  Reputation: 641

Like
0Likes
Like

Posted 16 June 2014 - 10:32 AM

Most commonly in FPS games, the user's weapons (as you've shown them) are always drawn in one position (center-screen). The user uses the mouse or keypresses to turn his character left/right/up/down, and, with either a mouse button or keypress, fires the weapon. The projectile then travels (in the 3D world) from the weapon position (at that moment) in the direction the user is facing (at that moment.) There's no picking needed, in that case. The player simply has, as attributes, a position and direction which the player manipulates.

If that's not what you'd like to happen, can you explain a bit more?

Well that's not i asked and i already know that. My game is going to support multiplayer so i need to display full 3d model of the character of other players and therefore they should look and aim at the point where the player is looking i.e client sends information regarding where he is looking and we use this information to display and to make the 3ď model look in the direction where client is looking.



For example: i'm playing an online fps game with my friend and when he moves in his world, i can see a 3d model of him moving in my world (he can see only his hands and gun in his perspective since its fps game while i can see his whole 3d model and the same way, i can only see my hands and gun while he can see full 3d model of mine). The same way when he looks at the sky, i can see a 3d model of him looking at the sky. This is what i'm taking about. How to make him look in a sky i.e in a particular direction?

#4 Buckeye   Crossbones+   -  Reputation: 4006

Like
1Likes
Like

Posted 16 June 2014 - 12:14 PM


How to make him look in a sky i.e in a particular direction?

 

Are you familiar with skinned meshes and animating them? If not, I'd suggest you setup a project to render animated skinned meshes, and get a thorough understanding of how bone orientations work. You'll need to set up a routine for orienting the world matrix for a character, and routine(s) for orienting individual bones (neck bone rotation for tilting up/down and rotating left/right).

 

That is, when another player orients himself, you'll need to get (over the network) his position and orientation, both general direction and specific "pose" direction/information. On your screen, his character will be rendered with specific bones oriented appropriately. If he's looking up to his right, you'll have to decide what bones to rotate to tilt his head back and rotate it in the direction he's looking.

 

That will require calculating relative angles between a character's facing direction, and the direction up/down/left/right for various bones (neck, hip, etc.) You'll have to decide whether to calculate bone orientations using forward or inverse kinetics.


Edited by Buckeye, 16 June 2014 - 12:15 PM.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.


#5 newtechnology   Members   -  Reputation: 641

Like
0Likes
Like

Posted 17 June 2014 - 01:22 AM

How to make him look in a sky i.e in a particular direction?


Are you familiar with skinned meshes and animating them? If not, I'd suggest you setup a project to render animated skinned meshes, and get a thorough understanding of how bone orientations work. You'll need to set up a routine for orienting the world matrix for a character, and routine(s) for orienting individual bones (neck bone rotation for tilting up/down and rotating left/right).

That is, when another player orients himself, you'll need to get (over the network) his position and orientation, both general direction and specific "pose" direction/information. On your screen, his character will be rendered with specific bones oriented appropriately. If he's looking up to his right, you'll have to decide what bones to rotate to tilt his head back and rotate it in the direction he's looking.

That will require calculating relative angles between a character's facing direction, and the direction up/down/left/right for various bones (neck, hip, etc.) You'll have to decide whether to calculate bone orientations using forward or inverse kinetics.
Yeah, I'm familiar with the concepts of animation and skinned mesh. In fact, I already have skinned models implemented into my game. Can you please explain me the math of this and what is inverse/forward kinematics? I think its related to physics.

#6 Kryzon   Prime Members   -  Reputation: 2683

Like
0Likes
Like

Posted 17 June 2014 - 03:07 AM

Have you considered the method suggested in the second-to-last post in that thread that you referenced?

#7 newtechnology   Members   -  Reputation: 641

Like
0Likes
Like

Posted 18 June 2014 - 12:17 AM

Have you considered the method suggested in the second-to-last post in that thread that you referenced?

 

 

 

tbh, I don't understand it. I just want to know the theory behind what I asked.

Edited by newtechnology, 18 June 2014 - 12:35 AM.


#8 Kryzon   Prime Members   -  Reputation: 2683

Like
0Likes
Like

Posted 18 June 2014 - 01:28 AM

Hello. You should watch the GDC video that I linked in that post, it explains more about additive animation.

It goes like this. You retrieve the mouse velocity for the current frame. It's a 2D vector representing the amount of pixels that the cursor moved from the last frame. You rotate your camera and weapon based on that, with the X component serving as the (negative) yaw rotation (Y axis) and the Y component serving as the pitch rotation (X axis).

You retrieve the world-space Euler rotation angles of your first-person camera, and send these angles to the other players.
In their clients, they will represent you with a 3rd person character that will aim based on the additive blend of 3 character poses: one with the character aiming down (+90º in the X axis), one with him aiming at the horizon, and one with him aiming at the sky (-90º in the X axis).
You will blend between these poses based on the sine of the X angle of the camera from the player they are trying to represent in 3rd person. This is a linear interpolation.

In pseudo-code, the expression for the final animated 3rd person pose be something like this:
If ( otherPlayer.eulerX > 0.0 ) {
	// Player is facing down. Represent him with a blend between aim-horizon and aim-down poses.
	otherPlayer.SetPose( otherPlayer.aimHorizon.Blend( otherPlayer.aimDown, Sin( otherPlayer.eulerX ) ) ) 
}Else {
	// Player is facing up. Represent him with a blend between aim-horizon and aim-up poses.
	otherPlayer.SetPose( otherPlayer.aimHorizon.Blend( otherPlayer.aimUp, Abs( Sin( otherPlayer.eulerX ) ) ) )
}
Using the Sin() value as the "alpha" in a linear interpolation.

#9 newtechnology   Members   -  Reputation: 641

Like
0Likes
Like

Posted 18 June 2014 - 02:42 AM

Hello. You should watch the GDC video that I linked in that post, it explains more about additive animation.

It goes like this. You retrieve the mouse velocity for the current frame. It's a 2D vector representing the amount of pixels that the cursor moved from the last frame. You rotate your camera and weapon based on that, with the X component serving as the (negative) yaw rotation (Y axis) and the Y component serving as the pitch rotation (X axis).

You retrieve the world-space Euler rotation angles of your first-person camera, and send these angles to the other players.
In their clients, they will represent you with a 3rd person character that will aim based on the additive blend of 3 character poses: one with the character aiming down (+90º in the X axis), one with him aiming at the horizon, and one with him aiming at the sky (-90º in the X axis).
You will blend between these poses based on the sine of the X angle of the camera from the player they are trying to represent in 3rd person. This is a linear interpolation.

In pseudo-code, the expression for the final animated 3rd person pose be something like this:

If ( otherPlayer.eulerX > 0.0 ) {
	// Player is facing down. Represent him with a blend between aim-horizon and aim-down poses.
	otherPlayer.SetPose( otherPlayer.aimHorizon.Blend( otherPlayer.aimDown, Sin( otherPlayer.eulerX ) ) ) 
}Else {
	// Player is facing up. Represent him with a blend between aim-horizon and aim-up poses.
	otherPlayer.SetPose( otherPlayer.aimHorizon.Blend( otherPlayer.aimUp, Abs( Sin( otherPlayer.eulerX ) ) ) )
}
Using the Sin() value as the "alpha" in a linear interpolation.

 

Okay so I've started understanding this but can I pre-calculate interpolation? maybe not. Also What is alpha? (The Angle is basically used as blend factor, right?) 
Is there any other simple technique (Like bone rotation.) ?



#10 Kryzon   Prime Members   -  Reputation: 2683

Like
1Likes
Like

Posted 18 June 2014 - 04:02 PM

- I believe that you can pre-calculate the interpolated poses from aiming up all the way to aiming down as a sequence of 180 frames (one frame for each degree of front rotation).
This would lose the benefit of interpolating poses in real time, which spares memory, but would be simpler to use - get the X rotation of the player from his FPS view and use that angle to pick a pose to represent him as a 3rd person character, and layer this pose with running or jumping sequences etc. so that the 3rd person character can move around while aiming in that direction.
otherPlayer.SetPose( otherPlayer.aimPoses( Int( otherPlayer.eulerX + 90.0 ) ) )
You don't need to pre-calculate the interpolated poses in programming, if you're going in this direction. You only need a 180 frame animation sequence with aim-up in the first frame as a keyframe, and aim-down as the last frame as a keyframe. You can do this in 3ds Max or Blender, which will interpolate between the two poses for each of the 180 frames, and back in your game engine you pick the frame that represents the player rotation. Just make sure that the tangents for the keyframes are set to "LINEAR," so that each frame accounts for an equal amount of change.

- "Alpha" is a possible way to name the interpolation factor; this comes from graphics programming and alpha blending. I believe "s" and "t" are also used to name this parameter.
What you use to calculate this value depends on what you're going to do with the poses. To calculate a blend factor you can use the angle of the player, or the sine function of that angle plus some offset etc.
https://en.wikipedia.org/wiki/Linear_interpolation#Programming_language_support

- I don't think there's any simpler way to do this. When you can set up poses for each critical point (down, middle and up), you can position every limb like they should be, and the software will interpolate between them and make it look natural.
Doing this in code requires much more time and effort, and may not look as natural.

In any case, your own experimentation will give you more answers than what most could say here.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS