How would I make a character face the direction they are moving?
by Nicolai Dutka · in Torque Game Engine · 07/19/2008 (6:02 pm) · 4 replies
Basically, I have a custom camera setup for an adventure game. The control object is $player and the camera object is $cam. I want it so that when you push left on the analog stick, the player faces left (in relevance to the camera) and then moves "forward" which is to the left. If the player pushes down and to the right, the player turns to face down and to the right, then moves that direction. I want the turn to be natural as opposed to using setTransform.
The camera is mounted to the player using setOrbitMode, so you can rotate the player without rotating the camera.
If it helps, I have the starting points to each level ALWAYS facing rotation "0 0 1 0" and the camera really never rotates throughout a level.
I am guessing this will require a basic rewrite of the movement functions in the default.bind.cs file, but I have been fighting with it for a couple hours now and not really getting the results I want.
Any ideas would be great!
The camera is mounted to the player using setOrbitMode, so you can rotate the player without rotating the camera.
If it helps, I have the starting points to each level ALWAYS facing rotation "0 0 1 0" and the camera really never rotates throughout a level.
I am guessing this will require a basic rewrite of the movement functions in the default.bind.cs file, but I have been fighting with it for a couple hours now and not really getting the results I want.
Any ideas would be great!
#2
Create a 2d vector (let's call it analogStickDir) which is the direction the analog stick is being pushed in (I have no idea how to do this, but it doesn't seem that complex. (0, 1) is up, (1,0) is right, (0, -1) is down, (-1, 0) is left and all in between.) Now you need the direction the camera is facing in world space, make another 2d vector for this (get the x&y from the camera's forward vector, normalize. Let's call it cameraDir). Now a new 2d vector to realate analogStickDir to cameraDir, moveDir, so that analogStickDir is rotated to match world space. It's hard to explain exactly what I mean there (and I forgot the method of how to :P ) but, to give an example: cameraDir (-1, 0) this would be to the left in the world, analogStickDir is (0, 1) or straight forward. moveDir = (-1, 0) to be forward in the direction of the camera.
Now get the players face direction (2d again, yay!) and interpolate between moveDir and the player's direction each frame, while having the player run forward.
Pretty bad explanation, eh?
07/19/2008 (7:30 pm)
Hmm, I got some ideas...Create a 2d vector (let's call it analogStickDir) which is the direction the analog stick is being pushed in (I have no idea how to do this, but it doesn't seem that complex. (0, 1) is up, (1,0) is right, (0, -1) is down, (-1, 0) is left and all in between.) Now you need the direction the camera is facing in world space, make another 2d vector for this (get the x&y from the camera's forward vector, normalize. Let's call it cameraDir). Now a new 2d vector to realate analogStickDir to cameraDir, moveDir, so that analogStickDir is rotated to match world space. It's hard to explain exactly what I mean there (and I forgot the method of how to :P ) but, to give an example: cameraDir (-1, 0) this would be to the left in the world, analogStickDir is (0, 1) or straight forward. moveDir = (-1, 0) to be forward in the direction of the camera.
Now get the players face direction (2d again, yay!) and interpolate between moveDir and the player's direction each frame, while having the player run forward.
Pretty bad explanation, eh?
#4
03/04/2010 (7:06 am)
Good thread. I'm going to try something like this when I get home and report back.
Torque 3D Owner Dan Keller
Default Studio Name