Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an actor named ball and I want to move it in a straight line which is created by actor ball's X and Y coordinate and cursor's X and Y coordinate. I have Move To behavior in gamesalad but I don't have exact idea how to move the ball with two Cartesian coordinates ball and cursor.

share|improve this question

Here's how to solve your issue inside GameSalad:

  1. Create 2 Game Attributes: TargetX and TargetY (both should be real)
  2. Open your Cursor Actor.
  3. Add two Constrain Attribute behaviors to the Cursor: 1 - Constrain self.location.x to touch1.x; 2 - Constrain self.location.y to touch1.y)
  4. Add two more Constrain Attribute behaviors to the Cursor: 1 - Constrain TargetX to self.location.x; 2 - Constrain TargetY to self.location.y
  5. Open your Ball Actor.
  6. Add MoveTo Behavior.
  7. Set MoveTo Coordinates to Match Custom Target Coordinates (X = TargetX; Y = TargetY)

Now drop your ball actor into your scene and test away.

share|improve this answer

I don't know about gamesalad in particular, but the general way you solve this problem is the following:

  • Translate the cursor's screen coordinates into your world coordinates (so it's in the same coordinate system as the ball). This is your target position.
  • Get the vector from the ball to the target position by subtracting the ball position from the target position. This is your unnormalized direction vector.
  • Normalize your direction vector
  • Figure your your per-frame movement amount. Usually by multiplying your units/second desired speed by the frame time.
  • Multiply your normalized direction vector by the per frame movement amount.
  • Add that per frame movement amount to your ball's position.
share|improve this answer
This is a good general explanation for most 2D game programming, but completely unrelated to how things work in GameSalad. – jhocking Feb 4 '12 at 2:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.