Can my character 'know' which actor it is touching?

robert.mccarthyrobert.mccarthy Member Posts: 165
edited September 2012 in Working with GS (Mac)
Hi All,

I have a part of my game which has stopped me in my tracks. I will explain the issue briefly, and simply, with the hope that one of you will know how to fix it:

I have 1 'character' actor which I can move around the screen. I also have 20 'ball' actors which are static and the name of each actor is a number from 1-20.

The problem I have is:

when my 'Character' overlaps/collides/touches a 'Ball' actor, I need my 'Character' actor to know which 'Ball' actor is it touching (i.e. I am touching ball of name 14).

I need to know this inside the 'Character' actor, as I have rules inside which say:
"if I am touching 'ball' 1 then..."
"if I am touching 'ball' 2 then..."
etc etc

So that is my problem. I have used random names (character/ball) just to make it easier to explain and visualise.

Thanks and hope someone can help

Best Answer

  • MobileRocketGamesMobileRocketGames Posts: 128
    edited November 2012 Accepted Answer

    Now this all works with 1, as I can 'hard-code' which ROW to update to...as I only have 1 gun.

    If I then spawn another, what I need to happen is that instead of 'hard-coding' which row the creep should update, I need the creep to know which gun it is touching, so that then it can update the relevant row.

    This would mean that if I spawn 5 guns on the screen, they don't all shoot at the same gun as they are all looking at row1.
    If i am understanding things correctly, the problem is you are using 1 prototype gun and spawning instances of that gun.
    Where as, if you duplicate that prototype and make enough guns for the player (more than they could need, essentially) and tell it that once gun1 is spawned, the next gun to spawn is gun2, and so on.
    They will all look the same, and function the same, but you can hard code different reactions because prototypes are global, (and precreated).
    Does this make sense?

    Basically your creeps are saying "when i touch this gun, I'm gonna do this"
    But you are only able to specify that one gun prototype, and so the creep can't accurately tell the engine what gun its hitting (or more importantly, what row to update) as all the instances would flag that same prototype when collided with.
    But if you already have 20 cannon prototypes (guns1-20) you can pre-specify which row it will update (rows 1-20) depending on which gun prototype it is touching.
    For example: "If I'm touching Gun5, update row 5".

    Edit # 8 :D :
    Also! if you create a new integer attribute inside the creep prototype, call it WhatGun you can say "when collide with Gun1 change self.WhatGun = 1" and "when collide with Gun2 change self.WhatGun = 2" and use self.WhatGun as a variable for the row in your table formula!

    This bypasses the need to pass an internal attribute between actors.

Answers

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited September 2012

    @robert.mccarthy

    Hi Robert, you've almost answered your own question! So the balls are static as you said, and providing Character actor can't overlap more than one ball at a time, a way to do it would be to make an integer attribute, let's call it BallNum.

    ---Add to each of the Ball actors

    When self.Ball overlaps or collides with actor of type Character
    Change Attribute BallNum to ---- the number of the ball

    ---Add to the rules of Character

    Rule: When Character overlaps or collides with actor of type Ball
    -----the following rules nested in the above
    Timer: After 0.01 secs
    When Attribute BallNum = 1
    ----do your stuff
    When Attribute BallNum = 2
    ----do your stuff
    When Attribute BallNum = 3
    ----do your stuff
    etc.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • robert.mccarthyrobert.mccarthy Member Posts: 165
    Wont work I am afraid. Basically I am making a tower defense game. I paid for a template, but they 'limit' the amount of guns (balls in my example) on the screen. Limiting them to a certain amount mean that they can store everything globally etc.

    I am in the process of doing it all dynamically, with a table.

    So at the moment, when my 'creeps/character' overlap a gun, I have sorted the rules so that it fires at the first one only. When the first one is out of its range, it fires at the second one (and so on, firing at all the creeps as they pass).

    Now, the way I have done it for the first gun is:

    When I spawn a gun, I create a row in a table. The table holds columns 'creepX' 'creepY' and 'creepNumber' (creepNumber is used to determine which of ALL the creeps over it to shoot at...this is not the problem so I wont explain much about this).

    Now when a creep overlaps a gun (so enters is shoot radius), IF its number is lower than the last 'creepNumber' in the table (meaning it is the first one to shoot at), it will update the 'creepX & creepY' with its position. It is then this position that is used for the projectile which is fired towards it.

    Now this all works with 1, as I can 'hard-code' which ROW to update to...as I only have 1 gun.

    If I then spawn another, what I need to happen is that instead of 'hard-coding' which row the creep should update, I need the creep to know which gun it is touching, so that then it can update the relevant row.

    This would mean that if I spawn 5 guns on the screen, they don't all shoot at the same gun as they are all looking at row1.

    This seems very complex to me, and it is hurting my head just explaining it, BUT I believe if I can sort this last bit out I will have a tower defense template which does not restrict the user to a certain amount of guns.

    Happy reading :)
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited September 2012


    Happy reading :)
    @-) .... :-w .... :-? ... #-o ... ;-)

    Think I see where you're at, Robert. The only thing I can suggest is - especially if there's a relatively low max. amount of guns that can be had - or the graphic is really small so even a lot of them won't add too much to the loading time - don't use spawn but put them all outside of the screen, to have them move to position instead....

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • CluvCluv Member Posts: 229
    You can use a global variable that takes into it an index from the static balls:

    Give each ball a static index. BallIndex 1, 2, etc. Then, create a rule that when they collide with the character change the global attribute (call it, BallTouchIndex) to the current ballIndex.

    Rule: when collide

    Change Attribute balltouchindex to ballindex

    This will pass the current ballindex (of the ball touching your character) out of the ball and into the game. You can then pass that wherever.

    This fix would only work for one character touching one ball. You could use a table to keep track of multiple touches, but I am assuming this will be OK.

    Good luck!
    Charles
  • SolarPepperStudiosSolarPepperStudios Member Posts: 754
    Try adding an attribute (boolean) to each actor and when the two actors collide, change both booleans to true and then what ever you want to happen to another actor, all you have to do is see if both booleans are true. If this isn't what you're looking for or it doesn't work contact me and I'll work on another solution.
  • robert.mccarthyrobert.mccarthy Member Posts: 165
    I think this comes down to the fact that you cannot pass an internal attribute of an actor directly to another.

    Once you can do this, then we will be able to finish this.

    Thanks all for the suggestions.
  • robert.mccarthyrobert.mccarthy Member Posts: 165
    You have got it MobileRocket! That is what I am trying to do.

    Your suggestion is the way we have had to go. It is a shame we had to go this way, as it is a lot more 'work' adding the 'if I touch 1 do this' for each creep/tower.

    Maybe one day, they will allow you to pass data between without going global first.

    Glad you understood what I meant :)
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited November 2012
    This thread has made me look into what can be done with tags.
Sign In or Register to comment.