Issue with constraining a crosshair to an actor

HappyKat78HappyKat78 Member, BASIC Posts: 173
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

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Pretty sure you're going to want to use a max/min function here instead of the way you're doing it.

    Here's an example, although it limits movement to a square rather than a circle.

    image

    (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

  • HappyKat78HappyKat78 Member, BASIC Posts: 173
    Thanks tatiang. I really want a circle to be honest, I initially coded it with max/min and got the square border that didn't look good for what I wanted. Do you not think the circle using Magnitude is possible? It seems like it is, I just can't work out why it's duplicating the crosshair after 100 mag.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    @HappyKat78 -- Very close. All you need to do is add a second condition to the rule:

    When (All)
    --Attribute (self.DistanceFromMaster) < 100
    --Attribute (self.MouseFromMaster) < 100

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • HappyKat78HappyKat78 Member, BASIC Posts: 173
    This works great. Wow, I was close, I knew it! Thanks so much for the help!
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    edited January 2013
    @HappyKat78 -- Glad its working for you!

    @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!
Sign In or Register to comment.