Throw ball, animal catches it

ckck Member Posts: 224
edited November -1 in Working with GS (Mac)
Working in 0.9.2.

I'm trying to throw a ball, and have an actor move to the ball and catch it. I have a number of issues.

I do it this way.

* I constrain two Game attributes to the X and Y of the ball (ballTargetX and ballTargetY)
* when the ball is released, ballThrown is changed to true
* when ballThrown is true, for the animal, I:
- Constrain self.Position.X to self.Position.X+(game.ballTargetX - self.Position.X)/4
- Same for Y
- Rotate to Position game.ballTargetX and game.ballTarget Y
* on collision with the ball, I:
- Timer - after 0.25 seconds
- Change Attribute ballThrown to false
- Move the animal back to its original position, using Move To
- Rotate the animal back to its original position
- Delete the ball, via the destroy behaviour in the ball actor
- After 0.5 seconds, spawn a new ball

My main three problems are:
* When I throw the ball, I'm using OnTouchRelease to change the attribute, but often, the touch has moved off the actor during the throw, so the attribute isn't getting changed
* Often, after "catching" the ball, the animal moves to somewhere off the screen, never to return again (bye, animal!)
* My rotation to the original position is a mess

Any suggestions, please?

Comments

  • ckck Member Posts: 224
    Solved the bear returning to its original place - used Interpolate self.Position.X and self.Position.Y, rather than move to. This also solved rotation.

    Still have the touch issue, though.
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    you could have a boolean called self.touched

    rule when mouse is down change self.touched to 1

    when self.touched is true and mouse is up
    change ballthrown to 1
    change self.touched to 0
  • ckck Member Posts: 224
    Smashed it. Thanks scitunes.
Sign In or Register to comment.