# How do I use cosp with angles?

Get help using Construct 2

### » Tue Sep 01, 2015 7:01 pm

updated capx

once the "X" leaves the dotted circle, the blue pointer jumps(rotates) too fast toward the X, would love to figure a way for the pointer to: ease into the rotation, increase speed midway, then near the end, slow down...
B
101
S
34
G
16
Posts: 1,212
Reputation: 17,016

### » Wed Sep 02, 2015 8:23 pm

okay, update..

I was able to make it better, but it's still not quite right.. it's definitely better.. but there must be a real way to do it.

Every Tick Set Pointer.angle_diff_to_x to anglediff(Self.Angle,angle(self.X,self.Y,PointToThis.X,PointToThis.Y))
T=min(abs(self.anglediff_to_x - 180) * (0.02/180),1)

Pointer Set Angle: anglelerp(self.Angle,angle(self.X,self.Y,PointToThis.X,PointToThis.Y),T)

This is nightmarish.. I'm spending days and days just trying to get the movement right... ready to scrap it a design a different movement...
B
101
S
34
G
16
Posts: 1,212
Reputation: 17,016

### » Mon Sep 07, 2015 6:29 pm

@jobel
You can't do it with just one formula, you need a variable that you change over time to do it.

One you could use is speed. It starts as 0 and it increases over time so you get an easing in effect.

rotate self.speed*dt degrees toward target_angle

In the actions above the 100 is the acceleration.

You can also make an easing out effect with it by giving speed an initial speed and using negative acceleration to slow it down.

Set speed to max(self.speed-100*dt, 0)
rotate self.speed*dt degrees toward target_angle

The max() is used above so the speed never becomes negative. The one problem is you need to handle is if the start speed is too low the sprite will stop short. To fix that we can calculate what the speed should start at with:
speed= sqrt(anglediff(self.angle, target_angle)*2*100)
Or instead of 100 use whatever you're using as an acceleration.

Next to do an easing in-out effect (which is basically what the first capx I posted) you can accelerate or deccelerate depending on the stopping distance which can be calculated with:
dist = (speed^2)/(2*acceleration)

So then it can be reduced to two actions as follows:

global number acceleration=100
global number target_angle =270

every tick:
--- set speed to max(0,(((self.speed^2)/(2*acceleration)<anglediff(self.angle, target_angle))?acceleration:-)acceleration)
--- rotate self.speed*dt degrees toward target_angle

You may also want to reset the speed to 0 when the target is reached.

Here's a capx:
https://dl.dropboxusercontent.com/u/542 ... n_out.capx

It differs from the first capx in that it doesn't try to be physically accurate.
B
95
S
34
G
128
Posts: 5,493
Reputation: 81,674

### » Wed Sep 09, 2015 8:00 pm

Thanks @R0J0hound I'll check it out! (I very much appreciate the help!)
B
101
S
34
G
16
Posts: 1,212
Reputation: 17,016

Previous