Game Development Community

Mouse issues with onMouseDown and Mouse Face behaviour

by Adam Griffiths · in Torque Game Builder · 03/05/2008 (8:04 am) · 1 replies

Hello all, I've been tearing my hair out on this one and I'm hoping somebody might be able to point me in the right direction.

The goal is to have a ship rotating to aim at the mouse and fire towards the mouse. The ship can also move with the arrow keys meaning direction will need to change.
I have the mouse face behaviour to enable the ship to face the mouse cursor and then I wanted to have the mouse shoot behaviour to shoot the lasers.
However, my first problem is if you don't move the mouse then the rotation of the ship stays rigid until the mouse is moved and then it snaps to look at it.
My second problem is that the laser seems to be activating twice (?) but not taking the mouse position the second time and firing out another laser shot but on a 90degree vector (the rotation offset).

What I'm thinking is could I have some kind of mouse-controller which controls all the aspects of the mouse, because I think that the behaviours are conflicting with each other. If i set the mouse fire to be on the laser for example the behaviour never gets called, it seems that if anything uses the mouse then it has to have all the functions within it, two objects cant both use the mouse at the same time. Similarly, two behaviours seem to conflict if they both control the mouse. Otherwise, would it be better to not have it in a behaviour at all and simply have it as a mouseControl.cs file executed from the level startup?

Any help would be much appreciated :)

#1
03/05/2008 (8:18 am)
Here's a question for you, why don't you simply have the fire action shoot at the same rotation of the player? The player is being rotated by the mouse action, thus eliminating the need to determine where the mouse is (ie where to shoot at). In my opinion, this would be far easier to accomplish than determining mouse position twice for the same effect. I would have to assume you want your fire action to come from the front of the ship, so if you set it up so that way when there is a 0 degree rotation on the ship, then the mouse fires directly towards that 0 degree angle, and as you turn the ship, so does where the fire rotation go. This is probably the simplest solution to your needs.

The code would be something along the lines of:
t2dScene::onMouseDown(%this)
{
%rot = $player.getRotation();
fireLaser(%rot);
}
function fireLaser(%rot)
{
//Put your shooting code here and set angle to %rot
}

Hope that helps.

Good Luck