Moving an actor in a semi-circular motion while facing outwards

SnapFireSnapFire Member Posts: 361
edited November -1 in Working with GS (Mac)
Hey everyone,

I have an actor that I need to move in a semicircle around a ball at the bottom of the screen. The actor is a rectangle, and needs to always be facing away from the ball in the bottom center, longest side away. Basically, there are tiny balls zooming toward the circle in the bottom center of the screen, and you have to stop them with your paddle. I also need that paddle to move to the right and the left when commanded to do so, in a circle. There is probably some really complicated math solution, or else it has something to do with rotate to position. Any help is greatly appreciated.

-Thomas
«134

Comments

  • SnapFireSnapFire Member Posts: 361
    Bump
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Here is a quick idea:

    Constrain Attribute: self.Position.X To: 100*cos( game.Mouse.Position.X *.375)+ game.BallX
    Constrain Attribute: self.Position.Y To: 100*sin( game.Mouse.Position.X *.375)+ game.BallY
    Constrain Attribute: self.Rotation To:vectorToAngle( self.Position.X - game.BallX , self.Position.Y - game.BallY )

    The "100" is the distance from the ball.
    The ".375" is to scale the mouse movement so that the paddle reaches the end of the semicircle as the mouse reaches the end of the scene. For an iPhone in landscape that is: 180/480 = .375.
    The rotation constraint faces the paddle away from the ball.

    Hope that helps!
  • SnapFireSnapFire Member Posts: 361
    I'm trying that now!

    Thanks,
    -Thomas
  • SnapFireSnapFire Member Posts: 361
    So.. just got through trying it. Here's what happened:

    The farther I moved my mouse to the right, the farther the paddle rotated to the left and vise versa. The paddle was also sticking so that the short side was towards the bottom center ball. It was almost like a baseball bat.

    However, this is not exactly what I wanted. What I actually need is for the paddle to:

    1) Have the long side toward the ball

    2) Move to right/left at a steady speed when an atribute is triggered

    3) Use accelerometer to move (not needed, but would be very nice)

    Other, than those things, this works seamlessly! Thanks so much.
    -Thomas

    PS: Maybe i'll use it how it is now for some other game...
  • SnapFireSnapFire Member Posts: 361
    Bump
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    OK try this:

    1) Reorient the image so that it is facing 0 degrees (pointing to the right). Alternatively, you can keep adding 90 degrees to the rotation until you get the desired orientation. (But its best to have the back side (the 'long side') facing to the right.)

    2) Replace the Mouse.Position.X with something that counts up or down (depending on if you want the paddle moving right or left) when an attribute is true.

    3) Not sure about the accelerometer -- does an attribute move the paddle or does the accelerometer? I'm not sure how you want 2) & 3) above to work at the same time. (Will require a bit more detail.)

    Hope that helps!
  • SnapFireSnapFire Member Posts: 361
    Ok, thanks for the reply.

    1) Got it - thanks

    2) I'll try that

    3) Here's the deal with the accelerometer: I want it so that when game.accelerometer.y > 0.1, then accelerate to the right and vise versa. Is it possible to accelerate back an forth in that arc motion? If I can only move at a steady pace I don't think it worth it.
    Also, there would be an option that changes game.accelerometer to 1 or game.touch to 1, so they won't be on at the same time.
  • SnapFireSnapFire Member Posts: 361
    So here's an update:

    1) Got it!

    2) I remembered I changed how it works a while ago, and now I need the paddle to zoom towards the touch, but stay in the arc. I changed game.mouseposition to game.touches.touch1, however, this is only a temporary fix. Is there any way to have the paddle accelerate toward the touch, but stay in the arc? I can't really seem to think of a solution. I know it's hard to understand but.... it would be really nice.

    3) Same as in my last post. If I could get an accelerate toward the touch thing going, it would be easy to add accelerometer.

    Thanks so much for all your patience and help
    -Thomas
  • SnapFireSnapFire Member Posts: 361
    Bump
  • SnapFireSnapFire Member Posts: 361
    Bump
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    OK -- I think I get a little clearer picture of what you are after. Try modifying the above suggestions as follows

    Make a new attribute (type=real), name it targetAngle (or whatever)

    Constrain Attribute: self.Position.X To: 100*cos( self.targetAngle)+ game.BallX
    Constrain Attribute: self.Position.Y To: 100*sin( self.targetAngle)+ game.BallY
    Constrain Attribute: self.Rotation To:vectorToAngle( self.Position.X - game.BallX , self.Position.Y - game.BallY )

    When mouse is down
    --Constrain Attribute: targetAngle To: vectorToAngle( game.Mouse.Position.X - game.BallX , game.Mouse.Position.Y - game.BallY )

    When game.Accelerometer.Y < -.1
    -- Timer: Every .05 seconds
    ----Change Attribute: self.targetAngle To: self.targetAngle - 2

    When game.Accelerometer.Y > .1
    -- Timer: Every .05 seconds
    ----Change Attribute: self.targetAngle To: self.targetAngle + 2

    Hope this helps!
  • SnapFireSnapFire Member Posts: 361
    Thanks for the help, trying that now!

    -Thomas
  • SnapFireSnapFire Member Posts: 361
    Um.....

    I tried what you suggested, and it started doing something really weird.
    The paddle stays constrained to the mouse's Y position, and is in the center of the screen. However, when you bring the mouse down to the level of the bottom-center ball, the paddle does a 180 degree turn/flip. Also, when the paddle goes about halfway up the screen, it starts to slow down and moves slower. I can't get it up to the up of the screen. As the mouse position gets higher and higher, the paddle moves slower. I triple checked everything. LEt me know if you can help. Thanks!

    -Thomas
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Weird indeed!

    I bet there is a problem with the equation in the constrain self.Position.X. (Since the Y constraint is working, but the X constraint is evaluating to 0, it makes the Y do funny things and ignores the X.) I'd suggest that there is an extra -- or perhaps a missing -- parenthesis in the equation. Or something is making the X constrain non-functional.

    Once that gets cleared up, then lets see how its working.
  • SnapFireSnapFire Member Posts: 361
    I suppose I'll look again....

    I'll let you know. Thanks again so much for all your help.
    -Thomas
  • SnapFireSnapFire Member Posts: 361
    Dude you are a freaking fortune teller! Missed the ending parenthesis on the X constraint. Thank you so much.

    However, now I'm having another problem :(
    So this is weird. I'll tell you what happens as well as I can:

    ------------

    Wow. I'm glad I decided to check over my rules one more time before I tried to explain this crazy thing I was having. And it works!!! Hurray! Turns out I had another parenthesis in the wrong place. Arg... Anyway, it's all good now. I cannot thank you enough. Without you that part of my game wouldn't have worked. I might even mention you in the credits. :)

    Thanks again,
    -Thomas
  • SnapFireSnapFire Member Posts: 361
    One more thing. (sorry)

    Could I make it so that it was smoother, like an accelerate toward thing instead of it being able to move as fast as you want it to and instantaneously where you want it to be. I'd like it to interpolate to where it should go instead of just going there immediately.
    I hope you can understand what I mean. It would give the game a much better feel, and I already have the other two modes doing that. It would be weird to have one that was like this and the others being much more smooth. If you could teach me how to do this, I'd be eternally grateful.

    -Thomas
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Glad its working for you! Here is one way to get it to interpolate to the mouse click:

    Make a variable (type = real) call it "mouseAngle" (or whatever)
    Then modify the mousedown rule--

    When mouse is down
    --Change Attribute: mouseAngle To: vectorToAngle( game.Mouse.Position.X - game.ballX , game.Mouse.Position.Y - game.ballY )
    --Interpolate Attribute: self.targetAngle To: self.mouseAngle (Duration:1 Function:Linear)

    Hope that helps!
  • SnapFireSnapFire Member Posts: 361
    Dude, you are just plain awesome! I'll try that in a few minutes!

    -Thomas
  • SnapFireSnapFire Member Posts: 361
    I tried it. It works well, but not perfectly.

    When I click my mouse over in the bottom right, it interpolates there fine. However, if while it's interpolating I move my mouse over to the other side, the paddle freezes. If I just tap places, it' fine, but when I try to drag, it's just not very smooth.

    Is there maybe another solution that could be smoother? Thank you so much.
    -Thomas
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    You probably used "constrain attribute" instead of "change attribute". (With change attribute, it only records the angle once and you don't get the constant update problem.)
  • SnapFireSnapFire Member Posts: 361
    Hey,

    So, I changed my behavior from constrain to change, and that made it better. However, this is not exactly what I wanted. I need the position to be constantly updating. So, when I move my mouse to another position, the paddle turns around and goes that way instantly. In other words, I need the paddle to move to where the touch is being pressed at all times. Not for it to move to where you touched, and then move to where you touch next. I know interpolation can't be interrupted, so could we use a different behavior like accelerate toward or something? I know i'm asking a lot from you, but I really do appreciate your help.

    -Thomas
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Hmm..... I'll need to think about that one for a minute. Do you basically want it to move at a constant speed toward the angle defined by the mouse and the ball? Or do you want it to "accelerate" to the angle? (There is a difference!)
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    OK -- here is one idea (based on constant speed -- not acceleration).

    when mouse is down
    -- when self.targetAngle < vectorToAngle( game.Mouse.Position.X - game.ballX , game.Mouse.Position.Y - game.ballY )
    ----Constrain Attribute: self.targetAngle To: self.targetAngle + 2
    ---otherwise
    ----Constrain Attribute: self.targetAngle To: self.targetAngle - 2

    You might need to mess with "<" or ">" and you might need to change the plus or minus. But that's basically the idea.

    Hope it works!
  • SnapFireSnapFire Member Posts: 361
    I want the paddle to accelerate toward the touch position in real time. So when the touch position changes, the paddle speed/position needs to change.
    I understand what you are trying to do with your last idea. However, I do need it to smoothly accelerate towards the mouseposition, and be changing in real time. That way, someone can have their finger on the screen and the paddle will be trying to get to where their finger is. However, as soon as they drag their finger somewhere, else. The paddle will slowly stop, halfway to it's first destination, and the start accelerating toward the new destination. This would all be constantly updating to where the finger is every moment. I hope this clears things up. I have been trying to think of ways to accomplish this for the last hour, but can't seem to come up with an idea... Please let me know if you have any ideas.

    -Thomas
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Hmm.... Does the acceleration need to be capped at a certain speed? Does it go faster in the beginning and then slow down when it reaches its destination? Is it dependent on the distance between its the current angle and the destination angle? (Does it move faster when it needs to traverse 180 degrees and slower when only needs to move 45 degrees?)

    Fun project!
  • SnapFireSnapFire Member Posts: 361
    Here's son=me answers:

    1)Yes, I'll use max speed like i've done before theoretically.

    2) Ease in and out if possible

    3) No, I just need it to speed up to max speed, the slow down before it reaches it's target to settle into place. Maybe we could figure out the distance from the target and figure the speed from there?

    4) It would accelerate up to the max speed, but when it gets close enough to the target, it would slow down. So if the angle was small enough, I suppose it wouldn't have to time to reach max speed.

    Thanks Again :)
    -Thomas
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Cool! You want a full-fledged negative-feedback control system!

    Its the same system missiles use (rather than ballistic bullets/cannon balls). It requires a bit more math but you are are on the right track with; "figure out the distance from the target and figure the speed from there." I might be able to get to this in a while.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    OK -- so here is a version that might be getting close to what you are looking for.

    when mouse is down
    -- Constrain Attribute: self.targetAngle To: self.targetAngle +(vectorToAngle( game.Mouse.Position.X - game.ballX , game.Mouse.Position.Y - game.ballY )- self.targetAngle )*.1

    It does not have the deceleration characteristics you were looking for (when it needs to change direction), but it does have the acceleration. You can mess with the ".1" to get different effects.
  • SnapFireSnapFire Member Posts: 361
    Ok..... I'll try that in a while.

    I'll let you know,
    -Thomas
Sign In or Register to comment.