Constrain a rotation

MrBloggyMrBloggy Member Posts: 35
edited November -1 in Working with GS (Mac)
I have an actor which is rotated by the Y accelerometer left and right.
How can i put a constraint on this at 45 degrees each way?
Thanks in advance

Comments

  • scitunesscitunes Member, Sous Chef Posts: 4,047
    I have a game in mind that will probably need something similar. Here is where I'm going to start, but as of yet I have not tested it. I am planning on creating an invisible actor and constraining its vertical position. I will then use the accelerometer (I am not saying X and Y as I have not decided how I am going to orient the phone) to move this actor back n forth. Then I will have a visible actor that has its X and Y constrained and has its rotation fixed. This will be at the bottom of the screen and it will appear that you are controlling it when in reality the invisible actor is being controlled. So then I will put a rotate to position behavior in the rotating visible actor and will tell it to rotate to the horizontal position of the invisible actor (I will need a game attribute that the invisible actor's horizontal position is constrained to). I may need to put the rotate to position behavior in a timer and set the timer to every 0.1sec.

    If this looks too choppy then I will try a constrain attribute behavior. This is a little trickier as I will need to use vectortoangle and constrain that angle to an attribute in the rotating visible actor. Then I will constrain the rotation of the actor to that self.attribute.

    The idea is to use the accelerometer to control the invisible "target" and then have the shooter at the bottom of the screen always rotate to be aiming at the target. Then I will probably put invisible walls to keep the invisible target from going to far. This will control the range of the angle of the shooter.

    Sorry if this is a bit confusing - it's too early for me to be completely coherent.
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    Or maybe put your rotate in a rule that says

    Rule (ANY)
    when attribute self.rotation < 45
    when attribute self.rotation > 315

    Rotate

    OTHERWISE

    Rotate 0 relative to ACTOR

    That way once it hits 45 the otherwise kicks in and it should rotate to 0 relative to actor (if you select relative to scene I think it will snap back to 0)

    One of these three approaches should work (probably with some serious tinkering!)
Sign In or Register to comment.