Issue with constraining a crosshair to an actor
Hi All,
I have an actor and a crosshair (ok, that's another actor, but I'm differentiating them for you!). I am trying to set it up so that when you click on the crosshair it's X and Y will constrain to the mouse coordinates. However, I don't want the crosshair from being more than a magnitude of 100 from the actor regardless of whether the mouse is further away from the actor. In that case, the crosshair will still follow the direction of the mouse but will be locked within a boundary so it's always within a magnitude of 100.
I can almost get this to work, but for some reason it locks the crosshair to Mag 100 as I would expect when the mouse is beyond a magnitude of 100 from the actor, but it then seems to duplicate another copy of the crosshair under the mouse wherever it is on the screen. To best show this I've attached a link to a file. There isn't actually much code used. The code that is setting these rules is in the CrossHair prototype.
If any of you would be kind enough to have a look at the file in the link below and offer some advice that would be great. I've double-checked the math and the magnitude function looks right, so I'm not sure if it's a bug or I've missed something obvious.
Thanks a million in advance!
http://dl.dropbox.com/u/45687190/Actor Targeting Issue.gameproj.zip
I have an actor and a crosshair (ok, that's another actor, but I'm differentiating them for you!). I am trying to set it up so that when you click on the crosshair it's X and Y will constrain to the mouse coordinates. However, I don't want the crosshair from being more than a magnitude of 100 from the actor regardless of whether the mouse is further away from the actor. In that case, the crosshair will still follow the direction of the mouse but will be locked within a boundary so it's always within a magnitude of 100.
I can almost get this to work, but for some reason it locks the crosshair to Mag 100 as I would expect when the mouse is beyond a magnitude of 100 from the actor, but it then seems to duplicate another copy of the crosshair under the mouse wherever it is on the screen. To best show this I've attached a link to a file. There isn't actually much code used. The code that is setting these rules is in the CrossHair prototype.
If any of you would be kind enough to have a look at the file in the link below and offer some advice that would be great. I've double-checked the math and the magnitude function looks right, so I'm not sure if it's a bug or I've missed something obvious.
Thanks a million in advance!
http://dl.dropbox.com/u/45687190/Actor Targeting Issue.gameproj.zip
Comments
Here's an example, although it limits movement to a square rather than a circle.
(Just turn off your existing rule and add that code to test it)
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
When (All)
--Attribute (self.DistanceFromMaster) < 100
--Attribute (self.MouseFromMaster) < 100
http://forums.gamesalad.com/discussion/comment/238467/#Comment_238467
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@tatiang -- Yes, there are several ways to do this. HappyKat78 has created a method that is probably less processor intensive. It only requires multiplication and no trig. functions!