How do I change angle smoothly?

Get help using Construct 2

» Mon May 08, 2017 9:03 pm

im using bullet behavior

and every 1 second use expression
set angle
int(random(0, 360))

what i can make to change this angle smoothly because now its skipping between angles
B
26
S
8
Posts: 229
Reputation: 2,228

» Mon May 08, 2017 9:44 pm

Set a TargetAngle variable instead of the actual angle.

Then have the bullet rotate towards TargetAngle.
B
60
S
30
G
134
Posts: 1,949
Reputation: 75,375

» Tue May 09, 2017 5:36 am

oosyrag wrote:Set a TargetAngle variable instead of the actual angle.

Then have the bullet rotate towards TargetAngle.

I thought that will be easy, can you show this in capx?
B
26
S
8
Posts: 229
Reputation: 2,228

» Tue May 09, 2017 9:43 am

Have several instance variables in your bullet object :
- TargetAngle - Numeric
- Shifting - Boolean (False by default)

// Sets the random value and tells the bullet it needs to shift in that direction
Event condition Every 1 sec
- action Set TargetAngle value to random(0,360)
- action set boolean Shifting to True

// The bullet is shifting in the target direction
Event condition Bullet Boolean Shifting is true
- Action Set Bullet.Bullet.AngleOfMotion to anglelerp(Bullet.Bullet.AngleOfMotion, Bullet.TargetAngle, dt * 4)
// We check a range where the angle of motion could be to stop the shifting
Sub event
condition System compare two values - Bullet.Bullet.AngleOfMotion + 2 < Bullet.TargetAngle
AND
condition System Compare two values - Bullet.Bullet.AngleOfMotion - 2 > Bullet.TargetAngle
- Action - Set Bullet.Angle of motion to Bullet.TargetAngle
- Action - Set Shifting to False
New to Construct ? Where to start

Please attach a capx to any help request or bug report !
Moderator
B
311
S
128
G
101
Posts: 7,416
Reputation: 75,228

» Tue May 09, 2017 2:02 pm

Kyatric wrote:Have several instance variables in your bullet object :
- TargetAngle - Numeric
- Shifting - Boolean (False by default)

// Sets the random value and tells the bullet it needs to shift in that direction
Event condition Every 1 sec
- action Set TargetAngle value to random(0,360)
- action set boolean Shifting to True

// The bullet is shifting in the target direction
Event condition Bullet Boolean Shifting is true
- Action Set Bullet.Bullet.AngleOfMotion to anglelerp(Bullet.Bullet.AngleOfMotion, Bullet.TargetAngle, dt * 4)
// We check a range where the angle of motion could be to stop the shifting
Sub event
condition System compare two values - Bullet.Bullet.AngleOfMotion + 2 < Bullet.TargetAngle
AND
condition System Compare two values - Bullet.Bullet.AngleOfMotion - 2 > Bullet.TargetAngle
- Action - Set Bullet.Angle of motion to Bullet.TargetAngle
- Action - Set Shifting to False

you mean something like that?
https://www.dropbox.com/s/v7al1u6ujtoh9 ... 7.png?dl=0
B
26
S
8
Posts: 229
Reputation: 2,228

» Tue May 09, 2017 2:14 pm

Both conditions "System - Compare two values" in the same sub event (hence the AND).
And both actions in that sub-event.
New to Construct ? Where to start

Please attach a capx to any help request or bug report !
Moderator
B
311
S
128
G
101
Posts: 7,416
Reputation: 75,228