GameSalad

Howdy, Stranger!

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

My rotation is jumpy

aracknoraracknor Posts: 54Member
edited November -1 in Working with GS (Mac)
I fix the other problem.
When I press UP it rotates counter-clockwise and if I keep the button pressed it moves normal. If I release the button and then I pressed again it may start in the position it was but sometimes it start in a different position on the rotation. The same happens when I hit Down.

Comments

  • aracknoraracknor Posts: 54Member
    When I press UP it rotates counter-clockwise and if I keep the button pressed it moves normal. If I release the button and then I pressed again it may start in the position it was but sometimes it start in a different position on the rotation. The same happens when I hit Down.

    The formula I am using is:
    (To move counter-clockwise)
    when all conditions are valid
    actor receive event key up
    constrain: self.Position.X to 100*cos(self.Time*300%360)+240
    constrain: self.Position.Y to 100*sin(self.Time*300%360)+160
    constrain: self.Rotation to vectorToAngle(240- self.Position.X , 160- self.Position.Y )

    (To move clockwise)
    when all conditions are valid
    actor receive event key Down
    constrain: self.Position.X to 100*cos(self.Time*-300%360)+240
    constrain: self.Position.Y to 100*sin(self.Time*-300%360)+160
    constrain: self.Rotation to vectorToAngle(240- self.Position.X , 160- self.Position.Y )

    I will be posting this on "My rotation is Jumpy" too. Almost every time I try to hit the ball, the pad appear in another place on the rotation.
    Thanks again.
  • A3MGA3MG Posts: 152Member
    You might need to make a variable to track rotation, that way you can use it to start in that tracked position.

    Come to think of it, you might want to just make a set of custom attributes for myPositionX, myPositionY, and myRotation. Then when you click up or down, first set it to the desired position and rotation using the new attributes, then have it start to do the moving.
  • aracknoraracknor Posts: 54Member
    A3mg thanks but that left me lost, i am clueless. I am new at this without any previous knowledge.
    Can you give me a little more details. Like what kind of attributes (interger, real,etc) for myPositionX, myPositionY and myRotation. Then for the setting of the desired position and rotation, where should I do this, should I substitute some of the formula or I have to insert a behavior?
    Thanks again
  • A3MGA3MG Posts: 152Member
    Can you give me a brief description (no code) of what you need it to do? Is it like a baseball bat that needs to rotate around by pushing up and down?

    Can you email me a project file? davey at a3mg dot com
  • aracknoraracknor Posts: 54Member
    ok is like a 360 ping pong game. I have the pad and I hit the ball then I move in a circle to wait for the ball and hit it again. Its like playing ping pong with myself.
    The problem is that when i press the button to move sometimes it jumps to another position in the circle and i miss the ball.
  • A3MGA3MG Posts: 152Member
    Sounds interesting. What are you using to move the paddle? Like a left and a right button?
  • A3MGA3MG Posts: 152Member
    Sorry, I see the controls in the post above.
  • A3MGA3MG Posts: 152Member
    The issue has something to do with the self.time and the milliseconds it takes to register the change in direction. The Time never stops.

    I made a similar example here and see the issue. I'll see what I can come up with.
  • aracknoraracknor Posts: 54Member
    Thanks A3MG
    I will be here.
    thanks
  • A3MGA3MG Posts: 152Member
    We may need to get ORBZ, synthesis, or FMG to chime in here. I think we need to switch up the code for the reverse direction more than just making part of the equation negative.

    On my version, when changing direction it seems good if I am close to the Y midline (y=160 or at 9o'clock and 3'oclock)

    When the paddle is at 12o'clock it jumps to 6o'clock when changing direction and opposite when the paddle is at 6'o'clock and I change directions it jumps to 12o'clock.

    This definitely has to do with the sin and cos equations.
  • A3MGA3MG Posts: 152Member
    @aracknor

    I am still looking into this. Anyone else want to chime in?
  • aracknoraracknor Posts: 54Member
    Hey A3MG I Just found a way at leas to save my purpose I am standing still because I think I am going to start bleeding from my nose at any moment... My brain is not the same after this.

    What I did was:
    Create 2 actors: 1 invisible and 1 visible which is the pad to hit the ball. The invisible will be the rotator. The rotator will have a Rule to Rotate counter-clockwise with the press of Up and another Rule to Rotate clockwise by pressing Down.
    The pad will be constrain to the Rotator position with the cos and sin formula and also it will have an Rotate To Angle to maintain its orientation.

    And with all this the pad travels smoothly Counter and Clockwise thru the entire rotation.

    Thanks A3MG for all the help and all the patient I really appreciate it.
  • A3MGA3MG Posts: 152Member
    Interesting, can you post your pad constrained to rotator position code?
  • A3MGA3MG Posts: 152Member
    I figured it out, nice solution.
  • aracknoraracknor Posts: 54Member
    First I create 2 real attributes:
    IRXPosition
    IRYPosition

    And one angle attribute:
    IRRotatorAngle

    1st Constrain attribute:
    self.position.X To game.IRXPosition +cos(game.IRRotatorAngle %360)*150

    2nd Constrain attribute:
    self.position.Y To game.IRYPosition +sin(game.IRRotatorAngle %360)*150

    Rotate to Angle:
    Angle: game.IRRotatorAngle Relative to: scene
    Speed 300 ( don't check any of the boxes)

    The Rotator is Constrained in this way
    game.IRRotatorAngle to self.Rotation
    game.IRXPosition to self.Position.X
    game.IRYPosition to self.Position.Y

    And then apply the movement with a rule to press up and Rotate Counter and so on

    Very simple but hard to find. I found some examples that game me the idea in a chainsaw tutorial
  • aracknoraracknor Posts: 54Member
    Oh I did not see your last post because i was writing the explanation and it took me a while going back and forward because my brain has not processed it entirely yet. But good
  • A3MGA3MG Posts: 152Member
    Funny, you and I did the same thing, but put the constraints/calculations on different objects.

    What I did was for the pad/paddle was have the following
    self.Position.X = IRXPosition
    self.Position.Y = IRYPosition
    Then the same vector to angle that was used before -
    Constrain: self.Rotation To: vectorToAngle(240- self.Position.X , 160- self.Position.Y )

    I put the sin/cos calcs on the rotator
    Constrain Attribute: IRXPosition To: 140*cos(self.Rotation)+240
    Constrain Attribute: IRYPosition To: 140*sin(self.Rotation)+160

    I might make something with this, will be fun to see what we both come up with.
  • ORBZORBZ Posts: 1,303Member
    Here is the problem.

    You are using self.time inside your trig functions to calculate the x and y position.

    Time passes while you are not pressing your button. When you press the button again the object teleports to the new position because at the time the button is pressed is when the cos and sin calculations are performed. The reason that it moves smoothly while you hold the button down is because small moments are ticking by on the clock and you see the x and y positions recalculated over a very small distance. This results in the apperance of smooth animation.

    To fix your problem you need to use the Move behavior.

    rule up pressed
    change attribute self.rotationDirection = 1

    rule down pressed
    change attribute self.rotationDirection = -1

    // point towards the center of the screen
    Constrain Attribute: self.rotation = vectorToAngle(270-self.position.x, 160-self.position.y)

    // move left and right relative to the actor
    Move: Angle: 90 (actor), Speed: self.rotationDirection * 100
  • aracknoraracknor Posts: 54Member
    Hey ORBZ thanks for sharing.
    I resolved my problem but I think that your answer is a lot simpler.

    This is what I don't know were to put:

    // point towards the center of the screen
    Constrain Attribute: self.rotation = vectorToAngle(270-self.position.x, 160-self.position.y)

    // move left and right relative to the actor
    Move: Angle: 90 (actor), Speed: self.rotationDirection * 100
  • ORBZORBZ Posts: 1,303Member
    put it inside your actor, not inside any rule.
  • aracknoraracknor Posts: 54Member
    I dont know, I just can make it work in this way
    When the paddle is at 12o'clock it jumps to 6o'clock when changing direction and opposite, when the paddle is at 6'o'clock and I change directions it jumps to 12o'clock.
    But like you say if I keep it pressed It keep going without the teleportation.
  • ORBZORBZ Posts: 1,303Member
    i'd have to see your code...
  • aracknoraracknor Posts: 54Member
    Ok
    I created a rule when all conditions are valid: actor receives, key, Up.
    Constrain attri: self.Position.X To 100*cos( self.Time *400%360)+240
    Constrain attri: self.Position.Y To 100*sin( self.Time *400%360)+160
    Change Attr: self.Rotation To 1

    Another rule when all conditions are valid: actor receives, key, Down.
    Constrain attri: self.Position.X To 100*cos( self.Time *-400%360)+240
    Constrain attri: self.Position.Y To 100*sin( self.Time *-400%360)+160
    Change Attr: self.Rotation To -1

    Then, not in a rule I put:
    Constrain Attri: self.Rotation To vectorToAngle(270- self.Position.X ,160- self.Position.Y )

    Move Direction 90 relative to actor, additive, Speed self.Rotation *100

    I know its wrong because is not working, it keeps teleporting.
    Can you see where or what is my mistake?
  • ORBZORBZ Posts: 1,303Member
    Yes, the problem is that you didn't do what I wrote, instead you mixed what I wrote with your own code. Look again at what I wrote, every line of what I wrote, very carefully. Don't inject any code into it. My code is a replacement for your code. You can not use self.time.

    I created a rule when all conditions are valid: actor receives, key, Up.
    DELETE THIS
    ----
    Constrain attri: self.Position.X To 100*cos( self.Time *400%360)+240
    Constrain attri: self.Position.Y To 100*sin( self.Time *400%360)+160
    -----

    ~ This is not what i wrote ~

    Change Attr: self.Rotation To 1

    ~ this is wrong too ~

    Another rule when all conditions are valid: actor receives, key, Down.
    Constrain attri: self.Position.X To 100*cos( self.Time *-400%360)+240
    Constrain attri: self.Position.Y To 100*sin( self.Time *-400%360)+160
    Change Attr: self.Rotation To -1 <--- this is totally not what i said

    ~ this IS correct ~

    Then, not in a rule I put:
    Constrain Attri: self.Rotation To vectorToAngle(270- self.Position.X ,160- self.Position.Y )

    ~ this is almost correct, I didn't say to set the speed to the rotation times 100. Read what I wrote.

    Move Direction 90 relative to actor, additive, Speed self.Rotation *100

    Read what I wrote again. It's not what you wrote.

    Only use the code i wrote in the post above, don't add your own to it. I didn't say to constrain any x or y position.

    self.rotationDirection is a variable that i made up. It's not self.rotation which is a system variable. You have to create an actor variable self.rotationDirection (integer).

    ps

    sorry if my tone seems harsh. It's nothing personal. I haven't slept and i'm in a hurry so I haven't taken the time to edit this for politeness. :)
  • aracknoraracknor Posts: 54Member
    Oh don't worry for your tone, I know that sometimes in order to learn you have to take BS from the people who really knows.

    ps
    And this is me taking the 10 seconds to edit for politeness.:)
  • ORBZORBZ Posts: 1,303Member
    cool, hope you got it to work :)
  • perseusspartacusperseusspartacus Posts: 5Member
    aracknor said:
    (To move counter-clockwise)
    when all conditions are valid
    actor receive event key up
    constrain: self.Position.X to 100*cos(self.Time*300%360)+240
    constrain: self.Position.Y to 100*sin(self.Time*300%360)+160
    constrain: self.Rotation to vectorToAngle(240- self.Position.X , 160- self.Position.Y )

    (To move clockwise)
    when all conditions are valid
    actor receive event key Down
    constrain: self.Position.X to 100*cos(self.Time*-300%360)+240
    constrain: self.Position.Y to 100*sin(self.Time*-300%360)+160
    constrain: self.Rotation to vectorToAngle(240- self.Position.X , 160- self.Position.Y )

    I tried this just now. All it did was move back and forth like a snake head, all the while rotating to face the earth. Why?
  • perseusspartacusperseusspartacus Posts: 5Member
    Oh i forgot to mention i was having jumps too. I hold up or down and it does the back and forth. I let go of the button and it seems to stop. I press it again and it jumps to where it would be if I had been holding the button the whole time.
  • tenrdrmertenrdrmer Posts: 9,934Member, Sous Chef, Senior Sous-Chef
    Well as Orbz pointed out in the next post 1 year ago that doesn't work.
    ORBZ said:
    Yes, the problem is that you didn't do what I wrote, instead you mixed what I wrote with your own code. Look again at what I wrote, every line of what I wrote, very carefully. Don't inject any code into it. My code is a replacement for your code. You can not use self.time.

    I created a rule when all conditions are valid: actor receives, key, Up.
    DELETE THIS
    ----
    Constrain attri: self.Position.X To 100*cos( self.Time *400%360)+240
    Constrain attri: self.Position.Y To 100*sin( self.Time *400%360)+160
    -----

    ~ This is not what i wrote ~

    Change Attr: self.Rotation To 1

    ~ this is wrong too ~

    Another rule when all conditions are valid: actor receives, key, Down.
    Constrain attri: self.Position.X To 100*cos( self.Time *-400%360)+240
    Constrain attri: self.Position.Y To 100*sin( self.Time *-400%360)+160
    Change Attr: self.Rotation To -1 <--- this is totally not what i said

    ~ this IS correct ~

    Then, not in a rule I put:
    Constrain Attri: self.Rotation To vectorToAngle(270- self.Position.X ,160- self.Position.Y )

    ~ this is almost correct, I didn't say to set the speed to the rotation times 100. Read what I wrote.

    Move Direction 90 relative to actor, additive, Speed self.Rotation *100

    Read what I wrote again. It's not what you wrote.

    Only use the code i wrote in the post above, don't add your own to it. I didn't say to constrain any x or y position.

    self.rotationDirection is a variable that i made up. It's not self.rotation which is a system variable. You have to create an actor variable self.rotationDirection (integer).

    ps

    sorry if my tone seems harsh. It's nothing personal. I haven't slept and i'm in a hurry so I haven't taken the time to edit this for politeness. :)

    Please in the future do not bump old threads like this. Every bit of the code posted here was created on a much older version of GameSalad and there is a very good chance some of it may not work on the current version. Try what orbz posted. If you cannot get it. just create a new thread on what you are trying to accomplish and the issues you are having.

    Thanks
    Aaron

    --Closed

    It's not my fault I never learned to take responsibility for anything. ;)

This discussion has been closed.