chasing missle

shotfrost

  • Posts: 221
i want to make a missile that when i click on an actor on screen,a missile appear and chase after the target.i have tried many way but none of them work.please help

froz

  • Posts: 250
Check the TD tutorial:
http://blog.publysher.nl/2012/04/tutorial-creating-tower-defense-game-in.html

In part 4 autor creates a behaviour for a missile-like bullets that chase after their target. You should read it from the beggining though, otherwise it may be hard to understand.

shotfrost

  • Posts: 221
thanks for help.but i cannot get into the website.besides,i have downloaded the game already.but i can't transfer the behavior to my game.And it looks like that this is created by coding,not by using blocks.since my knowledge in action script is 0,i couldn't do anything with this.but thanks for the help anyway.i really appreciate that.

froz

  • Posts: 250
Nope, it's created by blocks. There is one code block too, but it's not connected to your problem at all. However downloading the example in Stencyl is not going to help you if you can't see the tutorial itself. I have no idea why can't you see the website, it works for me.

This is the part the matters (event "when always"):


Target is an attribute that holds the actor that the bullet is chasing.

Basically what it does is check distance to target(in x and y), then if both are are below minimum distance it does something to the target, if not, it sets velocity of the bullet in direction to target and with given speed.

shotfrost

  • Posts: 221
well,thank you froz,i really appreciate,but actually the part i need most is not this.i am totally able to understand that code,and making an actor chase after an target is not very difficult,especially it is in pre shipped behavior.but the difficult one is that "when you click on an actor on the screen,any actor,that actor will be set as the target'.that thing must be code by hand,and that is the part i need most.however,there is no pre shipped behavior can do this,and the blocks provided won't do it too.however,i have found a way to do this,probably not the best solution for now but still is an solution.

« Last Edit: June 13, 2012, 06:32:28 pm by shotfrost »

froz

  • Posts: 250
You have everything you need in the palette, I don't see any need to use custom code for this. All you need is set Target in you missile behaviour to the actor that was clicked. There is a block for that (input > when mouse pressed (or released) on actor), you can use it inside "for each actor on screen" (or group or type) loop.

shotfrost

  • Posts: 221
well, i have tried it but i didn't work.first, on the mouse click behavior,in the "the when mouse is pressed on...:,you have to chose from three options:last creatd actor,a pacific actor and an attribute.second,even if some how i manage to do that,which mean if mouse is pressed on a specific  actor,something will happen,how do i set the target?i mean the target should be a game attribute,right,since the attribute will be used in different actor.but there  is no game attribute as actor.

however, it is very possible that i am lack of certain necessary knowledge to do that,since i am quite new to this.so if possiible,can you show me it in a more detailed way?i would really appreciate if you could.

froz

  • Posts: 250
You don't need a game attribute. I have just discovered that my Stencyl installation was corrupted by yesterday's crash, so I can't help you right now, but if you show what you already have, I'm sure someone here will be able to help you.

Xietao

  • Posts: 725
You can see the pre-shipped behavior "Follow Target" and then set the target at you own.
Free Time:
Monday, Wednesday, Friday: 13h
Tuesday, Thursday, Saturday, Sunday: 7h
Loving Linux...

Xietao

  • Posts: 725
Free Time:
Monday, Wednesday, Friday: 13h
Tuesday, Thursday, Saturday, Sunday: 7h
Loving Linux...

shotfrost

  • Posts: 221
well, i have tried both the pre shipped and the behavior "follow target" from stencylforge( and the later is actually a much better behavior ).and i am quite sure that i have tried anything to modified those behavior to meet my need,but actor with either of those behaviors simply cannot chase after a target that was clicked on by mouse.and i don't even know how to select a target by mouse.my solution right now is create a new behavior,and stick it to the target.that way,when the target is clicked,it will be set as an target.however, it is just an temporary solution,since if i have many different target,i have to stick to each target the same behavior.besides, if i do that,there can only one target and one chaser at a time,quite limited.soi am now looking for a better solution.and i also wonder if there is a way to do st like" if an actor(any actor) on the scene is clicked,st will happen"?,and that behavior is sticked to an actor.

froz

  • Posts: 250
Yes, there is. Use event "when mouse clicked" and inside it make loop "for any actor on screen" and inside that loop you can check if that actor was clicked and set your target to it. Note however that every actor is literally every actor, including missiles etc. So you may want to limit it to any actor of group or type.

shotfrost

  • Posts: 221
oh,thank you so much!!!!!!!!!!!i have done it successfully.now i have two ways to do the trick.this really help me a lot.an above all,the way to do this can be applied to many other of my behaviors.thanks thanks thanks.