Make coin move towards player?

  • So I'm working on a shooter game, and I'm trying to have it so when the ship is within a certain proximity of a coin (which is spawned once an enemy is destroyed), the coin will move into the player.

    I can't figure out how to detect when the coin is close to the player, and the best way to go about making the coin move towards (and touch) the player.

  • The expression you're looking for is:

    distance(coin.X, coin.Y, ship.X, ship.Y)

    As for moving the coin to the ship, there are a number of ways you could do that. I'd personally use rexrainbow's Move-To Behavior.

  • Thanks for replying! I'll check out the behavior, it sounds extremely useful. What event would I use to enter that expression? I'm looking, but I can't seem to find one that would fit.

  • You probably want to use it in system -> "every tick"

  • Oh, whoops. I meant what action would I use where I can enter the distance expression, sorry.

    Edit: Oh sorry, I got it. System>Compare two values. Thanks!

  • Here's how I did it. I used a FOR EACH [COIN OBJECT], got it to check the distance and set the angle if it was as close as I wanted it to be ( < 1000 ). I added the BULLET behaviour to the coins so I could just set the angle, then a speed and the behaviour would do the rest. You can take out the 1 second delay if you want, that's not needed. By leaving it in, it makes the coins 'hover' for 1 second and then fly towards the player.

    <img src="http://s7.postimage.org/6a716lqiz/collectcoin.png" border="0" />

  • Thanks for the help, but I figured out what the others meant. Here's my WIP so far if anyone wants to test it out. :D

    dl.dropbox.com/u/3489564/SHMUP/index.html (Can't post hyperlinks yet.)

    You have to refresh if you die, I can't figure out how to restart it. I did restart layout, but the enemies don't come back after the restart.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I like it! Is it going to be a 1942 remake? I love that game, dropped a fortune into that arcade machine when I was a kid.

  • Haha, that's one of my favorite arcade games. It's not a remake, but it's heavily inspired by that, and Jamestown. (If you haven't played Jamestown yet, play it now. If you loved 1942, you'll love Jamestown.)

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