Moving an Actor Thats Set up For Random Motion Using Sin and Cos.

floatingwoofloatingwoo Los Angeles, Calif.Member Posts: 393
edited June 2015 in Working with GS (Mac)

In this project....http://gsrca.de/131072

I have a random floating movement setup using sin and cos with a little rotation. I would like the plane to gradually move with ease, along its X axis to the right across the scene as the user touches the various background and foreground elements. Hence having her (the pilot) look toward the mouse click and react with (Oh and Ah). Try holding down the mouse on the scene.

I ’m having a bit of trouble hooking up the movement because the X and Y location attributes created for the random wobble are locked into that first self.position.

I’m thinking in order to make this work I would have to , have the plane control the camera, create a game attribute: moving and then create an invisible touch pad that I stretch over the entire scene so that it will register a touch? Possibly?
Code is as follows.....

And here is how I would like it to move...

Comments

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

    @floatingwoo said:
    I ’m having a bit of trouble hooking up the movement because the X and Y location attributes created for the random wobble are locked into that first self.position.

    You can change the self.locX and self.locY attributes to whatever you want/need.

    Change the values to x100, y100 and the actor will sit at x100, y100 (while continuing to wobble).

    Interpolate self.locX from 0 to 1024 and the actor will move from X=0 to X=1024 (while continuing to wobble).

    Constrain self.locX to 400 *cos(game time *200)+512 and Constrain self.locY to 400 *sin(game time *200)+384 and the actor will move in a big circle (while continuing to wobble).

    Constrain self.locX to self.time and the actor will move across the screen - very slowly! - (while continuing to wobble).

    . . . etc etc . . hope that makes sense !

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879

    You might try turning off the 'constrain self.position.x' behavior. It seems to me that the oscillating up/down and rotation behaviors you already have will give you the floating effect you are after.

    Then your 'linear velocity X' setup will take care of horizontal movement.

    In order to register touch -- and turn game.moving to true, you can (as you suggest) make a big touch sensitive area. Or you can use a 'mouse button down' rule. It will register as a touch on the whole scene without the need to make a separate touch sensing actor.

  • floatingwoofloatingwoo Los Angeles, Calif.Member Posts: 393

    @Socks @RThurman Thanks to both of your answers. It is working brilliantly .

    @Socks I was interested in your last example..."Constrain self.locX to self.time and the actor will move across the screen - very slowly! - (while continuing to wobble)." I couldn't get that one to work.

  • floatingwoofloatingwoo Los Angeles, Calif.Member Posts: 393

    Updated project....http://gsrca.de/131072

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

    @floatingwoo said:
    Socks I was interested in your last example..."Constrain self.locX to self.time and the actor will move across the screen - very slowly! - (while continuing to wobble)." I couldn't get that one to work.

    I suspect it was working but was moving so slowly (just 1pps) that you didn't notice it moving with all the other wobbling going on.

    Try multiplying the value, so for example try (self.time*100) - this will move your actor left to right at 100pps (the same speed as a linear velocity setting of 100)

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

    @floatingwoo said:
    Updated project....http://gsrca.de/131072

    Looking great ! :smile: The head movement is really good.

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

    @floatingwoo said:

    Also, you have your X constrain and your Y constrain in sync with each other, which kind of defeats the idea of a more organic random oscillation, as you have it set up the actor will simply move in a fixed diagonal line - never varying it's path.

    I'd jumble up the values more, keep them from syncing, so the path seems much more random, this kind of thing:

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

    And here's a little vibration thrown in for the rumble of the engine . .

  • floatingwoofloatingwoo Los Angeles, Calif.Member Posts: 393

    @Socks Said:
    Try multiplying the value, so for example try (self.time*100) - this will move your actor left to right at 100pps (the same speed as a linear velocity setting of 100)
    ...............
    Yep, that works.
    ................
    I'd jumble up the values more, keep them from syncing, so the path seems much more random, this kind of thing:
    ................
    Jumbling things up helps
    ...............
    And here's a little vibration thrown in for the rumble of the engine . .
    ...............
    Woho! I had the plane controlling the camera and everything was jumping in the beginning....Yeah, that should rattle the pilots brains. I may have to tone it down a bit.

    Thanks bunches man that will serve me well.

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

    @floatingwoo said:
    Woho! I had the plane controlling the camera and everything was jumping in the beginning....Yeah, that should rattle the pilots brains. I may have to tone it down a bit.

    You can take the shake out of the camera by simply giving the opposite values (just the vibration values) to the camera position.

  • anthony.veronsanthony.verons Member Posts: 4

    Hi guys,

    Thanks for your comment I learn many thinks ;)

    Socks you're really comfortable with sin & cos.. May be you'll can help me to resolve my pb.

    Here you can se my little Egg :
    https://youtube.com/watch?v=rEr4w1N7UPE

    I would like to make a movement on Position.Y in relation with the rotation of the egg.. Cause the bottom and the top of the egg go back from plateform.. and the final movement is circle, not elipse!

    Please let me know if you have time for me :)

    Thanks for all.
    Bye

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

    @anthony.verons said:
    I would like to make a movement on Position.Y in relation with the rotation of the egg.

    Hi @anthony.verons

    An ellipse (an oval) is not too difficult, but an egg shape (wider bottom / narrower top) would take a little more work - for an oval you just need to constrain the height of the egg (how far it is above the surface) to a function of its rotation . . . . hold on this might be quicker to do than to explain . . . . back in a second with a demo . . .

    Here you go, very quick demo attached, use the left and right keys, you would need to refine this, for example when you release the keys it would be best to get the egg to roll over onto one of it's 'flat' sides and settle there rather than remain upright at a weird (impossible for an egg!) angle . . . but this should give you an idea. File attached.

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879

    @Socks -- Very cool! Could you go into a little detail about the equation:
    10.5*cos( self.Rotation *2)+388

    How could it be generalized to other sized ovals?

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

    @RThurman said:
    Socks -- Very cool! Could you go into a little detail about the equation:
    10.5*cos(self.Rotation *2)+388

    388 is the absolute height of the centre of the egg.
    10.5 would be a quarter of the difference between the width and the height.
    self.Rotation *2 . . . because an oval has two peaks and two troughs.

    Not much to it really !

    Basically you want to oscillate between two different heights, with the top of a sine wave lifting the egg up at the point where it is most 'upright' (or upright+180°) and lowering it down for the flat sides. Hope that makes sense ?

    How could it be generalized to other sized ovals?

    I'm not sure, I wasn't really concentrating when I did it, but I it should be something like:

    ((height-width )/4) *cos(angle *2)+vertical offset

    P.S the relationship between the rotation and the speed is particular to the size and aspect ratio of the oval (if you want it to correctly track the floor).

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

    @RThurman said:

    P.S . . . Once you add a little shading you can get away with an egg shaped object (fatter at the bottom, narrower at the top - rather than an oval) rolling along in an oval pattern and you don't really notice that the discrepancy at all . . . file attached / L+R arrow keys.

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879

    @Socks said:
    388 is the absolute height of the centre of the egg.
    10.5 would be a quarter of the difference between the width and the height.
    self.Rotation *2 . . . because an oval has two peaks and two troughs.

    Thanks! That was very helpful.

    And egg2.zip is very handy too!

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

    @RThurman said:
    And egg2.zip is very handy too!

    Surprised you weren't tempted by the many egg puns just waiting to be used.

    :)

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879

    @Socks said:
    Surprised you weren't tempted by the many egg puns just waiting to be used.

    I confess to being tempted.
    But I declare that I abstained.

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

    @RThurman said:
    But I declare that I eggstained.

    That'll have to do.

Sign In or Register to comment.