How do I draw a path for sprite to follow

Get help using Construct 2

Post » Fri Jan 15, 2016 10:31 pm

I'd like to make a function that allows the user to draw a path from a sprite for the sprite to follow it.
Long ago, I found a .capx that does almost that. I tried to modify it but could make it work only when I draw the line from the front of the sprite.
See for yourself, capx is included in the link. Hope you'll be able to make it work right
Thanks !
Laurent
https://www.dropbox.com/s/kenyke42fe51w ... .capx?dl=0
B
37
S
15
G
5
Posts: 254
Reputation: 5,805

Post » Sun Jan 17, 2016 9:51 pm

Anyone ?
B
37
S
15
G
5
Posts: 254
Reputation: 5,805

Post » Sun Jan 17, 2016 10:06 pm

Unfortunately can't open the link you are referring to.
ImageImage
B
111
S
51
G
24
Posts: 787
Reputation: 23,394

Post » Sun Jan 17, 2016 10:16 pm

Laurent wrote:I tried to modify it but could make it work only when I draw the line from the front of the sprite.


Where do you want to draw the line from? In order for the sprite to follow the line, it would need to originate from the sprite at some point.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
136
S
31
G
86
Posts: 5,490
Reputation: 59,766

Post » Sun Jan 17, 2016 10:47 pm

If that doesn't work then I think there was a change in C2 that caused it not to work. However there should be a fix in the topic it came from as I recall.


Alternatively this also works:
Code: Select all
mouse: left button down
--- create dot at (mouse.x, mouse.y)

for each dot ordered by dot.zindex ascending
--- sprite: set angle toward (dot.x, dot.y)
   system: compare distance(sprite.x,sprite.y,dot.x,dot.y)<sprite.bullet.speed*dt
   --- dot: destroy
   else
   --- stop loop
B
94
S
33
G
114
Posts: 5,358
Reputation: 73,777

Post » Mon Jan 18, 2016 8:42 am

alextro wrote:Unfortunately can't open the link you are referring to.

The file has been created with the last version of the beta
B
37
S
15
G
5
Posts: 254
Reputation: 5,805

Post » Mon Jan 18, 2016 8:59 am

R0J0hound wrote:If that doesn't work then I think there was a change in C2 that caused it not to work. However there should be a fix in the topic it came from as I recall.


Alternatively this also works:
Code: Select all
mouse: left button down
--- create dot at (mouse.x, mouse.y)

for each dot ordered by dot.zindex ascending
--- sprite: set angle toward (dot.x, dot.y)
   system: compare distance(sprite.x,sprite.y,dot.x,dot.y)<sprite.bullet.speed*dt
   --- dot: destroy
   else
   --- stop loop


Thanks @R0J0 for the quick answer. But unfortunately, it doesnt seem to be working either.
B
37
S
15
G
5
Posts: 254
Reputation: 5,805

Post » Mon Jan 18, 2016 7:20 pm

B
94
S
33
G
114
Posts: 5,358
Reputation: 73,777

Post » Mon Jan 18, 2016 9:35 pm

Thanks, R0J0. I'll try to find a way to prevent the box to move continually
B
37
S
15
G
5
Posts: 254
Reputation: 5,805

Post » Mon Jan 18, 2016 10:50 pm

Laurent wrote:Thanks, R0J0. I'll try to find a way to prevent the box to move continually


Can be done easily.

Set initial speed of bullet sprite to 0.

When mouse down - set speed to 200.

When dot.count = 0 -> set bullet speed back to 0.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
136
S
31
G
86
Posts: 5,490
Reputation: 59,766

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 26 guests