Help with checking actors position against another

Hi All,

I was on game salad a couple of years ago and decided to return! Slowly getting back into things but now working on my windows PC rather than a mac so posting my question under this. I have a scene where I have an actor the user controls, I have other actors spawning off scene and moving across at the top. I want the moving actors to drop when they get within a set distance from the player actor.

I currently have a timer on the player actor to update game attributes for playerx/y position every 0.1 seconds, then on the moving actor check every 0.1 seconds if self.position.x < game.playerx + 50, if so then accelerate downwards but they don't move?

Can anyone give any advice? Thanks

Comments

  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    what I'd do:

    create two global attributes:
    playerX
    playerY

    on your player actor, constrain playerX to self.position.x, and playerY to self.position.y

    then on your moving actors, create an attribute called distance.

    constrain distance to the magnitude of (playerX-self.positionX,playerY-self.positionY).

    this should give you the distance from each actor to the player

    finally, have a rule that says something like

    when self.distance is < 100
    do whatever
  • MaccaMcgillMaccaMcgill Member Posts: 8
    Thanks for the reply jon. Where would you have the final rule? On the player actor or on the moving actors?
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    You put the last rule in the actor or actors you want to do something when the are a particular distance from each other.
  • MaccaMcgillMaccaMcgill Member Posts: 8
    Hi Jon,

    I tried exactly what you said but It's not working. What I did is as follows:

    Game Attributes (both integers)
    PlayerX
    PlayerY

    Player Actor:
    Constrain attribute game.PlayerX to self.position.x
    Constrain attribute game.PlayerY to self.position.y

    Moving Actor:
    Spawns and moves across the screen right to left.
    Attribute distance (integer)

    Constrain self.distance to magnitude(game.PlayerX - self.position.x, game.PlayerY - self.Position.y)

    Rule if self.distance < 50
    then accelerate 270 relative to scene with acceleration 150.

    However, the moving actor will just move right to left on screen and not drop. Where did I go wrong?
  • MaccaMcgillMaccaMcgill Member Posts: 8
    Can anybody help? Do I still need a timer on the moving actor or player actor to check/update their positions or does it get automatically updated upon moving?
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    put a display text behaivor on the moving actors to display the value of self.distance so you can check the value. what does it say? do you see it adjusting?
  • MaccaMcgillMaccaMcgill Member Posts: 8
    yeah the value is displayed. I worked out that I was asking it to be less than 50 away before it drop which is too low a value. Is it possible to check the distance of just the x-axis rather than y as well?
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    edited February 2014
    Yea just subtract self.x-player.x. Instead of using magnitude
Sign In or Register to comment.