How do I make an actor "lock" onto another actor?

I'm working on a word game, and have made lots of progress but am stuck on two points:

1. I want the player to be able to select and drag a letter to a certain spot and "lock" onto a certain spot on another actor, say at 92, 138. I thought I would have some sort of rule that says when the letter is dragged close to the spot, say within 10 of the x and y coordinates (82-102, 128-148), then it would lock into the correct location. Am I on the right track? If so, how to I tell it to do this?

2. After I get the above problem solved, and the letter is moved to another spot, I want another random letter to take the first letter's place. Would I use a boolean in a rule- something like if the space is occupied with a letter, then do nothing, but if the spot has been vacated (by moving the letter), then replace with random letter? That makes sense to me, but how do I do that? How does it know if it's occupied or not?

I'm sure the answers for this are easy, but I'm new at this. I've looked through tons of posts and tutorials, and can't seem to find the answer. Any help would be appreciated. Thanks!

Answers

  • contrasthallcontrasthall Member Posts: 131
    for question 1 i believe what you want to do is - create a rule in the letters if over lap "your empty space for letter" then change attribute for position of the letter x and one for change attribute for y. You could also do a move to rule and it will give a moving to or constrain but that could make adjusting it harder. Again I'm just trying to help and don't know the exact circumstances.

    for question 2 you could have all the spaces have a boolean associated with them in the scene and if 4 is false/empty then space 3 will have a rule to look for a empty space 4 and have associated rules to move that letter over and so on and so on for spaces before 3...its a lot to explain but i hope i sent you in a right direction, good luck.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    If you are trying to have an actor "snap to grid," then you can use something like this:

    When Touch is Released
    .....Change Attribute self.position.X to floor(self.position.X/game.GridSize)*game.GridSize+game.GridSize/2

    The idea is that let's say your grid is 100 pixels wide and you have a grid square that goes from x=200 to x=300. If you drop an actor at x=220, then 220/100=2.2 and floor(2.2)*100+50=250. So your actor snaps to the middle of the grid square.

    You can then do something similar with the self.position.Y value.
  • whompywhompy Member Posts: 27
    Great, thanks guys! I will try it.
  • SocksSocks London, UK.Member Posts: 12,822
    The idea is that let's say your grid is 100 pixels wide and you have a grid square that goes from x=200 to x=300. If you drop an actor at x=220, then 220/100=2.2 and floor(2.2)*100+50=250. So your actor snaps to the middle of the grid square.

    You can then do something similar with the self.position.Y value.
    Clever stuff tatiang, consider it stolen for my own game !

    : )
Sign In or Register to comment.