Game Development Community

Console Controls

by C. N. · in General Discussion · 08/21/2005 (7:45 pm) · 5 replies

Hi,
I'm having a problem with getting something to work. I don't have Torque yet (this week finally), but I've been trying to get 'console controls' into a graphically simple OpenGL application, just as a demo of the concept (for myself). I love console games and gameplay, always have, and that's what has lead me to this.

You know how in EVERY console game player movement is on the analog stick? You push up, player faces up then starts walking/running up, push left, player faces left, starts walking/running left, etc... I've been trying to do this for awhile and just can't seem to get it right. Programming an actual control pad, to get input that is, isn't the hard part. It's the mathematics behind the 'platformer controls' that are eluding me.

Somebody once told me that this analog stick movement is done by calculating the player's position/velocity vectors from the camera's vectors (up, lookAt, right)... Is this even close? Does Torque ship with this kind of 'gamepad' behaviour?

Any advice on how to proceed with this?

Thanks for any help.

#1
08/21/2005 (8:01 pm)
Chris there are very subtle properties and functionality of cameras in third person platformer style games. theres always either two ways the camera is handled: either the camera moves with the character automatically and repositions itself behind the character to keep him/her in view, or the camera may be manual and controlled by the player. or it may be a combination of the two. you should decide on all the little nuances and mechanics you want your camera to have since it will be tied so closely to the player movement and overall playability.

in regards to the math, youre going to want to build an axis system aligned to the current camera orientation. then horizontal movement will be achieved along the x-axis from the camera's standpoint, and lateral movement will be along the new y-axis. if you want more details let me know and i'll try to explain in more detail.
#2
08/21/2005 (8:26 pm)
Wow, that was the fastest response ever! I've heard the GG community was helpful, but whoa...

Hmm, I'm still not sure how to do that. I mean, my player has all their vectors (view, right, up, position) and the camera has the same (it's just a simple app). But how do I move the player with the analog stick? I want a Zelda/Mario64 type camera...

I'm using SDL/OpenGL. I've got my joypad data in a class. The stick values (a Vector2f) are obviously between -32000 and 32000 (er, approx), for each axis 0 and 1 (left analog). Upon stick movement I take the value and put it into the gamepad class (stickData.x and stickData.y) and scale it down so I'm not using a number in the 1000's for the math. Around here is where I get stuck. I know I need the camera's right vector for the player's X movement and the camera's view vector for the player's Z movement (in/out of the screen). Don't laugh too hard, but I know it's something like:

player.x += stickData.x * camera.GetView()...
player.y += stickData.y * camera.GetRight()...

Can anyone help with this?
#3
08/23/2005 (10:10 am)
Nobody?
#4
08/23/2005 (1:12 pm)
Chris i dont know opengl so i dont know how much help this will be to you.

in the end, what you need to do is create a 2d axis system along the ground in such a way that one axis is oriented in the same direction the camera is facing, and the other axis is perpendicular to it. the axis system wont necessarily lie on the same plane as the plane created by the view-right camera vectors because the new axis system will always be parallel to the ground.

the reason i mentioned what i did in the previous post is because the sophistication of your algorithm really depends on how dynamic your camera will be. if your camera never rotates during play, then your math will be different than for a camera which will rotate about all 3 vectors.

the reason what youre doing above doesnt work is because your not applying vector movement correctly. you should have something more along the lines of:

forward():
player.x+=stickData.x*camera.getview().x ...
player.y+=stickData.y*camera.getview().y ...

right():
player.x+=stickData.x*camera.getright().x ...
player.y+=stickData.y*camera.getright().y ...

like i said i dont know opengl or what the hell a stickdata is but im thinking this may be closer to what you want to happen.
#5
08/23/2005 (3:54 pm)
Ah,
Sorry I wasn't more in depth... StickData is a class where analog input from the gamepad goes. Axis 0 is left-right on the analog (stickData.x), Axis 1 is up-down on the analog (stickData.y).

I see what your saying.. thanks.