Need help, iTorque coding.
by Thomas Steffen · in iTorque 2D · 05/13/2012 (4:09 pm) · 4 replies
I am using iTorque. I am having issues figuring out how to create a code to make an object fire a projectile in the direction or area of the mouse cursor click(finger touched area).
About the author
#2
The issue I'm having is having the projectile go to the same area.
Here is the coding I am failing with:
I hope I am adding this to the thread correctly. I see that there is a linearVelocityX for direction, but what would I change that to? Are there other areas to modify as well?
05/13/2012 (5:39 pm)
I am using the FaceTouch.cs file from the provided tutorials and games. This behavior allows the object to face the direction that the mouse cursor(touch) is.The issue I'm having is having the projectile go to the same area.
Here is the coding I am failing with:
I hope I am adding this to the thread correctly. I see that there is a linearVelocityX for direction, but what would I change that to? Are there other areas to modify as well?
function TimerShootsAdvBehavior::fire(%this)
{
if (!isObject(%this.projectile) || !%this.owner.enabled || !%this.isToggled)
return;
%projectile = %this.projectile.cloneWithBehaviors();
%position = %this.owner.position;
if(isObject(%this.muzzleFlash))
{
%this.muzzleFlash.setVisible(!%this.muzzleFlash.getVisible());
}
if(%this.muzzlePoint > -1)
{
%muzzlePoint = %this.owner.getLinkPoint(%this.muzzlePoint);
%position = %muzzlePoint;
}
%projectile.setPosition(getWords(%position, 0, 1));
%projectile.setLinearVelocityX(%this.projectileSpeed);
%this.schedule(%this.genDelay(), "fire");
}
#3
You'll want to use
setLinearVelocityPolar(%direction, %speed)
05/13/2012 (10:51 pm)
setLinearVelocityX is just the velocity along the X axis.You'll want to use
setLinearVelocityPolar(%direction, %speed)
#4
Thank you for your help!!
05/14/2012 (5:23 am)
I got it working. I had to change the code to:%projectile.setLinearVelocityPolar(%this.owner.rotation, %this.projectileSpeed);
Thank you for your help!!
Torque Owner David Helmer
The Kids
We'll be happy to help. So first things first, can you describe the code that you're already using? If you click the "MarkupLite is enabled" link, you'll see how to add tags to make code in your posts more readable.
Once we see what you're attempting to do, we'll be able to provide better help.
Cheers.