Math question

The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
edited November 2012 in Working with GS (Mac)
I'm using this equation to make an actor function like a windshield wiper (20*sin((self.time*200)%360)) it works awesome but I would like to define the starting rotation angle, in other words facing left, right up or down flipping at 20 degrees. I've tried predefining the rotation but it always defaults to the same direction. Okay Mr Wizard help me.

Comments

  • MarkOnTheIronMarkOnTheIron Member Posts: 1,447
    I made a windshield demo a while ago: https://dl.dropbox.com/u/8244920/Windshield.zip

    In that demo to define the windshield rotation you need to add or subtract a value from the long actor instance constrain rotation rule.
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited November 2012
    Will check it out but still would like to know how to expand that expression. :D with the method I'm using I can slim the code for the paddle down to only three constrain attributes. Two for the offset and the one above if I can add the starting rotation angle into it.
  • MarkOnTheIronMarkOnTheIron Member Posts: 1,447
    In my demo there are only three constrains like you're trying to do. :)

    However if you want to use your formula try to add or subtract a value from it and see if it changes anything.
  • SocksSocks London, UK.Member Posts: 12,822
    edited November 2012
    If you are constraining self.rotation then simply add an offset (C)

    A*sin(game.Time*B)+C

    A range of sweep
    B=speed
    C=offset in degrees.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    edited November 2012
    Darn! Everyone beat me to it!

    self.startAngle+(self.wiperTravel*sin(( self.Time*self.wiperSpeed )%180))


    Edit:
    I think @Socks wins this one! It would look something like this in GS speak:
    (90+self.startAngle)+((self.wiperSweep/2)*sin(self.Time*self.wiperSpeed))
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited December 2012
    Thanx guys will test it out tomorrow! It's a flipper like in pinball but self activated. @rthurman I knew you'd have the answer! I need a math genius like you in my Skype list...lol

    Edit: damn guys I need a math tutor! I was never very good at trig or calculus. I gave you all an awesome.
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited December 2012
    Okay the results are in! The method @socks proposed doesn't work, it does funky stuff same with the second formula in @RThurman edit. @Rthurman your first equation was correct. Here is the trick, you can't set the rotation field in the actor and address it in that formula you have to create a self angle attribute and address that leaving the actor Rotation attribute alone. So the code goes as follows.

    Two constrains X & Y with the offsets.

    Constrain: Self.position X (TO) tableCellValue( game.Bumper_Picked.TBL ,2, self.Spawn Location # )-magnitude( self.Offset X , self.Offset Y )*sin(( self.Rotation )-atan( self.Offset X / self.Offset Y ))

    Constrain: Self.position Y (TO) tableCellValue( game.Bumper_Picked.TBL ,3, self.Spawn Location # )+magnitude( self.Offset X , self.Offset Y )*cos(( self.Rotation )-atan( self.Offset X / self.Offset Y ))

    One Change attribute if pulling starting rotation from another attribute or table. If preset angle then just change the value of the self attribute, Self.start_angle, in the actor. If not do below.

    Change attribute: Self.start_angle (TO) Value of start angle.

    Next we need to constrain the actors Self.Rotation to the equation.

    Constrain: Self.Rotation (TO) Self.start_angle+(20*Sin((Self.Time*200)%360))
    (20 is wipe angle) (200 is speed)

    Works fantastic thanks guys.

    @markontheiorn Why I didn't use yours is because it relies on another actor with a host of rules. Using this method I could abandon the other actor and its code.
  • capitalcarnagecapitalcarnage Member Posts: 371
    I was sure that Jimmy was the eldest in the class and that the train traveling at 1.78mph from Paddington to Aberdeen would get in first. ah well, maths was never my strong point
  • SocksSocks London, UK.Member Posts: 12,822
    edited December 2012
    >"Okay the results are in! The method @socks proposed doesn't work, it does funky stuff"

    It should work fine, but to be honest you don't state what you are using in your original post (I assumed it was constrain rotation . . . ?)


    If it is constrain attribute / self.rotation . . this will give you an undulating rotation:
    Constrain attribute: self.Rotation To: 45*sin( game.Time *100)


    And this will give you an offset of 20 degrees.
    Constrain attribute: self.Rotation To: 45*sin( game.Time *100)+20


    >"Constrain: Self.Rotation (TO) Self.start_angle+(20*Sin((Self.Time*200)%360))"

    Also here you don't need the '%360' from what I can see as the values are constantly moving between -20 and +20 (via 0) - unless I am misunderstanding why you are using the %360 ???

    It could simply be Self.start_angle+20*Sin(Self.Time*200) . . . . or put another way . . . . 20*Sin(Self.Time*200)+Self.start_angle . . . . or put another way . . . A*sin(game.Time*B)+C

    ; )
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    @FryingBaconStudios -- Here is a previous thread with a couple of examples of flipper behavior:
    http://forums.gamesalad.com/discussion/38641/pinball-flippers-is-this-possible-and-how

    @capitalcarnage -- I hated those math problems in school. (I still do.) I bet if i could have used GameSalad I would have figured them out!
  • SocksSocks London, UK.Member Posts: 12,822
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    @Socks -- Nice and straight-forward. No wasted calculations! Thanks!
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    @socks looks slick! But it's over my head as understanding it in relation to the offset of the actor. get the rotation equation but I'm lost on the offset you set up. (dyslexics and trig don't go together) as to why it acted funky, It must be the way I have my offset that screwed up your equation. You are the man.
  • SocksSocks London, UK.Member Posts: 12,822
    @FryingBaconStudios

    "I'm lost on the offset you set up."

    There is no offset, I'm just shaking the actor up and down and a little left and right - at the same time as rotating it.
Sign In or Register to comment.