Getting Enemies to shoot

funkydude

  • Posts: 170
Hi I have looked on stencylpedia to find out how to get enemies to shoot.I haven't came across any thing that would help to explain how to do this.
Is there something that can help me on this ?.

« Last Edit: January 05, 2013, 11:44:39 am by funkydude »
Games -Flash, Play free online games.
http://www.games-flash.co.uk/
See us on facebook and twitter
https://www.facebook.com/gamesflasharcade
https://twitter.com/gamesflash

t4u

  • Posts: 418
do every(rate of fire) seconds
create actor bullet near enemy with velocity in direction of palyer
USE PICTURES WHEN YOU ASK SOMETHING!
If I helped you be sure to mention it in your game.

Tutorials + downloads:
http://t4upl.blogspot.com/

funkydude

  • Posts: 170
Thanks on the input but i was hoping of something more that would explain to me what i need to do step by step.

So far i have managed to get my player ship moving,flicker,shooting,die when health is 0 plus sound effect for shooting.
I have my enemies bullet and ship with 2 behaviors enemies health and single direction motion atm.
Also background music and background images for scenes.

All i need to something that would really help with enemies ship to shoot.
Games -Flash, Play free online games.
http://www.games-flash.co.uk/
See us on facebook and twitter
https://www.facebook.com/gamesflasharcade
https://twitter.com/gamesflash

Ceric

  • *
  • Posts: 610
Here's a behavior that does this (see the attached pic at the bottom). To make it, start by creating the following attributes:

PlayerActor (its type is Actor, and it's NOT hidden)
Direction (its type is Number, and it IS hidden)
Timer (its type is Number, and it's NOT hidden)
ShotSpeed (its type is Number, and it's NOT hidden)

Next, you'll need one Event, under the Time category, which is "Do every n seconds."

Basically you need to create the shot, calculate the x and y distance between the enemy and the player actor, then use that number to calculate the direction the shot should fire. The Timer attribute is used to determine how often your enemy should shoot at your player actor. You put all of that inside the Event, as shown.

Note that for the Player Actor attribute, this is an Attribute of type "Actor," and you set it on an individual basis for each enemy actor in your scene. This means that after you place an enemy in your scene, you click on it, click the "customize" box in the Inspector on the right side of the Scene Editor, and then select your player actor (i.e. the actor you want the enemy to shoot at) in the correct behavior (i.e. whatever you're calling this behavior) shown in the Inspector.

There are a few other ways you could do this, for example you could have it detect the player actor that enters a region set in a radius around your enemy actor, so it only fires when the player gets close, but it depends on the kind of game you're making.

Oh, also note that you need a behavior on your bullet actor that explicitly removes it, i.e. kills it when it hits your player actor, after a set period of time, or when it leaves the screen. You attach that "removal" behavior to your bullet actor, though. It wouldn't have anything to do with the behavior shown.

« Last Edit: January 05, 2013, 05:47:10 pm by Ceric »

funkydude

  • Posts: 170
Thanks Ceric for the info i will let you know when done if i can get it working,thanks again.
Games -Flash, Play free online games.
http://www.games-flash.co.uk/
See us on facebook and twitter
https://www.facebook.com/gamesflasharcade
https://twitter.com/gamesflash

funkydude

  • Posts: 170
Ok got it working,but how do i get enemy to shoot at player.
Don't get me wrong it is shooting just not at player actor.
I have set the diectionr i want and bullets to go south and set speed.

The game am making is a space shooter.
Games -Flash, Play free online games.
http://www.games-flash.co.uk/
See us on facebook and twitter
https://www.facebook.com/gamesflasharcade
https://twitter.com/gamesflash

ipe 369

  • Posts: 1001
Look at the behaviour you have been given. Look at what it's doing. Think about it. Now how could you modify that to do what you want?

Ceric

  • *
  • Posts: 610
To start, did you actually select your player actor in the Scene as the Actor your enemy should shoot at? 

funkydude

  • Posts: 170
To start, did you actually select your player actor in the Scene as the Actor your enemy should shoot at?

To what you said i did.

PlayerActor (its type is Actor, and it's NOT hidden)
Direction (its type is Number, and it IS hidden)
Timer (its type is Number, and it's NOT hidden)
ShotSpeed (its type is Number, and it's NOT hidden)

But y have playeractor as attribute when there is an actor made in the behavior ?.

This is whats in my behavior.

Actor [its type is actor and its hidden] <<<this i can not delete.
PlayerActor (its type is Actor, and it's NOT hidden)
Direction (its type is Number, and it IS hidden)
Timer (its type is Number, and it's NOT hidden)
ShotSpeed (its type is Number, and it's NOT hidden)
Games -Flash, Play free online games.
http://www.games-flash.co.uk/
See us on facebook and twitter
https://www.facebook.com/gamesflasharcade
https://twitter.com/gamesflash

funkydude

  • Posts: 170
To start, did you actually select your player actor in the Scene as the Actor your enemy should shoot at?
Yes its set.

To what you said i did.

PlayerActor (its type is Actor, and it's NOT hidden)
Direction (its type is Number, and it IS hidden)
Timer (its type is Number, and it's NOT hidden)
ShotSpeed (its type is Number, and it's NOT hidden)

But y have playeractor as attribute when there is an actor made in the behavior ?.

This is whats in my behavior.

Actor [its type is actor and its hidden] <<<this i can not delete.
PlayerActor (its type is Actor, and it's NOT hidden)
Direction (its type is Number, and it IS hidden)
Timer (its type is Number, and it's NOT hidden)
ShotSpeed (its type is Number, and it's NOT hidden)
Games -Flash, Play free online games.
http://www.games-flash.co.uk/
See us on facebook and twitter
https://www.facebook.com/gamesflasharcade
https://twitter.com/gamesflash

funkydude

  • Posts: 170
Got it working ty all for the help on this thanks :).
Games -Flash, Play free online games.
http://www.games-flash.co.uk/
See us on facebook and twitter
https://www.facebook.com/gamesflasharcade
https://twitter.com/gamesflash

funkydude

  • Posts: 170
Now i have another problem,I can't get the enemy to die even tho i have gave it health 100% then die at 0,so i don't know what am doing wrong.

Its a behavior Enemies Health from stencyl that am using.
Games -Flash, Play free online games.
http://www.games-flash.co.uk/
See us on facebook and twitter
https://www.facebook.com/gamesflasharcade
https://twitter.com/gamesflash

ipe 369

  • Posts: 1001
Just post the behaviour, more chance of getting an answer because people can't be arsed to open up stencyl just to help someone else. Unless you're really nice, like... Jesus.

funkydude

  • Posts: 170
Here is a few images of enemies health.
This is all its got.

« Last Edit: January 18, 2013, 01:09:09 pm by funkydude »
Games -Flash, Play free online games.
http://www.games-flash.co.uk/
See us on facebook and twitter
https://www.facebook.com/gamesflasharcade
https://twitter.com/gamesflash

ipe 369

  • Posts: 1001
Do you have a 'sword' collision group?