Rotation problem.

Blitz3D Forums/Blitz3D Beginners Area/Rotation problem.

JustLuke(Posted 2006) [#1]
I have a game idea that uses a third person perspective viewpoint. Holding down the right mouse button and moving the mouse left or right causes the camera to rotate around the player character. The player steers the on-screen character with the arrow keys. My problem is this:

Regardless of the direction that the character appears to be facing (because the camera can be spun around him, as I said, resulting in the character potentially facing any direction of on screen rotation):

Pressing a directional arrow should make the character model rotate smoothly via the shortest direction until he faces in that direction before moving forward.

In other words:

Pressing the 'up' key will make the character turn to face away from the camera. If the player is already facing 'into' the screen then he will move forward.

Pressing the 'down' key will make the character turn to face the camera. If the player is already facing toward the camera then he will move forward.

Pressing the 'left' key will make the character turn to face the left of the screen. If the player is already facing toward the left of the screen then he will move forward.

Pressing the 'right' key will make the character turn to face the right of the screen. If the player is already facing toward the right of the screen then he will move forward.

Combinations of keys (for example, pressing 'up' and 'left') should, of course, cause the same type of behaviour for diagonal movement.

All of the above should work consistently regardless of the original rotation of the player model, which could be any angle depending on how the player rotates the camera.

Sorry for describing this in such minute, repetative detail, but I've asked for help with this before and people always seem to misunderstand what I'm after.

There does not appear to be any built in commands to exactly match my requirements. I gather that it has something to do with vectors, but I'm really not sure. My knowledge of mathematics sucks.

Can anyone help me with this, please?


Stevie G(Posted 2006) [#2]
I posted this code a while back ... maybe it can help you. User cursors and A+S to rotate the camera.

Stevie




DH(Posted 2006) [#3]
Here is some of my test code, not sure if it will work though, just wrote it on the spot here at work....




(tu) sinu(Posted 2006) [#4]
The method posted by stevie G is best and simplest and i think you should use that one :)


DH(Posted 2006) [#5]
But it doesn't do what he wants it to do. Read what he is saying carefully, then run the two versions and see which accomplishes the task he wants....

I don't see any calls to the mouse for view rotation in Stevie's code, yet:
Holding down the right mouse button and moving the mouse left or right causes the camera to rotate around


Perhaps I misread.....


Stevie G(Posted 2006) [#6]
@ Dark Half,
I was under the impression that the guy just wanted movement similar to Mario 64 which is what the code example I posted does. Sure, the camera rotation is done using keys rather than mouse but it's a one line change to implement the mouse look.

I haven't tried your code so it may well work better. That said, I really couldn't care less whether he uses your code, mine or the bastard son of both ;)

Stevie


DH(Posted 2006) [#7]
@Stevie
I could care less who's code he uses as well, hell, he might as well come up with his own.
but I've asked for help with this before and people always seem to misunderstand what I'm after.



JustLuke(Posted 2006) [#8]
Stevie G wrote:
That said, I really couldn't care less whether he uses your code, mine or the bastard son of both ;)

I chose the third option and it works very well. Thanks, guys!


(tu) sinu(Posted 2006) [#9]
aligntovector isn't that good to use, watch the angles using it, it can take an eternity using it to get to the next angle as it really slows closer to the new angle( you might overcome it with some math, i never did.)

Even with the rate parameter you don't get the desired effect.
Also the feel of the turn is better using the other method.