# Make coin move towards player?

Get help using Construct 2

### » Wed Oct 31, 2012 10:05 pm

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.
B
19
S
4
G
1
Posts: 42
Reputation: 1,793

### » Wed Oct 31, 2012 10:12 pm

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.
B
108
S
37
G
9
Posts: 319
Reputation: 12,359

### » Wed Oct 31, 2012 10:21 pm

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.
B
19
S
4
G
1
Posts: 42
Reputation: 1,793

### » Wed Oct 31, 2012 10:27 pm

You probably want to use it in system -> "every tick"
B
91
S
44
G
17
Posts: 1,012
Reputation: 18,572

### » Wed Oct 31, 2012 10:31 pm

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! darkpivot2012-10-31 23:14:42
B
19
S
4
G
1
Posts: 42
Reputation: 1,793

### » Wed Oct 31, 2012 11:35 pm

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.

vandinz2012-10-31 23:39:17
B
20
S
5
G
4
Posts: 208
Reputation: 3,985

### » Wed Oct 31, 2012 11:54 pm

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

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. darkpivot2012-10-31 23:55:40
B
19
S
4
G
1
Posts: 42
Reputation: 1,793

### » Thu Nov 01, 2012 12:38 am

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.
B
20
S
5
G
4
Posts: 208
Reputation: 3,985

### » Thu Nov 01, 2012 12:57 am

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.)
B
19
S
4
G
1
Posts: 42
Reputation: 1,793