It looks like you're new here. If you want to get involved, click one of these buttons!

BrassMonkeysUK
Posts: **33**Member, PRO

Hello all,

I have looked through the forums & found many topics on actor rotation, following the examples on how to set up actor rotation, randomly switching between clockwise & anti clockwise and random rotation speeds but still struggling to put it all together.

I am trying to create an actor which I would like to rotate in a fixed position (ie not moving around the screen), randomly switching between Clockwise and Anti-Clockwise and at random speeds, whether its Clockwise or Anti-Clockwise.

I have tried various ways from the examples with timer settings etc but no joy.

I'm sure its simple to code but my brain has suffered a mental block.

Many thanks for any assistance.

Rob

Using GameSalad on WIndows PC

0

## Comments

12,822MemberTry constraining the rotation to some compounded sine waves, not at my computer right now so can't test it, but try something like - constrain rotation to:

200 *sin( self.Time *19 *sin( self.Time *7)) *cos( self.Time *22 *sin( self.Time *14))

33Member, PROSorry, thanks for your help so far .. Do I create a 'constrain attribute' rulewithin the actor itself and then this:

constrainself.rotateto200 *sin( self.Time *19 *sin( self.Time *7)) *cos( self.Time *22 *sin( self.Time *14))

I take it there are no attributes?

12,822MemberYour post is longer than the formula !

Not sure whether you'd need a rule or not or what the rule would be checking for as I know nothing about your game.

33Member, PROI'm just working with shapes rotating at the moment, no games in mind as yet

Just looking how to rotate a shape in a continuous spin, randomly switching between clockwise and anti clockwise and at varying speeds .. Without stopping.

Bit like cogs on a wheel, if you know what I mean!

Weird I know haha !

I've tried various methods from people's examples but no joy !

12,822MemberDid you try my example posted above ?

11,838Member, Sous Chef, PRO, Senior Sous-Chef@BrassMonkeysUK Yes, you constrain self.Rotation to that whole expression.

@Socks You had lost me at 200. I threw this into a demo I was making for someone else and it's a nice effect:

Edit:forgot to randomize the dot color... new link below.New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User

12,822MemberNice !

I was thinking, maybe the final '14' should be something else like 11 or 12 - as there is a 7 earlier on, and seeing as 7 divides so neatly into 14 it's probably better to make it a little messier (as it's meant to be 'random').

33Member, PROAwesome demo!

I started fresh and got your example working . How do you know such things ? lol

33Member, PROwould you mind breaking down the mathematics behind that equation please so I get the idea behind it? ... maths is not by biggest subject!!

12,822MemberHave you tried it yet ?

12,822MemberNeverforget to randomize the dot colour, shame on you.33Member, PROYes, it works thankyou for the help!

I tested it and left it running and eventually the shape went into a spinning frenzy without slowing down haha

11,838Member, Sous Chef, PRO, Senior Sous-ChefI saw that too... lol.

New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User

33Member, PROIve read that cos and sin are related to trigonometry .. where does this fit in with this please?

Edit: ... think Ive worked it out that cos is to go clockwise and sin for anti-clockwise .. ps. I am crap at maths lol

12,822MemberHere are some that don't get into a spinning frenzy . . .

. . . . . . . . . .

Uncertain:(111 *sin( self.Time *44))+(66 *cos( self.Time *27))+(221 *sin( self.Time *33))+ (111 *cos( self.Time *34)+66)+(33 *cos( self.Time *211)-22)+(112 *sin( self.Time *33)+180)

. . . . . . . . . .

Smooth:(200 *sin( self.Time *44))+(88 *cos( self.Time *65))+(600 *sin( self.Time *10)) +(22 *sin( self.Time *222))

. . . . . . . . . .

Safe Cracker:(200 *sin( self.Time *97))+(90 *cos( self.Time *336))+(600 *sin( self.Time *10)) +(22 *sin( self.Time *1000))

. . . . . . . . . .

Electronic:(200 *sin( self.Time *100))+(10 *sin( self.Time *2000))

. . . . . . . . . .

Left to right in video - Uncertain - Smooth - Safe Cracker - Electronic.

33Member, PROAwesome work! .. I've been racking my brain for ages on how to do this and you've shown me the light!

I am trying to work it out myself by trial and error but when a brickwall appears do you mind me asking for help and any questions that I may have ?, keeping it in this topic rather that starting new ones !

12,822MemberThat's essentially what the forum is for, you don't have to ask my permission to ask questions !

33Member, PROCool! cheers!

33Member, PROI've spent a good part of 5-6 hours on this now and having trouble with it .. not sure if this is achievable but will put it out to you Pro's ..

I have the rotating square as above working fine thanks to your help, but now I'm working a scoring system with this project.

