Move To, Accelerate Toward Help

sawkasteesawkastee Member Posts: 184
edited June 2012 in Working with GS (Mac)
I'd like to create a vacuum effect. I have a vacuum actor and a ball actor. When I press a button the ball actors move toward the vacuum however they all move at the same speed/velocity toward the actor. I'd like actors far away to move more slower to the vacuum and actors very close to move quickly. If possible I'd like to add another rule that if the button is pressed longer the stronger the vacuum pulls the ball actors to it.

So far this is what I have (not much)!

BALL ACTOR:

Change Attribute
self.dist.from.vacuum to self.Position.X - game.vacuum X

Change Attribute
self.dist.from.vacuum to self.Position.Y - games.vacuum Y

Accelerate
Direction 270
Acceleration 300
Relative to Scene

(
Rule when game.button.pressed is true
Move To
game.vacuum X
game.vacuum Y
Relative to Scene
Speed 300

Accelerate Toward
game.vacuum X
game.vacuum Y
Relative to Scene
Speed 300
)

Rule when actor collides with vacuum
Destroy actor

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    You're on the right track. Here's a demo that shows one way to adjust the velocity based on the distance: https://www.dropbox.com/s/sdsbf4rdpdtus4a/Velocity by distance.zip. It uses magnitude to determine the distance (x1-x2,y1-y2) and then uses the distance in a formula that subtracts distance from total possible distance (in this case 480, the height of the scene) and then multiplies the result by a constant (in this case 0.6, but it could be anything) to set relative speeds.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • sawkasteesawkastee Member Posts: 184
    Thanks for the help but I still can't get it. Here's what I have so far with your help.

    VACUUM ACTOR
    Change Attribute
    game.vacuum.x to self.position.x
    Change Attribute
    game.vacuum.y to self.position.y

    BALL ACTOR
    Rule
    When attribute game.button.pressed = true
    Constrain Attribute
    self motion linear velocity x
    -(480-magnitude( self.Position.X - game.vacuum.x , self.Position.Y - game.vacuum.y ))*.6
    self motion linear velocity y
    -(320-magnitude( self.Position.X - game.vacuum.x , self.Position.Y - game.vacuum.y ))*.6

    Instead of the balls going toward the vacuum actor they go to the bottom left hand corner of the screen. I want the vacuum actor to be anywhere on the screen. I thought the problem was due to constrain attributes having the 480x and 320y values in front magnitude but taking them out only sends the balls toward the upper right hand of the screen not toward the actor.

    I can get it working where the balls go to the vacuum using the line below but they don't have any velocity (ones closer move faster, farther slower).

    Accelerate Toward game.vacuum.x and game.vacuum.y relative to scene, acceleration 300

    How can I get velocity and them going toward the vacuum at the same time???

    Thanks!
  • sawkasteesawkastee Member Posts: 184
    Here's another question while we are at it. I have a max.balls.count and when the ball actors collide with the vacuum I increase the attribute by +1. However sometimes balls hit the vacuum actor so fast that it does not count them correctly. How can I fix this???
Sign In or Register to comment.