How do you make an enemy shoot at the player but not always hit him?

IncrediboIncredibo Member Posts: 274
edited November -1 in Working with GS (Mac)
okay so on my next game I want there to be two actors the player & the computer but i want the computer to shoot at the player but miss at time or hit at times is this possible"??/?

Regards,
Bo

Comments

  • AsymptoteellAsymptoteell Member Posts: 1,362
    Make the direction of shooting slightly randomized relative to the actor it's shooting at's position.
  • IncrediboIncredibo Member Posts: 274
    so how would the rule be set??

    also your help is greatly appreciated
  • anithmukanithmuk Member Posts: 235
    I'm still kinda new to GS so there's probably a much better way to do this, but I would try:
    Creating two real game attributes and constrain them to the player actor's x & y position (eg player x and player y). Then on the actor thats being shot towards the player go:

    accelerate towards/move to X coordinate: game.player X + random (-50,50;or whatever numbers you want)
    Y coordinate: game.player Y + random (-50,50)

    This way whenever the actor is shot at the player's actor it should shoot anywhere from 50 to the left, 50 to the right, 50 up and 50 below the actor and occasionally hit. Of course you'll have to continually deactivate and reactivate the random expression so that it stays random and since I've never dealt with that before I don't quite know how to do it :S, try searching "seed random expression" or something like that.

    EDIT: obviously, the smaller the number spread in the random expression, the greater chance of hitting
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    Here's how I would do it. In the spawn behavior for angle in the enemy use:

    VectorToAngle(game.playerX-self.positionX,game.playerY-self.positionY)relative to scene

    Then in the bullet just have a move 0 to actor. This will only hit the hero if the hero does not move. But if the hero moves the bullet will go towards the spot that the hero was at when the shot was fired. So depending on how fast you set the move behavior to the hero will have time to get away.
  • IncrediboIncredibo Member Posts: 274
    @scitunes
    Well both character want be moving they will just be shooting at each other from side to side??
    so does the rules stiull apply
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    you could randomly select a number of 0 or 1 every time it shoots, and if it's a zero hit the player, if it's a 1 miss?
    something like that
Sign In or Register to comment.