How can rotate actor x degrees clockwise then x degrees anticlockwise and repeat

StormyStudioStormyStudio United KingdomMember Posts: 3,989
edited November -1 in Working with GS (Mac)
Good evening,

Tricky one here I think (or perhaps simple for someone)

I want an actor to automatically rotate clockwise x degrees, then x degrees the other way. Ideally being able to control the speed as well.

I've tried using the rotate behavioir but you have to choose clockwise or anticlockwise.

I've tried putting in code like:
10*sin( game.Time *10)

and tried using cos as well just incase.

10*cos( game.Time *10)

I dont fully understand cos and sin too much and have simply taken the code for making a platform move left then right.

Any ideas welcome, even if you can think how I could do it using timers?

Comments

  • SparkyidrSparkyidr Member Posts: 2,033
    do something like

    When self.rotation=0
    set angular velocity to a positive number

    then

    When self.rotation=(whatever angle you want it to stop and return at)
    sent angular velocity to a negative number

    I think that should work.
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    cheers...will give that ago at lunch time...

    many many thanks...

    I ended up trying to do something like that last night, but was over complicating it all.
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    hmm....still can't get it to work. I made some game attributes to control the values.

    Have set it up, so:

    .............................--------------------------........................-----------------------------

    if attribute 'self.rotation < '-game.angle '

    Change attribute, 'self.motion.AngularVelocity' to 'game.rotate.value'

    and

    if attribute 'self.rotation > 'game.angle '

    Change attribute, 'self.motion.AngularVelocity' to '-game.rotate.value'

    .............................--------------------------........................-----------------------------

    Also tried using '=' instead of '<' or '>'.

    If I use the '=' sign, I need to have the platform already rotating so it reaches one of the rotation values. But it never stops when it reaches them. Or with the < and > signs it will just keep spinning the full 360 in one direction.

    Maybe there is a whole different approach to take.

    Not even sure if GameSalad works with negative angles?

    I want the platform to rotate about 10 degrees one way then back to 0 and 10 degrees the other. But also be able to control the speed and angle via a game attribute.

    Help please..
  • ORBZORBZ Member Posts: 1,304
    Sin(game.time*100)*angle
  • rebumprebump Member Posts: 1,058
    Don't think you want to use "=" when testing real values for velocities, angles, etc. since they will rarely ever match exactly.

    I'll poke around when I get home tonight. I have something similiar going 180 degrees back and forth...I'll see if I can get it to go 10 degrees reliably (not sure if it will be random on whether or not it goes clockwise/counterclockwise since it doesn't use the simplistic "Rotate" behavior but will play around to be sure).

    There is another post/thread on the flakiness of the "rotate" behaviors floating around:

    http://gamesalad.com/forums/topic.php?id=3044#post-17090
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    I have tried using

    Sin(game.time*100)*angle

    where angle is my 'game.angle' attribute. (also tried a number instead)

    It either previews with a plain black screen.

    Or nothing happens with rotation but the actors that are sitting on actor fall through it.

    Have tried:

    Sin(game.time*100)*angle

    on:
    Rotate to angle,
    Rotate,
    and Change Attribute - Rotation
    Change Attribute - Angular Velocity.

    Nothing works as yet.

    I've also tried the above on a new actor object just incase it was causing problems.

    REBUMP, let me know if you work anything out, I think I've read that link on the flakiness of rotation...will have a look at the link.
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    have just tried it:

    Sin(game.time*100)*10

    in a new project, with the above code on various things on a new actor, and it won't preview on anything.
  • firemaplegamesfiremaplegames Member Posts: 3,211
    just make sure Sin is lowercase: sin
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    What would you recommend using it on, which behavior...
  • rebumprebump Member Posts: 1,058
    How about this:

    http://gamesalad.com/game/play/40104

    There are rotation (I call it "wave") speed and sweep amount game level attributes you can set to control the actors' movements.

    You would think the "Rotate to Angle" behavior would handle this nicely but it just doesn't seem to like endpoints being tested with "Rule" behaviors (even using greater than/less than and slight overages on rotation sweep amounts).
  • UtopianGamesUtopianGames Member Posts: 5,692
    What about using a timer?

    rotate clockwise then after X time rotate anti clockwise and repeat?

    Just a thought as i have not tested it.

    Darren.
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    Rebump, that link may do what I need, quite trippy....will take a look at the project tonight. Many thanks for that...

    and Utopiangames, that sounds like it would work....why my little mind could'nt think like that I don't know....I guess I could set it up so it :

    rotate clockwise then after X time rotate anti clockwise and repeat.

    And have an game.attribute for speed which I could control to vary it.
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    Rebump, thanks for the custom made project, had a look through it over my lunch, looks like it will do exactly what I need.

    Be great if you could explain the code a bit for me, I understand what does what but, not the finer details as why it does it. Just like to understand it more for my own inner growth

    i.e.
    ......

    if self.rotation is equal to or greater self.InitialRotation +( game.WaveSpanInDegrees /2.0)

    Then self.angular.velocity -1* game.WaveSpeed
    .......

    Firstly why do you have to divide by 2 on game.waveSpinDegrees (if '/' means divided)

    Then why change angluar velocity to -1* wave speed variable, what does the -1* acheive

    Lastly:
    I may try the timer idea too just to see how well that works, out of interest too.

    Do you reckon timers are more processor heavy than the smarter looking 'sin' coding.
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    is it just for a visual effect? You could just animate.
  • rebumprebump Member Posts: 1,058
    I'll just preface this with I started working on one method of implementing this with the "RotateToAngle" behavior but as I stated, GS didn't really seem to be consistent with its treatment of that inside of rules. Then I switched to another method that was very inconsistent (go GS!) and exhibited some of the behavior you were running into. Finally, I moved to the final method you see in the demo. Since it was 1 AM and I was getting tired, I thought "it works solidly now...don't eff with it." That should be the GS motto until we are out of Beta! ;-) So after some minor cleanup removing things that were no longer used at all, I uploaded it to GS.

    So with how it stands currently, the logic in there allows me to compute the endpoints of the wave based on the start position in the middle of the wave (what I call the "top of the wave"). The attribute game.WaveSpanInDegrees represent the full movement/sweep (in degrees) from one side of the wave to the other. Thusly, from one side of the wave to the top of the wave is half of that. It is an easy way to compute both endpoints of the wave (i.e. just add or subtract game.WaveSpanInDegrees/2 from self.InitialRotation).

    I thought that actors who implement this wave behavior would be easier to place in the scene if they were at the top of their wave (i.e. in the middle of the wave). I thought they would look best at the start of the scene beginning their movement from the top. If you want them to begin from one side or the other, you could easily make the change.

    When placing them, I drop the actor into the scene, fine tune its self.Position.X&Y position and then set its self.InitialRotation and self.Rotation to the same starting angle. Technically, you don't need to set self.Rotation as it will be set for you, but by setting it, you will see it in the scene editor as it will appear upon start of scene. In the example, one actor has self.InitialRotation set to 0, another to 90, the third to 180, and the last to 270.

    So upon start, self.InitialRotation is copied into self.Rotation to set the starting angle at the top (if you hadn't done so already when manually placing it). It then starts moving, if I recall correctly (I'm at work now on a PC), counter-clockwise. When it reaches one side of the wave, it then reverses direction to clockwise and proceeds game.WaveSpanInDegrees movement to the other side where it revereses back to counter-clockwise movement. It does this over and over. The reason why I implemented self.InitialRotation is I need that value retained for reference when computing the endpoints of the wave (see above). If I just set self.Rotation, that value would obviously change as the actor moved so I would have not reference point to get the endpoints.

    The "multiple by negative one" thing is just reversing the rotation direction. Positive angular velocity is counter-clockwise rotation and negative angular velocity (i.e. the "-1 *" bit) is clockwise rotation (I hope I didn't get that reversed in my write-up here).
  • rebumprebump Member Posts: 1,058
    @scitunes: That would be easier for artist/creative types for sure! I think he said somewhere that he was wanting a moving platform or something.

    However, I could be wrong, as I would think he would want the platform horizontal/flat as it moved along the arc/wave.
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    Rebump, many thanks for that ...just read it through once and 75% sank in, will read again when I'm not at work trying to look busy.

    @Scitunes, unfortunatel it needs to be in game rotation not animation as I want it to interact with some other actors.

    Rebump .... many many many many thanks for this....hopefully I will get it working as needed tonight and I can move onto the next areas of the game.
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    @Rebump, once again many thanks, have read through all your help and divulged the project.

    Took some working in my little mind to get round it, the idea of the wave is brilliant all is now crystal clear, and I'm glad to have learned it.

    Have recreated it on my own project now and after some teething problems, it now works perfectly.

    Had a problem where it was not working if the initial rotation was '0', it would only work if it was a higher number. Checked through my code about 20 times and could not see why, but have simply added a rule that if the actor is activated and rotation = '0' to turn on angular.velocity to the game.wavespeed

    Also have tinkered with it as I'm trying to get a better understanding of it, and I don't think you need to do the divide by 2 on the angle in the formula. Seems to work ok just using the standard number.

    Many thanks, and once I get my game finished a free copy will be heading your way. Won't be ready any time soon, keep having to stop to look after my crying/feeding/sleeping baby daughter....gonna book days off work soon to get some serious work done on it.

    Many thanks again...

    draper3000
  • rebumprebump Member Posts: 1,058
    @draper3000: Glad you got it working.

    I'm in the same boat with our third child, a 2.5 year old who is hyperactive and never sleeps. By the time I get home from the day job and assist the SO with the child, I'm pretty pooped. I have a cr@pload of time off accumulated too but if I take it off, I usually end up taking care of the toddler the whole day (something about "how about a day off for me" or something from the SO). :-(

    I think if you don't do the divide by two, you will be doubling the width (i.e. arc) of the wave so you may want to check to make sure (although if the movement fits where you have it, don't worry). And just to clarify, if game.WaveSpanInDegrees is 45, then the actor will rotate 45 degrees one way and then 45 degrees back the other way with the divide by two in place. Without the divide by two, you would get 90 degrees of back-n-forth rotation.

    Good luck and look forward to seeing your game.
Sign In or Register to comment.