How do I change angle smoothly?

Get help using Construct 2

Post » 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
25
S
8
Posts: 219
Reputation: 2,181

Post » Mon May 08, 2017 9:44 pm

Set a TargetAngle variable instead of the actual angle.

Then have the bullet rotate towards TargetAngle.
Mistakes were made.
B
54
S
28
G
115
Posts: 1,705
Reputation: 65,083

Post » 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
25
S
8
Posts: 219
Reputation: 2,181

Post » 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

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
295
S
118
G
96
Posts: 7,327
Reputation: 71,246

Post » 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
25
S
8
Posts: 219
Reputation: 2,181

Post » 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

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
295
S
118
G
96
Posts: 7,327
Reputation: 71,246


Return to How do I....?

Who is online

Users browsing this forum: dop2000, R0J0hound and 11 guests