0
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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.
\$\endgroup\$
1
  • \$\begingroup\$ This is a good general explanation for most 2D game programming, but completely unrelated to how things work in GameSalad. \$\endgroup\$
    – jhocking
    Feb 4 '12 at 2:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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