How do I use cosp with angles?

Get help using Construct 2

Post » Mon Aug 24, 2015 12:11 am

I need an Ease-In-Out (Quad or Quart) dealing with rotation and angles.

can anyone help?
https://dl.dropboxusercontent.com/u/362 ... InOut.capx
B
98
S
32
G
16
Posts: 1,204
Reputation: 16,715

Post » Mon Aug 24, 2015 6:16 am

While lerp() can be used for easing out, there's no way to do easing that way.

The main way to use easing like that is this:
about-the-new-interpolations_p787879?#p787879

Although that's not really suitable for a moving target like yours.

You could treat it a bit different by using angular speed. Basically just accelerate toward the target and decelerate to stop at the angle exactly.
For that you could use this older example:
https://dl.dropboxusercontent.com/u/542 ... rret2.capx
B
92
S
32
G
110
Posts: 5,298
Reputation: 71,507

Post » Mon Aug 24, 2015 6:40 am

thanks @R0J0hound ! This is actually for a top-down space shooter.. I have a big heavy cruiser that catches up with the player (in a straight line making course corrections until the ship is in range). Once the Cruiser is in range, it slows down and uses it's 360 degree cannon to shoot at the player. Once the player is out of range the Cruiser needs to pursue. This is where the easing comes in.. If the Cruiser needs to rotate it looks horrible with lerp() because there is no easing into the rotation - it happens way too fast - and if I slow the rate down, the ship does WAY too big of a loop to catchup to the player. It looks fine easing out of the rotation.

I'm just trying to make the movement seem semi-realistic due to the size of the ship - with so much mass you'd probably see slow and small rotations.

so currently I'm doing:

anglelerp(self.Angle,angle(self.X,self.Y,Player_ship.X,player_ship.Y),0.005)

and instead I need:

anglecosp(self.Angle,angle(self.X,self.Y,Player_ship.X,player_ship.Y),0.005)

The one bug is if the course corrections(Cruiser ship rotation) are still happening when the target is in range. (because it's not supposed to rotate when the target is in range). The rotation suddenly stops - which kills the easing. But I've coded for that giving the ship some fake "aftertouch" which helps it looks like it'm slowing down to a natural speed. Even if it over shoots it doesn't matter since the ship has a gun with a 360 degree range - as long as it's headed in the direction of the player its fine.

thanks for the capx.. that looks perfect! it should work!
B
98
S
32
G
16
Posts: 1,204
Reputation: 16,715

Post » Mon Aug 24, 2015 2:32 pm

R0J0hound wrote:The main way to use easing like that is this:
about-the-new-interpolations_p787879?#p787879


yes I've used lerp and cosp already just like this.. I was just hoping to use cosp with angles. I would definitely request an anglecosp() function.. how else is there to ease in/out simply.

your old turret capx is a good work around though- thanks. I should be able to adapt it to my needs but it would be so much more simple to have 1 math function. I wonder if I could just do an Ease In and then fake the Ease Out. I could do the lerp backwards somehow..
B
98
S
32
G
16
Posts: 1,204
Reputation: 16,715

Post » Tue Aug 25, 2015 6:48 pm

The difference between lerp and anglelerp is anglelerp lerps in the closest direction.

Also I'd like to point out that while something like:
lerp(a, b, 0.5) will give an easing out effect, so will cosp(a,b,0.5), qarp(a,b,c,0.5) ... etc.
As long as a constant value is used for any of the interpolation functions it will only give an easing out effect.
B
92
S
32
G
110
Posts: 5,298
Reputation: 71,507

Post » Wed Aug 26, 2015 1:22 am

@R0J0hound cosp seems to have an Ease In effect as well no?

I've used lerps inside of a lerp..

i.e. lerp(lerp(a,b,0.1),lerp(c,d,0.1),0.1)

it depends on the application but maybe I can give lerp an Ease In effect by changing both values at different rates?? (now I'm starting to go over my own head)
B
98
S
32
G
16
Posts: 1,204
Reputation: 16,715

Post » Wed Aug 26, 2015 4:18 pm

although for easein&out seems like you would need a 4th value that defines the curve maybe?
B
98
S
32
G
16
Posts: 1,204
Reputation: 16,715

Post » Wed Aug 26, 2015 4:56 pm

In the first link I posted I did show how to use interpolation for all easing effects. What I'm saying is only using a fixed value (0.1 is fixed) for the last parameter won't give anything but an easing out effect.

Basically all the interpolation functions define some kind of curve from a to b. For example cosp() could look like this:
Code: Select all
a|--.
 |   `-.     
 |      `.
 |        `.
 |           |           \           
 |             |             \         
 |              \         
 |               `.         
 |                 `.       
 |                   `-.   
b|                     `--,
 +-------------------------
 0                        1


The last parameter specifies a location along this curve from 0 to 1. Now if you gradually increase that value from 0 to 1 you'll get whatever easing as the curve provides. If you instead just use a fixed value for the last parameter and keep changing "a" then none of the functions will give any advantage over just using lerp.

But the best proof is to try it.
B
92
S
32
G
110
Posts: 5,298
Reputation: 71,507

Post » Wed Aug 26, 2015 6:52 pm

R0J0hound wrote: What I'm saying is only using a fixed value (0.1 is fixed) for the last parameter won't give anything but an easing out effect.t.


okay, I'll give that a try.. thanks!
B
98
S
32
G
16
Posts: 1,204
Reputation: 16,715

Post » Tue Sep 01, 2015 6:30 pm

@R0J0hound I'm trying to use the angle as the last lerp parameter, so that when the rotation makes a smaller angle the last parameter will change... the only probably is the angle gets smaller. I need that number to go up to make an easing-in effect. any ideas?

I could just make a variable I supposed and add dt to it, but it seems like I would want to relate it to the difference in angle..

example:
spriteA angle: 180
spriteB angle: 0

rotating sprite A:
anglelerp(spriteA.angle,spriteB.angle,0.05) - creates a nice easing out effect, but the start is too abrupt.

instead I'm trying:

anglelerp(spriteA.angle,spriteB.angle,angle(spriteA,spriteB) / 10000) //works similar unless I can figure out how to get the last number to go up instead of down.

feels like I should add 180 or something to it... since my greatest angle would be 180? (which I would want to be 0.001) and my closest angle would be 0 (which I'd want to be 0.05).. but so far it's not working.. any suggestions?

EDIT: I was saying anglediff but I just meant angle()
B
98
S
32
G
16
Posts: 1,204
Reputation: 16,715

Next

Return to How do I....?

Who is online

Users browsing this forum: 25games, Artcadev, mekonbekon and 24 guests