Bullet angle of motion resets when you set speed to 0?

Discussion and feedback on Construct 2

Post » Fri Apr 04, 2014 1:43 pm

Hi! I used the bullet behavior to animate a sprite and I wanted to pause it for a short time and let it flash when it reaches a certain point. I used "on collision with object" and then set bullet speed to 0, let it flash, wait 2 sec and then set speed to 100 again. But it will reset the angle of motion to 0 to move it to the right (it was set on Startup to 90 to move from top to bottom). Is this a bug?

When I use Bullet: Set enabled it works fine, it stops and starts with the same angle.
Bl4ckSh33p-Soft - Custom Software and Indie Games
B
56
S
16
G
6
Posts: 743
Reputation: 9,310

Post » Fri Apr 04, 2014 2:41 pm

Bl4ckSh33p wrote:Hi! I used the bullet behavior to animate a sprite and I wanted to pause it for a short time and let it flash when it reaches a certain point. I used "on collision with object" and then set bullet speed to 0, let it flash, wait 2 sec and then set speed to 100 again. But it will reset the angle of motion to 0 to move it to the right (it was set on Startup to 90 to move from top to bottom). Is this a bug?

When I use Bullet: Set enabled it works fine, it stops and starts with the same angle.


It is not a bug in the sense "it is not a wrong value" (since at a speed of 0, every angle of motion is valid, mathematically it would result in a divide 0 by 0 to calcul it, so instead of having a mathematical error in that particular case it just pick 0 by default for some reason), I suggest if you need to set the speed to 0 someday, first store the angle of motion into an instance variable, so you can re-use it later.

Edit:when the behavior is disabled, it just means that is skipped, so the values should still be valid, but aren t re calculated nor interpreted
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Mon Feb 02, 2015 6:42 pm

I have the same problem when I was adding pause in the game and in my opinion its a bug because I set the speed at 0 and not the angle of motion.

Disable/enable bullet won't help me in my case so we have to store the angle of motion in a variable for 10.000+ objects :(
B
46
S
9
G
5
Posts: 110
Reputation: 3,782

Post » Tue Feb 03, 2015 3:06 pm

Internally, Construct never actually stores an "AngleOfMotion" value. Whenever the behavior or user needs the value, it recomputes the value via the arctangent based on the current vx/vy, these being the horizontal and vertical velocity values. This means that when you set speed to 0, vx and vy also get zeroed out and the angle now returns 0.

If vx and vy were instead inferred from angle and speed (aka: vx = cos(angle) * speed, vy = sin(angle) * speed) then this issue wouldn't occur.

@Steely
I'd recommend taking a look at using the system time scale (setting it to zero) to create a pause for the game instead of manually managing all the objects.
B
31
S
7
G
8
Posts: 232
Reputation: 6,274

Post » Fri Feb 06, 2015 3:39 pm

cacotigon wrote:Internally, Construct never actually stores an "AngleOfMotion" value. Whenever the behavior or user needs the value, it recomputes the value via the arctangent based on the current vx/vy, these being the horizontal and vertical velocity values. This means that when you set speed to 0, vx and vy also get zeroed out and the angle now returns 0.

If vx and vy were instead inferred from angle and speed (aka: vx = cos(angle) * speed, vy = sin(angle) * speed) then this issue wouldn't occur.

@Steely
I'd recommend taking a look at using the system time scale (setting it to zero) to create a pause for the game instead of manually managing all the objects.


@cacotigon
Thanks for the explanation, its more clear for me now but I can't use the pause with timescale now, I need only a part of the game to set at pause, but I figured it already out with the power of families.
B
46
S
9
G
5
Posts: 110
Reputation: 3,782


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 13 guests