[SOLVED]move objects toward player if X pixels away

Get help using Construct 2

Post » Mon Nov 14, 2016 6:21 pm

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.
Last edited by jeffige on Mon Nov 14, 2016 9:15 pm, edited 2 times in total.
B
38
S
18
G
19
Posts: 664
Reputation: 14,107

Post » Mon Nov 14, 2016 6:27 pm

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
B
9
S
3
Posts: 150
Reputation: 1,264

Post » Mon Nov 14, 2016 6:36 pm

@CloveltOc

Thanks for the reply.

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

Image

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.
B
38
S
18
G
19
Posts: 664
Reputation: 14,107

Post » Mon Nov 14, 2016 6:37 pm

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
B
9
S
3
Posts: 150
Reputation: 1,264

Post » Mon Nov 14, 2016 6:56 pm

@CloveItOc

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.
B
38
S
18
G
19
Posts: 664
Reputation: 14,107

Post » Mon Nov 14, 2016 7:21 pm

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
B
9
S
3
Posts: 150
Reputation: 1,264

Post » Mon Nov 14, 2016 7:27 pm

@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.
B
38
S
18
G
19
Posts: 664
Reputation: 14,107

Post » Mon Nov 14, 2016 7:34 pm

Don't have Spritefont+, could you make a vanilla .capx if possible?
B
9
S
3
Posts: 150
Reputation: 1,264

Post » Mon Nov 14, 2016 7:40 pm

@CloveltOc

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

I tried deleting the spritefont+ plugin but it's still showing.
B
38
S
18
G
19
Posts: 664
Reputation: 14,107

Post » Mon Nov 14, 2016 7:50 pm

@CloveltOc

Try this


CAPX
B
38
S
18
G
19
Posts: 664
Reputation: 14,107

Next

Return to How do I....?

Who is online

Users browsing this forum: bluesun66, Yahoo [Bot] and 11 guests