FaceMouse and getrotation
by Matt Bates · in Torque Game Builder · 04/07/2007 (5:24 am) · 2 replies
I have written a small custom behavior that applies a impulse force to an object in the direction its facing on mousedown and it work's great. I've tried combining this with the FaceMouse behavior and it works great when applying the force the first time but after that my behavior doesn't recognize any updates to the rotation.
The echo is there for debugging benefit, if any one wouldn't mind giving this a whirl and post back what result you get would be awesome.
if (!isObject(MouseDownImpulseBehavior))
{
%template = new BehaviorTemplate(MouseDownImpulseBehavior);
%template.friendlyName = "Mouse Down Impulse Force";
%template.behaviorType = "Input";
%template.description = "Clicking on the object applies a impulse force to it";
%template.addBehaviorField(force, "Force to apply to the object", float, 10.0);
%template.addBehaviorField(angle, "Angle at which to apply force (-1 for direction facing)", float, 0.0);
}
function MouseDownImpulseBehavior::onBehaviorAdd(%this)
{
%this.owner.setUseMouseEvents(true);
}
function MouseDownImpulseBehavior::onMouseDown(%this, %modifier, %worldPos)
{
if (%this.angle == -1)
%this.angle = %this.owner.getrotation();
echo(%this.angle);
%this.owner.setImpulseForcePolar(%this.angle, %this.force);
}The echo is there for debugging benefit, if any one wouldn't mind giving this a whirl and post back what result you get would be awesome.
About the author
#2
04/07/2007 (6:20 am)
Ah yes, thats a fairly stupid hole. Thanks for the pointer, fresh eyes always help.
Torque Owner Magnus Blikstad
if (%this.angle == -1)
%this.angle = %this.owner.getrotation();
You're setting the angle to something other than -1... next time this statement won't be true.