How can rotate actor x degrees clockwise then x degrees anticlockwise and repeat
StormyStudio
United KingdomMember Posts: 3,989
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?
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
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.
many many thanks...
I ended up trying to do something like that last night, but was over complicating it all.
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..
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
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.
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.
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).
rotate clockwise then after X time rotate anti clockwise and repeat?
Just a thought as i have not tested it.
Darren.
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.
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.
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).
However, I could be wrong, as I would think he would want the platform horizontal/flat as it moved along the arc/wave.
@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.
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
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.