[SOLVED]move objects toward player if X pixels away

0 favourites
  • 13 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • The game: roll a ball around and collect stars while staying on top of disks.

    There is a power-up in the game that once enabled, it will surround the ball and should act like a magnet, pulling any stars a short distance away toward the ball itself.

    I can not give the stars a 'solid' behavior, the ball hesitates once it collides with the stars. And i can not give the stars a 'physics' behavior since there may be up to 50 stars on screen at any given time, and when i tried adding that behavior the fps went way down.

    I looked at some posts and examples, but either it's not what i need, or they use the physics behavior.

    How can i draw the stars toward the ball if they are, say, 300 pixels away?

    Any help is greatly appreciated.

  • for each star

    if powerup is enabled

    and

    if distance(ball.x,ball.y,star.x,star.y) is greater than (300)

    -(star)move towards position (ball.x,ball.y) distance -20/20 or whatever

  • CloveltOc

    Thanks for the reply.

    What is the distance -20/20? Is that how many pixels they would move?

    As you can see in the image, the stars will be moving along with the disks up and down the screen and be different distances away. Once they collide with the ball they will be destroyed and scored.

  • Move towards position is the action's name

    Position and distance are just parameters of said action

    Distance is how many pixels they will move each time the action is triggered

  • Sorry brother, not seeing a Move towards position.

    To make it easier, i may just add a circular sprite - 300 pixels circumference - set to invisible. Then i may be able to figure out the "is overlapping another object" to get them to move to the ball.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Whoops, totally made move towards position up. Sorry!

    Move at angle will serve the exact same purpose, just put angle() instead of distance()

    Jeez, not feeling bright today

  • CloveltOc

    Yeah, it took me a minute but i got that. Still haven't figured it out yet, though.

    If you want to take a look at it, i'd be much appreciative.

    CAPX

    The star events/actions are on the pickups layout, at the bottom. I just added bullet behavior to the stars. Still working through it.

    Oh, the shield is on an achievement trigger. When i test, i go to menu layout > enable 'clear storage' > run > go back and disable 'clear storage' > run it again and test.

  • Don't have Spritefont+, could you make a vanilla .capx if possible?

  • CloveltOc

    sorry, still a noob....Vanilla.capx?

    I tried deleting the spritefont+ plugin but it's still showing.

  • CloveltOc

    Try this

    CAPX

  • CloveltOc

    So i think i got it. I found this post about a Vacuum and at 1st look, it wasn't what i was looking for. But after dissecting it for some time.... voilà!

    Thanks for all your help, brother.

    Now, i still gotta work on the shields' GV and getting them to actually spawn when they're supposed to.

    Oh yeah, thanks for that capx awesome help!

  • CloveltOc

    So i think i got it. I found this post about a Vacuum and at 1st look, it wasn't what i was looking for. But after dissecting it for some time.... voilà!

    Thanks for all your help, brother.

    Now, i still gotta work on the shields' GV and getting them to actually spawn when they're supposed to.

    Oh yeah, thanks for that capx awesome help!

    Any chance this vacuum CAPX still exists?

    I am trying to build a magnet shield to collect coins in my game but the gravity attract / physics / 8 direction attempts I have are not interpreting the player movement enough (You fly past a coin and it struggles to catch you up correctly)

  • Mayfly Ive been away from c2 for quite a while, but sorry the capx isnt there anymore.

    But as I recall it was just a sprite the had object move towards you while you held down a button ^^

    sorry i cannot help more

    > CloveltOc

    >

    > So i think i got it. I found this post about a Vacuum and at 1st look, it wasn't what i was looking for. But after dissecting it for some time.... voilà!

    >

    > Thanks for all your help, brother.

    >

    > Now, i still gotta work on the shields' GV and getting them to actually spawn when they're supposed to.

    >

    > Oh yeah, thanks for that capx awesome help!

    Any chance this vacuum CAPX still exists?

    I am trying to build a magnet shield to collect coins in my game but the gravity attract / physics / 8 direction attempts I have are not interpreting the player movement enough (You fly past a coin and it struggles to catch you up correctly)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)