Advanced level programmers?
by Robert Carroll · in Torque Game Builder · 09/22/2009 (11:04 pm) · 4 replies
Can anyone Pls Pls Pls help me This code will complete my game im a novice at Scripting.
How would I get this to fire a projectile by clicking anywhere in the World/SceneWindow2D.
In the origonal I have to click on the object.
~~~~~~~~~~~
I Cut out the begening and End there uneeded
~~~~~~~~~~~
// begin firing when mouse down
function MouseDownFire::onMouseDown(%this, %modifier, %worldPosition, %mouseClicks)
{
%this.fire(1);
}
// stop firing when mouse up
function MouseDownFire::onMouseDown(%this, %modifier, %worldPosition, %mouseClicks)
{
%this.fire(0);
}
function MouseDownBehavior::fire(%this, %val)
{
if (%val == 0)
{
cancel(%this.fireSchedule);
return;
}
if (!isObject(%this.projectile))
return;
%projectile = %this.projectile.cloneWithBehaviors();
%projectile.setPosition(%this.owner.position);
%projectile.setRotation(%this.owner.rotation);
%projectile.setLinearVelocityPolar(%this.owner.rotation, %this.projectileSpeed);
How would I get this to fire a projectile by clicking anywhere in the World/SceneWindow2D.
In the origonal I have to click on the object.
~~~~~~~~~~~
I Cut out the begening and End there uneeded
~~~~~~~~~~~
// begin firing when mouse down
function MouseDownFire::onMouseDown(%this, %modifier, %worldPosition, %mouseClicks)
{
%this.fire(1);
}
// stop firing when mouse up
function MouseDownFire::onMouseDown(%this, %modifier, %worldPosition, %mouseClicks)
{
%this.fire(0);
}
function MouseDownBehavior::fire(%this, %val)
{
if (%val == 0)
{
cancel(%this.fireSchedule);
return;
}
if (!isObject(%this.projectile))
return;
%projectile = %this.projectile.cloneWithBehaviors();
%projectile.setPosition(%this.owner.position);
%projectile.setRotation(%this.owner.rotation);
%projectile.setLinearVelocityPolar(%this.owner.rotation, %this.projectileSpeed);
About the author
Stay Up all night playing PS3 ;) add me PSN: RCBASEBALL13.
#2
09/23/2009 (7:24 pm)
Im a total noob Im sorry I didn't get any of that. I have it to Facce the mouse so it would be like a clock. And with all the calling on the object how do I call with the behavior?
#3
That said, a rough idea might be like...
essentially what I am getting at is that I think the fire should be associated with the sceneWindow2D, because you are not clicking on the object, you are clicking on (virtually) empty space.
09/24/2009 (2:10 am)
I am no expert Robert, but from my understanding, as I have a similar issue, is that you must call the sceneWindow2D. The sceneWndow2D is your camera view. So what ever is inside that view, presuming this is the area where you click, you will get a measured response.That said, a rough idea might be like...
function fire::onMouseDown(%this, %modifier, %worldPosition, %mouseClicks)
{
if (%this.worldPosition)
{
/// I am unsure how to declare this
%this.worldPosition.isSomewhereOnSceneWindow2D
/// I have tried to tell it to fire if the clicked position,
///which it is, is and where on the sceneWindow2D
%this.fire(0);
}
}essentially what I am getting at is that I think the fire should be associated with the sceneWindow2D, because you are not clicking on the object, you are clicking on (virtually) empty space.
#4
http://i707.photobucket.com/albums/ww73/RcBaseball13/ES.png
Im making a zombie game thats why I needed the mouse shoots behavior.
09/24/2009 (2:24 am)
Thats what I tried from some other code but the Behavors would be 10 times better. I found a "Complicated Way around this though, I made a Ivisible picture or sceneObject and put that as the behavior and mounted the gun onto that. http://i707.photobucket.com/albums/ww73/RcBaseball13/ES.png
Im making a zombie game thats why I needed the mouse shoots behavior.
Torque Owner NCGames
First, make sure that mouse events are enabled on the object. Next, make the call to the behavior and not to the object. After that, set the position of the object equal to the position of the mouse upon being held down. Notice that this will not update if he moves his mouse before he lifts it. Last, don't forget that you need to save the event within the object to access it later.