Point to mouse/touch direction

HawtSawceHawtSawce Member Posts: 42
edited November -1 in Working with GS (Mac)
Hi,

I have been having a hard time getting GS to get 1 actor to aim at the mouse position. Sadly I've done it on a harder 3D application and can't seem to get it right here O__o

If someone could tell me the string that'd be great.
So far I have been using this and it applies to the entire screen and not just the stage area:

SpawningActor: constraings self.rotation to: vecToAngle(game.Mouse.Position.X,game.Mouse.Position.Y)

The spawned actor then moves to the destination but it isn't quite right.

Basically it is like a bullet fired from 1 actor and it should continue straight in the direction spawned. I also noted when I scroll the screen - this stops working altogether or works really wonky.

Any pointers would be appreciated.

Comments

  • firemaplegamesfiremaplegames Member Posts: 3,211
    for the vectorToAngle, try:

    Constrain Attribute: self.Rotation To: vectorToAngle(game.Mouse.Position.X - self.Position.X,game.Mouse.Position.Y - self.Position.Y)

    However, if your screen scrolls, you will need to add in the camera offset to the Mouse Positions above.

    Add an unlocked instance to the Scene that can read the camera properties, specifically the camera origin, and constrain that to global attributes.

    You will end up with something like this:

    Constrain Attribute: self.Rotation To: vectorToAngle((game.Mouse.Position.X+game.cameraX) - self.Position.X,(game.Mouse.Position.Y+game.cameraY) - self.Position.Y)
  • HawtSawceHawtSawce Member Posts: 42
    ----
  • HawtSawceHawtSawce Member Posts: 42
    The first portion of that worked. Trying second now.

    Thanks, you've ben helpful as always.
  • firemaplegamesfiremaplegames Member Posts: 3,211
    An unlocked instance has access to everything in the Scene - you can control all of the other actors, read all of their attributes, and react to them. This goes for the Camera as well.

    Create two new global integer attributes, cameraX and cameraY.

    Create a new Actor. A simple box will do. Turn off its Movable property. Do NOT put any code in this Actor.

    Drag an Instance of the Actor out into the Scene, just out of view.

    Now double-click on the Instance in the Scene. You should see a large padlock on the right side. Click on that to access its behaviors.

    Drag a Constrain Attribute behavior into the behaviors.

    Constrain Attribute: game.cameraX To: Current Scene.Camera.Origin.X

    Do the same thing for the Y origin.
  • HawtSawceHawtSawce Member Posts: 42
    Very nice it worked well. Thanks for the help :)

    Oh haha I tried to edit my last comments but didn't get to them in time. I realized what you meant after posting it like a newb. Thanks for taking the time to clarify anyhow.
Sign In or Register to comment.