Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Throwing/projecting an actor constrained to my Player actor.

ZeroCredibilityZeroCredibility Posts: 16Member
edited January 2012 in Working with GS (Mac)
It seems I have to ask for help at almost every step of the way, so I here I go again.
In my first attempt at a game, I have my player actor moving all over the scene which is set up to be top down like smash TV or Bomberman. My player actor can pick up an item to be used as a projectile - I used constraining to achieve this.

Now I want to have my actor throw the projectile actor a fixed distance in the direction it is facing. I've been able to drop these items so far, but not throw them.

Could anyone point me in the right direction? I've got a funny feeling that this is where I start to learn about game math.


  • scitunesscitunes Posts: 4,047Member, Sous Chef
    Here's how I would do it (if I understand what you are trying do).

    I would create a game attribute (type angle) called game.HeroAngle (or something like that). Then I would constrain the hero's self.rotation to game.HeroAngle
    I would also create two integers called game.heroX and game.heroY. Then I would constrain the hero's x and y to them.
    Create a boolean called game.Throw

    I would also create a self integer attribute in the item called self.ItemState - Eventually you will have three states 0) Item not collected 1)Item being held) 2)Item thrown

    Then I would do this:

    (In item)
    when overlaps with item change self.HoldingItem to 1
    when self.ItemState = 1, constrain self.postionX and self.positionY to heroX and Y (though you may need to do some trig to have it always in the right hand of the hero)
    When game.throw is true And self.ItemState = 1, change self.itemState to 2

    When self.ItemState = 2, change velocity (angle = game.HeroAngle speed whatever you want). Then you could adjust the drag settings in the item so that it comes to a stop after a bit. You could then have a rule that says when self.linearvelocityX and linearvelocityY both = 0 change self.ItemState to 0.

    You may need to tweak this a bit it should get you on the right track.
  • ZeroCredibilityZeroCredibility Posts: 16Member
    @scitunes Thanks for putting this together - It will help me greatly!
  • ZeroCredibilityZeroCredibility Posts: 16Member
    @scitunes Am I right to guess that I need to change the game.throw boolean state to true when i press my 'throw' button?
  • scitunesscitunes Posts: 4,047Member, Sous Chef
  • GLGAMESGLGAMES SingaporePosts: 988Member
    and change it back to false when bomb leaves hand
This discussion has been closed.