Game Development Community

adding an offset to the shoots behavior

by brandon young · in Torque Game Builder · 12/04/2012 (7:13 pm) · 5 replies

Hi. Im new to torque 2d and torque script. How can i add an offset to the projectile that is being shot using the shoots behavior.

%projectile.setPosition(%this.owner.position);

This spawns a projectile from the center of the sprite that is doing the shooting.
If i wanted to offest the projectile say 34 pixels on the Y axis, how would i do that?
How can i get myself familiar with torque script? I generaly like to figure out these problems on my own, but honestly dont even know how to start this with torque script.
Thanks in advance.

About the author


#1
12/04/2012 (8:25 pm)
There are all of the tutorials in the official documentation. You'll probably want to look at Game Tutorials -> Behaviors:

docs.garagegames.com/tgb/official/

I've never used this site, but it seems really good:

torquescripter.com/index.html
____________________

Quote:%projectile.setPosition(%this.owner.position);

That probably is the line that you want to edit - but think of it as adding an offset to the shooter, not the projectile. But yes, the shooter does pass the offset down to the projectile.

Let us know if you get stuck.
#2
12/04/2012 (9:48 pm)
Thanks for your reply. I have read the official documentation. I go back to it continously. I have done the tutorials. An offset as i described is not covered, as far as i can tell. I could eaisly be wrong, as there is alot of documentation there. The behavior shooter tutorial does not cover an offset either.

"but think of it as adding an offset to the shooter, not the projectile. But yes, the shooter does pass the offset down to the projectile."

yes, correct. The object doing the shooting, in this case a player, using the shooting behavior, is telling a projectile object at what position to spawn. Im looking to spawn my projectile in a different location than center.
#3
12/04/2012 (10:32 pm)
Quote:yes, correct. The object doing the shooting, in this case a player, using the shooting behavior, is telling a projectile object at what position to spawn. Im looking to spawn my projectile in a different location than center.

Exactly, awesome. Much better explained than what I said.

Yes, there is nothing in the tutorials that directly or indirectly talk about adding an offset to a shooter behavior; however, everything you need to do what you want is there. It just requires some synthesis.


So, you want a variable offset on any object that is a shooter.
->Therefore, you need to add a field to the shooter behavior
--*Perhaps you need to look up how to add a field to a behavior?

The next question to answer is what type of field should this be?
->Your turn. What do you think?
#4
12/05/2012 (5:08 pm)
Add a link point to your object and have the projectile spawn at it. Code similar to the following....

%sprite = <myFiringObject>; // replace that with your shooter.

   %muzzlePoint = getWords(%sprite.LinkPoints, 0, 1);
      
   %muzzlePoint.x *= (%sprite.getSizeX()/2);
   %muzzlePoint.y *= (%sprite.getSizeY()/-2);

   %projectile.setPosition(%muzzlePoint.x, %muzzlePoint.y);

Probably will have to tweak that somewhat....

Hope it's useful.
#5
12/05/2012 (5:11 pm)
Aw, crap - can't remember when we tweaked setPosition.... Might have to call %projectile.setPosition(%muzzlePosition) instead.