Game Development Community

Aim and fire with mouse

by Richard Pettyjohn · in Torque Game Builder · 05/29/2006 (12:37 pm) · 27 replies

I'm tring to use an aiming system where you click the mouse to fire and the character fires toward the mouse. I thought that moveMap.bind(mouse0, "button0 ", "$pShip.isFiring();", "$pShip.notFiring();"); would have the ship fire when I click the mouse but it does't seem to. As for the second part I don't have a clue how to do it.

Help would be appretiated.

Edit: typos
Page«First 1 2 Next»
#21
06/21/2006 (10:07 am)
Now the player rotation is no longer random unfourtunantly the right side (if the ship is facing up) is the side that faces the mouse.
#22
06/21/2006 (10:22 am)
Ok, apparently they went against the norm of computer math and adopted a model of having 0 degrees pointing up. Usually, 0 degrees points to the right, and positive angles go counter-clockwise. The model TGB uses seems to mimic a real-life compass, at least in the case of setting rotation angles on objects.

Try changing my above code block from
%shotAngle = mRadToDeg(mAtan(%dy, %dx));
to
%shotAngle = mRadToDeg(mAtan(%dx, %dy));

I just swapped the %dx and %dy in the call to mAtan. If that seems backwards, dry changing %dy to -%dy.
#23
06/21/2006 (5:46 pm)
Thanks! Its fixed.
#24
06/22/2006 (10:41 am)
A big thanks to everyone who helped out with his problem :) We have such an awesome community!
#25
08/18/2006 (10:17 pm)
I noticed that the ship does not rotate whenever the mouse button is held down. Is there anyway to fix this?
#26
08/19/2006 (7:32 am)
@Rachid - In the same way you use "onMouseMove", also use "onMouseDragged". That way, you can hold the mouse down and it will still rotate.
#27
08/19/2006 (9:40 am)
Works great, thanks!
Page«First 1 2 Next»