Game Development Community

noob OnMouseMove question

by Galcian · in Torque Game Builder · 03/02/2009 (10:31 am) · 3 replies

Hi All, I'm mucking around with a trial version trying to get the hang of it and thinking about getting a license.

For my first non-tutorial game I decided to try and remake a missile defence game I used to play Back In The Day (TM).

Anyway, to the point, I'd like to make a turret that points towards the current position of the mouse. I tried doing this via behaviours and the turret will point towards the mouse but only if the mouse is actually on the turret.

So I decided to make a fireZone trigger area, and use it's onMosueOver function through scripting to pass the info to a function on the turret class, like so:

function fireZone::onMouseMove(%this, %modifier, %worldPos)
{
%mousepos = %worldPos;

$PT.face(PT, %modifier, %mousepos);
}

$PT is defined in the onLevelLoaded for the turret as such:

function playerTurret::onLevelLoaded(%this, %scenegraph){
$PT = %this;

}

The function is called properly, but for some reason %mousePos is set to 0,0 when it's passed to playerTurret.face

Is this due to variable1 = variable2 assigning variable1 as a pointer to variable2? If so how do I get a full copy of the %worldPos variable for passing along the function/ how can I get onMouseMove to work when the mouse is not on the object in question?

Cheers
-Galcian

About the author

Recent Threads


#1
03/05/2009 (8:57 am)
Can we see the playerTurret::Face() function? My guess is that it's probably defined as:
playerTurret::Face(%this, %modifier, %mousePos). If that's the case, you don't need to explicitly state (PT...) in the parameters and instead would just pass it the %modifier and %mousePos. Although if you're not interested in anything more than the position of the mouse, you could just pass it the %mousePos.
#2
03/05/2009 (7:00 pm)
Last time I tried the TurnToFaceMouse (or similarly named) behavior, it worked great. Did you try that one?
#3
03/06/2009 (9:57 pm)
I found a bug in my behaviour and fixing it solved the problem.

Jason, you're right, I was passing it %this when i get a chance I'll try removing that and see if it helps.