follow mouse constrain to circle

SAMmanSAMman Member Posts: 228
edited November -1 in Working with GS (Mac)
Hey guys, could anyone help with this? I want to orbit an actor around another actor but I want it to follow the mouse and not just be going around in orbit. I want's it to be constrained around a circle still but just be able to make it follow where the mouse is without leaving the orbit constraints. Any thoughts? Thanks.
SM

Comments

  • SAMmanSAMman Member Posts: 228
    is there anyone that can help? I really need some on this one.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    Try something like this:
    constrain attribute: self.Position.X To: sceneX+orbitRadius*cos(vectorToAngle( game.Mouse.Position.X - sceneX , game.Mouse.Position.Y - sceneY ))
    constrain attribute: self.Position.Y To: sceneY+orbitRadius*sin(vectorToAngle( game.Mouse.Position.X - sceneX , game.Mouse.Position.Y - sceneY ))

    sceneX and sceneY is the center point (in scene coordinates) that you want to orbit around
    orbitRadius is the distance from the center point
  • SAMmanSAMman Member Posts: 228
    it almost works. it's just doing a strange thing with making two images of the actor that is in orbit appear instead of one. but you have certainly helped. Any ideas how to fix this? Thanks again.
  • SAMmanSAMman Member Posts: 228
    it workd, thanks!
  • SAMmanSAMman Member Posts: 228
    I had my constraints mixed up.
  • SAMmanSAMman Member Posts: 228
    any thought on how to integrate tilt control in place of the mouse? That was my next step.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    Glad it worked!

    Also, if you want the actor to point away from the center point (and towards the mouse) you could constrain the actor to:
    vectorToAngle( game.sceneX - self.Position.X , game.sceneY - self.Position.Y )

    As for tilt control, here is a way to determine "down" from the accelerometers. (The actor can point "down", whatever that means.)

    (vectorToAngle( game.Accelerometer.X , game.Accelerometer.Y )+90)%360

    The +90 is in case the device is oriented to landscape left. If in portrait, just remove the +90.

    EDIT: Both of those would be used to constrain self.rotation
  • SAMmanSAMman Member Posts: 228
    that makes sense. thanks. I am still messing around with but something just isn't working quite right.
Sign In or Register to comment.