Point to mouse/touch direction
HawtSawce
Member Posts: 42
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.
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
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)
Thanks, you've ben helpful as always.
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.
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.