Make player's ship get sucked into a vortex?

Get help using Construct 2

Post » Sun Oct 04, 2015 12:41 pm

Hiya, I'm making a space combat game that will have vortices as transitions between levels... can anyone suggest a good way to make the player's ship get "sucked in" (preferably in a spiral movement) as they come within a certain range?

Currently I've got:

System: distance(PlayerShip.X,PlayerShip.Y,Vortex.X,Vortex.Y)<1600
>Move PlayerShip 20-(int(distance(PlayerShip.X,PlayerShip.Y,Vortex.X,Vortex.Y)/80)) pixels at angle(PlayerShip.X,PlayerShip.Y,Vortex.X,Vortex.Y)

Thing is, this just pulls the player directly toward the vortex. Is there a good way to make it happen in more of a spiral fashion? Geometry's not my strong point :mrgreen:
B
15
S
4
G
1
Posts: 286
Reputation: 1,988

Post » Sun Oct 04, 2015 1:48 pm

Since I suck at maths, I tend to solve problems visually and then implement that.

Here's what I would do.

1. Make an invisible sprite, as a long line, default 64 x 64 is fine. Set its Height to 10, Width 2* (whatever u want the radius of your vortex pull to be). So if you want it to pull when the ship is within 1600 pixels, make it 3200 pixels.

2. Make the point of origin in the center. Add 1 more image point, at the tip of the line, or (32,64) coordinates.

3. Give it the behavior Rotate. Set it to whatever speed that you want the vortex to look like.

4. Give the vortex line an instance variable "IsActive=0".

5. Give your ship an instance variable "IsVortex=0".

6. Do your distance check, when the ship is <1600 distance, set the ship instance variable IsVortex=1 and Pick the Vortex Line Nearest to Ship.X & Ship.Y (so it filters out only that vortex its close to), and set the instance var IsActive=1. Also, set the angle of the Line Vortex towards the position of your ship (X,Y) so the line will instantly point to "touch your ship".

Now, both ship & vortex will have their instance variable flagged to 1, we consider that On/Active.

7. Do a check for your ship, if IsVortex=1, set it's position to another object, the Line Vortex at image point 1. This will cause the ship to be "stuck" to the line vortex. Now the line vortex is rotating and the ship gets dragged with it, spinning around your vortex.

If there's multiple vortexes, simply do a filter to pick by evaluate VortexLine.IsActive=1 so the ship only attaches to the currently active vortex.

How to get it to spin closer and fall into the vortex?

8. Do a check for your vortex line, if IsActive=1, set its Width to be Self.Width * 0.95 (or whatever speed you want, a lower number will suck the ship in faster).

Done, visually it works exactly like a vortex sucking in your ship if it gets too close.

:D

There's probably a much shorter way to do it with a math formula, but this works and doesn't use much CPU calculations, it's simply a re-sizing of a spinning line's width.
B
70
S
24
G
19
Posts: 1,757
Reputation: 17,614

Post » Sun Oct 04, 2015 6:01 pm

That's a really cool solution, thanks for taking the time to write that out :) My only question would be that I want the ship to be able to escape the vortex (by aiming away and accelerating) - with this method, would the player still be able to escape?
B
15
S
4
G
1
Posts: 286
Reputation: 1,988

Post » Mon Oct 05, 2015 12:00 am

The player can escape as soon as you change the instance variable on the player ship from IsVortex=1 to IsVortex=0. It will no longer be forced to be stuck to the vortex line as it spins and shrinks, able to fly away.

It will still be in range for the original distance check, since it would be less than 1600 pixels away at that point. So if you want to face away and fire afterburners, you have to do separate checks for angle vs vortex (within (vortex.angle -180) by 30 degrees), and if its within that angle and afterburners are fired, change an instance variable. So you need a new var for your ship, call it "IsEscaping=0", so when you want to escape and it fits the angle/afterburner check, change it to IsEscaping=1

In the original distance check, make sure you also add Player.IsEscape=0 so that distance check ONLY triggers when player is not trying to escape the vortex.

This kind of stuff is what I do for my own space game. I tend to always think outside the box and apply work-arounds for solving a problem, but it works. :)
B
70
S
24
G
19
Posts: 1,757
Reputation: 17,614

Post » Mon Oct 05, 2015 10:17 am

Cheers man - your project's looking ace by the way, it's really come a long way since I last saw it! You've got my Greenlight vote :)
B
15
S
4
G
1
Posts: 286
Reputation: 1,988

Post » Mon Oct 05, 2015 6:20 pm

@lolpaca
To make it spiral just add 80 or something to the angle. 90 would kind of be just a orbit.

System: distance(PlayerShip.X,PlayerShip.Y,Vortex.X,Vortex.Y)<1600
>Move PlayerShip 100*dt pixels at angle(PlayerShip.X,PlayerShip.Y,Vortex.X,Vortex.Y)+85
B
91
S
31
G
102
Posts: 5,233
Reputation: 67,252

Post » Tue Oct 06, 2015 9:52 am

R0J0hound wrote:@lolpaca
To make it spiral just add 80 or something to the angle. 90 would kind of be just a orbit.

System: distance(PlayerShip.X,PlayerShip.Y,Vortex.X,Vortex.Y)<1600
>Move PlayerShip 100*dt pixels at angle(PlayerShip.X,PlayerShip.Y,Vortex.X,Vortex.Y)+85


Nice one, thank you!
B
15
S
4
G
1
Posts: 286
Reputation: 1,988


Return to How do I....?

Who is online

Users browsing this forum: JarkeyBacon and 3 guests