Making an actor swing in a circle around a point, using the accelerometer

owen_dennisowen_dennis Just a guy, you know.Member, PRO Posts: 236
edited March 2016 in Working with GS (Mac)

Here's a picture to help explain what I'm trying to do:

What I'd like the player to be able to do is use the accelerometer to swing the triangle around the circle. So if you tilt to the right, the triangle rotates around the edge of the circle toward the right. If it's closer to the bottom of the circle it will rotate around the bottom, if it's closer to the top it will rotate around the top. I've set up the offset for the triangle using the usual offset you see around the forums.

It's the swinging around and controlling the rotation that has me a little stuck. One version I tried was to simply constrain the triangle's rotation to vectortoangle(game.accelerometer.x,game.accelorometery). This, however, is a little jittery and I can't really control the speed with which the rotation happens, it just clicks into place around the circle.

The second method I tried is I had an invisible weight/actor that goes in the direction of the tilt and runs against invisible walls. Then the rotation of the triangle is constrained to the vectortoangle of where that weight is relative to the center of the circle. That method works great and I can control the speed easily, however, the weight sometimes gets caught or slows down as it hits a small corner found between the meeting of the walls. I also tried making a massive circular collision box but it slows down wheneter it his the corners of the polygons.

I guess another option would be to figure out a way to use gravity and then give the triangle some weight, then have the accelerometer control gravity?

I feel like there's something there with the first method I used, but I'm not sure exactly how to get there. I need to be able to adjust the speed and I need the triangle to swing around the circle depending on which side of the circle it's on, instead of just snapping to the other side. Does anyone have any ideas on this?

Comments

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

    This might help:

  • louistrudellouistrudel Member, BASIC Posts: 15
    edited March 2016

    @owen_dennis said:Does anyone have any ideas on this?

    Im not really sure what you are trying to do here
    if you want to move an actor go around a Circle here is my way of doing it:

    create a game angle attribute: Angle

    Constrain
    Self.PositionX = (Cos(Angle) * Radius)+X
    Self.PositionY = (Sin(Angle) * Radius)+Y

    Where
    X= PositionX of the circle
    Y = PositionY of the circle
    Angle = the angle your actor is in the circle
    Radius= speaks for itself

    Then

    just play with the angle (interpolate,use timers, loop it, use your imagination)

  • owen_dennisowen_dennis Just a guy, you know. Member, PRO Posts: 236
    edited March 2016

    @RThurman said:
    This might help:

    Thanks! That's the kind of thing I'm looking for! However, It seems to have the issue I've seen where if the triangle is at like 10 and then has to go to 350, it goes around the long way instead of just crossing through 0 to get there. Which is weird, cause that %360 trick is in there.

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

    OK -- use the following equation in the constrain rotation behavior:
    self.Rotation +((((( self.downAngle - self.Rotation )+180)%360)-180).9).1

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

    @RThurman said:
    OK -- use the following equation in the constrain rotation behavior:
    self.Rotation +((((( self.downAngle - self.Rotation )+180)%360)-180).9).1

    self.Rotation +((((( self.downAngle - self.Rotation )+180)%360)-180)*.9)*.1
    
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    Thanks @Socks -- I forgot that vanilla strips out some 'control' characters.

  • owen_dennisowen_dennis Just a guy, you know. Member, PRO Posts: 236

    @Socks @RThurman That's perfect! Thank you! I'm going to spend some time breaking down the math of what this means so I can understand what's going on, but it totally does exactly what I want it to. Thanks a lot!

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

    @owen_dennis -- you are welcome!

    Most of it is the equation implements a 'negative feedback control system'.

    The " +180)%360)-180 " part manipulates the number so that it passes through the 0-360 boundary cleanly.

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited April 2016

    @RThurman said:
    @owen_dennis -- you are welcome!

    Most of it is the equation implements a 'negative feedback control system'.

    The " +180)%360)-180 " part manipulates the number so that it passes through the 0-360 boundary cleanly.

    @RThurman @Socks
    I'm using this method as well but I need to build on it. I want to have multiple actors around the radius that move synchronously. How would I do this using the new COM feature or another method that adds to the current equation? I can do it using an oversized actor with a custom collision shape but custom collisions do not respect the overlap and collide condition and I need that.

    Edit: I I figured out a solution but still interested in your options.

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

    Hm... I'd probably experiment with adding an offset to each actor. The offset would be how many degrees an actor needs to be from the original angle.

    Probably something like:
    self.Rotation +(((((self.downAngle-self.Rotation+offsetAngle)+180)%360)-180)*.9)*.1

Sign In or Register to comment.