Game Development Community

Dual stick shooter code

by John Bura · in Torque X 2D · 08/31/2010 (6:52 pm) · 5 replies

Hi Guys,

Im trying to write a dual stick shooter code but it doesn't seem to be working. Ive spent an embarrassing amount of time trying to get this done. :P This is just part 1 where I can get the controllers to work. The next step will be to fire when the stick is all the way to one side. I think that that part should be easy.

SceneObject.Rotation= (float)Math.Atan2((double)move.Sticks[1].Y, -(double)move.Sticks[1].X);
                Vector2 direction = T2DVectorUtil.VectorFromAngle(SceneObject.Rotation);

Has anybody got this to work :)

#1
09/01/2010 (6:23 am)
First of all, you don't need to use the angle if you just want a directional vector, all you need to do is this:
Vector2 direction = move.Sticks[1];
direction.Normalize();

Finally, rotation is in degrees with torque, so you'll need to convert from radians to degrees in order to set your rotation right:
SceneObject.SetRotation((float)(Math.Atan2(move.Sticks[1].Y, -move.Sticks[1].X)*180/Math.PI),true);
Should do it.
#2
09/01/2010 (1:50 pm)
@ Christopher

I tried something like this but it says I can't covert vector 2 to movestick.

Vector2 direction = move.Sticks[1];
                direction.Normalize();

Does anybody know how to solve this :)
#3
09/01/2010 (3:28 pm)
If I'm understanding the question correctly, this should work

if(move.Sticks[0].X != 0f || move.Sticks[0].Y != 0f)
     _sceneObject.Rotation = T2DVectorUtil.AngleFromVector(new Vector2(move.Sticks[0].X, -move.Sticks[0].Y));
#4
09/01/2010 (3:40 pm)
Thanks that worked perfectly! All I have to do is implement the fire code and it should be done :).
#5
09/01/2010 (10:20 pm)
I'm sorry, it was late, I made a mistake. You'll have to convert it to a Vector as the sticks are treated differently by torque.

So you'd have to do:
Vector2 direction = new Vector2(move.Sticks[1].X, move.Sticks[1].Y);
direction.Normalize();