GameSalad

Howdy, Stranger!

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

Random actor rotation speeds

BrassMonkeysUKBrassMonkeysUK Posts: 33Member, PRO
edited January 2015 in Working with GS (PC)

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

Comments

  • SocksSocks London, UK.Posts: 12,822Member

    Try 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))

  • BrassMonkeysUKBrassMonkeysUK Posts: 33Member, PRO

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

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

    I take it there are no attributes?

  • SocksSocks London, UK.Posts: 12,822Member
    edited January 2015

    @BrassMonkeysUK said:
    Do I create a 'constrain attribute' rulewithin the actor itself and then this:

    Your post is longer than the formula ! :smile:

    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.

  • BrassMonkeysUKBrassMonkeysUK Posts: 33Member, PRO

    I'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 !

  • SocksSocks London, UK.Posts: 12,822Member

    @BrassMonkeysUK said:
    I'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 !

    Did you try my example posted above ?

  • tatiangtatiang Posts: 11,696Member, Sous Chef, PRO, Senior Sous-Chef
    edited January 2015

    @BrassMonkeysUK said:
    Sorry, thanks for your help so far .. Do I create a 'constrain attribute' rulewithin the actor itself and then this:

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

    I take it there are no attributes?

    @BrassMonkeysUK Yes, you constrain self.Rotation to that whole expression.

    @Socks You had lost me at 200. :s 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

  • SocksSocks London, UK.Posts: 12,822Member

    @tatiang said:

    Nice ! :)

    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').

  • BrassMonkeysUKBrassMonkeysUK Posts: 33Member, PRO

    @tatiang said:

    Awesome demo!

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

  • BrassMonkeysUKBrassMonkeysUK Posts: 33Member, PRO

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

  • SocksSocks London, UK.Posts: 12,822Member

    @BrassMonkeysUK said:
    would you mind breaking down the mathematics behind that equation please so I get the idea behind it? ... maths is not by biggest subject!!

    Have you tried it yet ?

  • SocksSocks London, UK.Posts: 12,822Member

    @tatiang said:
    Edit: forgot to randomize the dot color

    Never forget to randomize the dot colour, shame on you.

  • BrassMonkeysUKBrassMonkeysUK Posts: 33Member, PRO

    Yes, 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

  • tatiangtatiang Posts: 11,696Member, Sous Chef, PRO, Senior Sous-Chef

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

    I saw that too... lol.

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

  • BrassMonkeysUKBrassMonkeysUK Posts: 33Member, PRO
    edited January 2015

    Ive 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

  • SocksSocks London, UK.Posts: 12,822Member
    edited January 2015

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

    @tatiang said:
    I saw that too... lol.

    Here 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.

  • BrassMonkeysUKBrassMonkeysUK Posts: 33Member, PRO

    Awesome 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 !

  • SocksSocks London, UK.Posts: 12,822Member

    @BrassMonkeysUK said:
    . . . when a brickwall appears do you mind me asking for help and any questions that I may have ?

    That's essentially what the forum is for, you don't have to ask my permission to ask questions ! :smile:

  • BrassMonkeysUKBrassMonkeysUK Posts: 33Member, PRO

    Cool! cheers!

  • BrassMonkeysUKBrassMonkeysUK Posts: 33Member, PRO
    edited January 2015

    I'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 ?

  • SocksSocks London, UK.Posts: 12,822Member
    edited January 2015

    @BrassMonkeysUK said:
    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.

    In the Rotating Square actor:

    . . . . . . . . . .

    Rule: When mouse button is down

    ••• Rule: (nested in the above rule) When (all conditions are valid)

    ••• 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.

  • SocksSocks London, UK.Posts: 12,822Member
  • BrassMonkeysUKBrassMonkeysUK Posts: 33Member, PRO

    great 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?

  • SocksSocks London, UK.Posts: 12,822Member
    edited January 2015

    @BrassMonkeysUK said:
    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.

    You can't honestly hope to put just some of the stuff in and expect it to still work ! :smile:

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

    B: 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 ?

    :tongue:

    Obviously looking at the screenshot you've not got a when mouse button is down rule, 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'.

  • BrassMonkeysUKBrassMonkeysUK Posts: 33Member, PRO

    Ok thank you ! Appreciate the help !!

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

  • BrassMonkeysUKBrassMonkeysUK Posts: 33Member, PRO

    Apologies 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 .....



  • SocksSocks London, UK.Posts: 12,822Member
    edited August 2016

    In 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.

  • BrassMonkeysUKBrassMonkeysUK Posts: 33Member, PRO
    edited August 2016

    As 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!.

  • SEMASEMA Posts: 161Member

    @Socks said:
    Try 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))

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

Sign In or Register to comment.