Square movement path with rounded corners

Get help using Construct 2

Post » Sun Feb 24, 2013 10:42 am

I have a ship patrolling around in a square, with rounded corners. Is there a better way to do this than what I have here?

https://www.dropbox.com/s/vv3od8ismwj4opn/Untitled-1.gif

I have tried to make a function to add 1 degree, repeat 90 times, but it only runs once because of the run once condition. The same problem occurred when I tried to use an OR block to save on events, but the OR block doesn't work with run once.

If I don't use run once, my ship starts going in circles when it hits a corner.

Also, I ran into a problem in Firefox and IE, it seems like the turn rate is tied to fps, so when fps drops the ship starts swimming off the edge of the screen.

Live Demo: http://www.mbcoffice.com/construct/index.html

Edit: Ack links don't work. Typing them out in plaintextoosyrag2013-02-24 10:43:53
Mistakes were made.
B
37
S
17
G
67
Posts: 1,041
Reputation: 38,211

Post » Mon Feb 25, 2013 6:27 pm

Use invisible sprites located right before the turns. When the ship collides with those sprites add 90 to an instance variable of the ship called "targetAngle". Then every tick rotate the ship toward the targetAngle.

ex:
http://dl.dropbox.com/u/5426011/examples16/roundedBoxPath.capx
B
79
S
24
G
54
Posts: 4,744
Reputation: 40,751

Post » Wed Feb 27, 2013 6:11 am

Thanks! Very clean solution.

I found the tutorial on dt after looking at your capx, probably should have read that before I started.

I stayed with 4 events that "trigger once" for the corners though. I wanted to avoid using extra objects and collision calculations (assuming that events require less overhead - please correct me if I'm wrong!). I guess if I had many ships with different paths, I should use collision objects.

At least I got rid of the double location conditions as a side effect of using a variable target angle. By setting the variable start value to 90 less than my initial heading, the ship will start on the correct heading without turning right away when the layout starts.

https://www.dropbox.com/s/ohug88xa3d66br2/Capture.PNG

Thanks again for your input!
Mistakes were made.
B
37
S
17
G
67
Posts: 1,041
Reputation: 38,211


Return to How do I....?

Who is online

Users browsing this forum: austinblackbelt, Matthew de, Skebab, spcsmrf and 6 guests