I have the main square rotating on top of a slightly larger square which then sits on top of another slightly larger square. Basically 3 squares stacked, birds eye view.

Top - Rotating Square #1 (100x100)

Middle - Square #2 (115x115)

Bottom - Square #3 (150x150)

When 'level' the square #1sits perfectly in square #2, but when square #1 is rotating its edges pass over square #3 as well.

I'm attempting to add a scoring system to this, so that when the rotating square is 'within' square 2 and you touch the screen, it adds points, say 5. but if while rotating you touch the screen and the rotating square is passing over square 3 due to not being level with square 2, you lose 5 points.

I've been working with collision behaviour but only add points no matter where the rotating square is positioned.

Hope this makes sense?, if not, I can email across the project file so you get an idea about what I'm doing ?

12,822MemberIn the Rotating Square actor:

. . . . . . . . . .

Rule: When mouse button is down

••• Rule: (nested in the above rule) When (

conditions are valid)all••• When Numeric expression self.rotation%90 is >= (greater or equal to) 9.5

••• When Numeric expression self.rotation%90 is <= (smaller or equal to) 80.5

•••••• Then take 5 points from a score attribute.

•••••• Otherwise add 5 points from a score attribute.

12,822Member33Member, PROgreat stuff!! cheers!!

Its working to an extent that it does add and subtract, although it appears to be random when subtracting? and not every time when I click and square 1 is in contact with square 3.

Not sure if its because I am on a PC, so wasn't able to find the 'numeric expression' function. Is this Mac only ?

It doesn't allow me to add %90 after self.rotation. I selected the 'Attribute' function?

12,822MemberYou can't honestly hope to put just

someof the stuff in and expect it to still work !A:

If you add up 50 and 50 and multiply it by 4 you get 400B:

I added up 50 and 50, but the multiply button doesn't seem to work, but I hit equals anyway, but I'm not getting 400, what gives ?Obviously looking at the screenshot you've not got a

when mouse button is downrule, nor have you got the numeric expressions.I don't know the PC version that well, I wasn't aware it lacked the numeric expression part.

You can get around this by doing the numeric expression outside of the rule - which produces a result - and then just use that result instead.

So . . . if the rule won't let you enter (for example) 50+cheese+the moon/200 . . . then you just make an attribute (let's call it 'X') and change it to or constrain it to 50+cheese+the moon/200 - then in the rule you need now only enter the attribute 'X'.

33Member, PROOk thank you ! Appreciate the help !!

Where do I find Cheese & Moon ? ...... kidding lol

33Member, PROApologies for this rather long post ...... Working from this old thread, I have managed to have time now to work on this game properly and hope to upload for the world to have a little play in the not too distant future! unfortunately I have lost the old project and started from scratch ...

Now for the problem that's causing me a slight headache (once more)

I am working with Windows GS.

I have the rotating square as above working fine and now sorting out the scoring system which somewhat works to an extent. At the moment, points are added very 'mouse down' rule, no matter what position the rotating square is in.

I've been working with collision behaviour but only add points no matter where the rotating square is positioned.

I have the main square rotating on top of a slightly larger square which then sits on top of another slightly larger square. Basically 3 squares stacked, birds eye view.

Top - Rotating Square #1 (110x110)

Middle - Square #2 (135x135)

Bottom - Square #3 (150x150)

When square #1 (top rotating square easy) is 'level', this sits perfectly in square #2 (middle square easy). During rotation square #1's edges pass over square #3 also.

I'm attempting to add a scoring system to this, so that when the rotating square is 'within' square 2 and you touch the screen, it adds points, say 5. but if while rotating you touch the screen and the rotating square is passing over square 3 due to not being level with square 2, you gain no points/lose points. (still deciding which better).

There is a timer which stops the game when it reaches zero and displays the final score.

The rules are within the Rotating Square actor.

I have created an Integer attribute 'rotating x' which is because WindowsGS doesn't allow Numeric expressions. It is setup as a constrain Attribute where self.rotation to self.rotation%90

I've tried to put as uch info as I can in this post, so any help/advice is really appreciated. Any questions etc please let me know.

I know there is something Ive missed out or placed in the wrong but lets see .....

12,822MemberIn the first screenshot . . .

There is no need to constrain the actor's self.image attribute to an image file, you can simply apply the image file to the actor.

Using a constrain like this keeps applying the image to the actor 60 times a second ! Basically every 1/60th of a second the actor which has already got the Sqbb2 image file applied to it, is told to change its image file from Sqbb2 to Sqbb2 !

. . . . . . . . . . . . .

Demo project attached, I used a custom collision shape for the 'bottom' actor.

33Member, PROAs always your a genius ! Diamond!!

I'll give this a go with my project and see how it goes but you've nailed what Ive been trying to solve!.

161MemberHow do you come up with this formulas, you are awesome. Thanks