Constrain to Circle while dragging?

NtGNtG Member Posts: 103
edited January 2012 in Working with GS (Mac)
Hey yo, I have seen fire maple's constrain to circle project, and what I want to do is similar to that, however I want my object im dragging to stay constrained to the outskirts of the circle. So if i am dragging my object I want it to remain on this black line:

http://www.medwaycropcircle.co.uk/The Circle ONEsmaller.jpg

Is there any way to do this? because I noticed that when dragging, objects tend to just move through other objects even if they are set to collide and not movable. Constrains override collisions. Im wondering if there is a workaround.

Comments

  • calvin9403calvin9403 Member Posts: 3,186
    so what do you want to do? just let the objects go around the circle? and what happen if you drag the actor? what do you want it to do?
  • NtGNtG Member Posts: 103
    If i drag the actor i want it to constrain to the perimeter of the circle so it cant go inside or outside
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    Here is one way to do it. Lets say that you want the center of the circle to be at 240,160 -- and you want the circle to be 75 pixels from the center to the perimeter. (The circle has a radius of 75.) And lets say you want the object to drag at a constant distance of 75 pixels from the center of the circle. Here are the rules/behaviors:

    Make an attribute (of type real) called "mouseAngle"

    Rule: When touch is pressed
    ---- Constrain Attribute: game.mouseAngle To: vectorToAngle( game.Mouse.Position.X -240, game.Mouse.Position.Y -160)

    Then have the following constrains _outside_ of the above rule:
    Constrain Attribute: self.Position.X To: 240+75*cos( game.mouseAngle )
    Constrain Attribute: self.Position.Y To: 160+75*sin( game.mouseAngle )
    Constrain Attribute: self.Rotation To: game.mouseAngle


    Thats it! You can change the x,y coordinates and the radius to suit your needs

    Hope this helps!
    RThurman
  • NtGNtG Member Posts: 103
    RThurman to the rescue again! haha I will try this out tomorrow morning, hopefully it works out the way I intend it to!
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    Of course it will work out the way you intend it to! GameSalad is perfect for this kind of thing!

    RThurman
  • NtGNtG Member Posts: 103
    I am having a problem with the object not staying with the mouse (I dont really know how to describe this). When I click and then drag then the object I am dragging isnt following the mouse position perfectly any way to fix this? Could it be a problem with my dragging rule?
  • NtGNtG Member Posts: 103
    nevermind, fixed it lol :)
  • CloudsClouds Member Posts: 1,599
    @RThurman

    Brilliant stuff !! (re: draggable circle code)
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    @NtG .... Glad its working for you!

    @Tynan .... It is brilliant! But it's not my idea. I lifted it off of someone else. Personally I have not had an original thought. All my posts come from cobbling together others' stuff. There have been some truly great posts in this forum. And the previous forum was full of great pearls of wisdom from the legends of GameSalad.

    RThurman
  • CloudsClouds Member Posts: 1,599
    edited January 2012
    @RThurman

    "It is brilliant! But it's not my idea. I lifted it off of someone else. Personally I have not had an original thought"


    You disgust me, you shameless thief . . . .

    [goes off to work on his game largely cobbled together from stolen ideas]

    ;)
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    You disgust me, you shameless thief . . . .
    Hey! I'm not shameless!

    But I am appreciative of this great forum and the shamelessly helpful people who frequent it.

    RThurman
Sign In or Register to comment.