How do I create a CPU actor that attacks another actor?

patapplepatapple Member Posts: 873
edited June 2012 in Working with GS (Mac)
Hi,

I'm trying to create an actor that every random(2,4) attack another actor. The other actor is moved by the player. I have no idea how to tell this actor to attack (go on the position) of the actor controlled by the player.
Any idea?

Second: in gamesalad, can we intercept the velocity of a collide between two actors?

Thanks and cheers

Best Answers

  • fadamionfadamion Posts: 309
    edited June 2012 Accepted Answer
    Add a global attribute called "help me" then when you attack tell 2nd actor to attack.
    in 2nd actors code you will need a vector to angle telling 2nd actor to go to the actor your attacking.

    something like this

    vectorToAngle( game.playerX - 2ndactors.Position.X , game.playerY - 2ndactors.Position.Y )
  • Fredrik BixoFredrik Bixo Posts: 239
    edited June 2012 Accepted Answer
    @patapple yeah i have also discovered that its pretty hard to make "artifact intelligence" in gamesalad

    Maybe this can help you:
  • JohnPapiomitisJohnPapiomitis Posts: 6,256
    edited June 2012 Accepted Answer
    @johnPapiomitis no, i need to create an enemy actor that is going to play with the player. The player has an actor and he need to destroy the cpu actor just going again it. The cpu actor must counterattack it. I think to create a system like this one is a little bit complicated with my capacity. I think i never see a gs game with a system like this one. I'm wrong?
    Theres been other gs games with systems like that, cause ive made some before.

    You need to set up states if you want differnent counteractions based on what the player does.

    Quick Example:

    Attribute called player state, self attribute in ai called whatever.

    When the player attacks change playerState to 1

    In ai when playerState=1
    -change attribute to random(1,2)

    When attribute =1
    -do counter behaviors

    When attribute = 2
    - take damage

    Next state

    When player hits button to flee battle or whatever
    -change playerState=2

    In ai when playerState=2
    - change self attribute to random(3,4)

    When attribute = 3
    - do nothing

    When attribute = 4
    - move to or interpolate to or whatever behavior you just to the playersX and Y to follow him.

    Youll need to set up states and counterstates for everything.

    Each number for that self attribute will represent a differnt counteraction based on the player state. You can give it more of a span in the random expressions to change the odds.

    You can also use writeable tables which im sure would make it easier.

Answers

  • patapplepatapple Member Posts: 873
    Thanks but i didn't understand the expression: i created a timer and what must i put in? A move to behavior? And the vectorToAngle expression where must go? :)
  • Fredrik BixoFredrik Bixo Member Posts: 239
    edited June 2012
    Every 2,4 sec

    Change attribute selfposition X to GamePlayerX and Selfposition Y to GamePlayerY

    And then make the player constrain selfpoistion to Gameplayer Y and X
  • patapplepatapple Member Posts: 873
    @gameARN no, with this rules the other actor follow every moment the player. i want that this actor, sometimes go again the player and then return to the previous position! :)
  • Fredrik BixoFredrik Bixo Member Posts: 239
    edited June 2012
    @patapple ok then add
    Every 2,4 sec

    change selftempX and selftempY to selfposition x,y

    Change attribute selfposition X to GamePlayerX and Selfposition Y to GamePlayerY

    when "other actor" collides with player change self position to temp x,y

    And then make the player constrain selfpoistion to Gameplayer Y and X



    does it work? :)
  • patapplepatapple Member Posts: 873
    @gameARN but if i do every random(2,4) it doesn't move directly to the other player, it goes jerky :)
  • Fredrik BixoFredrik Bixo Member Posts: 239
    edited June 2012
    @patapple ahh then instead of to "change" to use "move towards" position behavior. That would work. Or am I wrong again? :)
  • patapplepatapple Member Posts: 873
    I already use the "move to" beahvior. I need to create a very complete cpu actor but i think that is too hard to do in gamesalad.
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    edited June 2012
    I already use the "move to" beahvior. I need to create a very complete cpu actor but i think that is too hard to do in gamesalad.

    So you think it would be easier to code it? Dont take this the wrong way, because im not trying to sound rude or mean on purpose. But its not that its to hard in gamesalad, its that its above your skill level.

    Your saying you want to make a complex ai enemy actor, then your asking how to do it. We cant just tell you how to set up the whole system. You need to do it and ask specific questions when you get stuck on something. Your not really explaining to good what your trying to do either.

    And yes you can get the velocity on collide. Just make game attributes and change those to the objects motion linear x and y when it collides, then you know how fast/hard it collided.
  • patapplepatapple Member Posts: 873
    @johnPapiomitis no, i need to create an enemy actor that is going to play with the player. The player has an actor and he need to destroy the cpu actor just going again it. The cpu actor must counterattack it. I think to create a system like this one is a little bit complicated with my capacity. I think i never see a gs game with a system like this one. I'm wrong?
  • patapplepatapple Member Posts: 873
    I will try this. Can you give me any link to a game with this system? So i have an example to see :)
Sign In or Register to comment.