Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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
add comment

2 Answers 2

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
add comment

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
add comment

Your Answer

 
discard

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.