# How do I ?

0 favourites
• 20 posts
• Hi,

i have an object that rotate 360 degress

i would play to play a sound every 5 degress

something like every that object rotate 5 degres it play that sound

how can i done it ?

thanks

• There are lots of ways to do this.

The following way will work if the object is spinning very slowly (less than 1 degree per tick). If it is spinning more quickly you are going to get a very erratic sound:

Condition:

System -> compare two values -> sprite.angle%5 < 1

Action:

Audio -> Play sound

For an object that is spinning more quickly, give the object an instance variable called "lastSoundAngle". When you first play a sound, set lastSoundAngle = sprite.angle. Every tick, check if abs(anglediff((sprite.Angle - lastSoundAngle)) > 5, then play the sound again and set lastSoundAngle = sprite.Angle.

• did not understand

an example will be appreciated

thank you

• Here you go.

(I just used cjbruce 's code, nothing fancy)

Btw, in case you didn't know, the % in divisions is the so called modulo operator.

In returns the rest of a division.

An example: 5 modulo 2 (5%2) would return 1, since you can put the 2 two times in the four, but you'll have one rest.

12 % 5 = 2,

66 % 10 = 6

and so on.

This is especially useful here, but generally useful, if you want to see whether a number is dividable by another number.

• Here you go.

(I just used cjbruce 's code, nothing fancy)

Btw, in case you didn't know, the % in divisions is the so called modulo operator.

In returns the rest of a division.

An example: 5 modulo 2 (5%2) would return 1, since you can put the 2 two times in the four, but you'll have one rest.

12 % 5 = 2,

66 % 10 = 6

and so on.

This is especially useful here, but generally useful, if you want to see whether a number is dividable by another number.

not work as perfect

• Even though there is no sound at all in the game link, I can tell you why it might not work:

The game you are creating has rotation speeds of 1000+ degrees per second.

One frame is usually rendered at 1/60 of a second.

1000/60 is ~17 degrees per second.

This means that during one frame, the audio would have been played three times already.

(And this is only for 1000 degrees per second, imagine it being 3000)

Like this, the sound would play each frame.

Since the sounds won't stop after one second, they'll overlap and cause weird noises.

You will have to step up with the 5 degrees to something like 20 or even more.

• need some bug fixes about the sound but it's ok

• The audio scheduling example included with C2 may be useful to play multiple sounds in between ticks. Just set the interval to 5/speed, where 5 is the number of degrees per sound and speed is in degrees per second of the rotation.

• cannot done it

• Rewriting what R0J0hound said:

In your project, you have two parameters:

• Sound per X degrees "Every X degrees, I want the sound to be played"
• Rotation speed "Every second, my object should rotate Y degrees"

So far, so easy.

Now you create a condition:

Every Z seconds

Under that condition, put your Play audio action.

Now replace Z in your condition by this combination of expressions:

Z = X/Y

or

Z = Sound per X degrees / Rotation Speed

Example:

• You want your sound to be played every 10 degrees that the object rotates
• Your object rotates with the "Rotate" behavior

Use this for the "Every Z seconds" condition:

Every "10 / Object.Rotate.Speed" seconds

my object is rotating 360 degrees and i would like to play a sound every 5 or 10 degrees ?

how can i done it ?

thank you

• Can you put a screenshot of the event that you are using to rotate the object?

• You should check out a guy called jeremantor vids. He could show you how its done.

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• Can you put a screenshot of the event that you are using to rotate the object?

i'm just using the rotate behaviour

• 20 posts