Character hit behaviour

Codeclass2

  • Posts: 42
Hello. I am sorry for such a huge and noob question, but i couldn't find any solutions on Youtube or on this forum.

I'm making a platformer. My main characters has 2 animations of close range attack. But i don't know which behaviour to use to actually attack with this character (tried couple, they didn't work). Which behaviour or script should i use? And which behaviour do i need to use on my enemies for them to die when they are being hit?

Vaibhav Sangwan

  • Posts: 157
Hi CodeClass2,
your question is a bit difficult to understand.
Can you explain in some detail what you exactly want to do?


If you want to create a behaviour so that your player attacks on an enemy if they are near your player, then you can either create a region around your player and if an enemy is inside it,  make your player do whatever you want him to do.
Or you can use the Pythagoras theorem to get distance between the enemy and your player, and if this distance is smaller than the distance you specify, make your player do whatever you want.

Codeclass2

  • Posts: 42
Ok, sorry for being not so specific. For starters, i want to make attack behaviour. I tried couple of them in StencylForge, but they don't seem to work.
About hit collision - are there any tutorials or something about it?

Vaibhav Sangwan

  • Posts: 157
Everything you should know about collisions:-
http://www.stencyl.com/help/view/collisions-and-groups/
A video on killing an actor when collided with anything else:-
https://www.youtube.com/watch?v=hd1JuZmMep8

Codeclass2

  • Posts: 42
Yeah, this one i looked at, doesn't resolve my problem.

Again, how do i make attack behavior? Downloaded behaviours like "attack on button" doesn't seem to work. I think, when i learn this thing, i would be able to set collisions myself.

DeckBlack

  • Posts: 159
+ If the character can move during an attack, you will need to move the Slash along with it while the Slash exists.

Vaibhav Sangwan

  • Posts: 157
"Attack by Hitting Button" behaviour(on StencylForge) seems to be working fine for me.
Try using that.
+ If the character can move during an attack, you will need to move the Slash along with it while the Slash exists.

To move the slash along with the character,
-create an actor attribute and set it to slash in char.png image.
-in when updating event of  character,add

if("actor attribute" is alive)

  set x of "actor attribute" to         (x of self+______)
  set y of "actor attribute" to         (y of self+______)

Codeclass2

  • Posts: 42
Thank you guys for helping me. None of those things worked, but then i thought that behaviour "Jump and run movement" might be blocking her other animations. I deleted this behaviour and yep, attack scripts started working. So now i just need to understand how to do these 2 behaviours together :) Any suggestions on how to do it?

« Last Edit: March 11, 2018, 11:25:43 am by Codeclass2 »

Vaibhav Sangwan

  • Posts: 157
You should use (current animation for self) code in "if" codes when switching animations in the actor behaviors.

Codeclass2

  • Posts: 42
Ok, i didn't quite get it... where do i need to use that script? If i'm using DeckBlack's script, for example.

Vaibhav Sangwan

  • Posts: 157
If you don't have combined animations like jump-attack or running-attack, you can see this.
Sorry for making it so complex but I couldn't make it more simpler.

Codeclass2

  • Posts: 42
Again, Vaibhav, thank you for helping me so much. I'll try that script and write how it works.
It just controls the animations, as i see. With which scripts do i control the movement and jumping though?

Vaibhav Sangwan

  • Posts: 157
but then i thought that behaviour "Jump and run movement" might be blocking her other animations.
You have "jump and run" and "attack" behaviour, right?
add the code given in animations.png to your actor and just remove all the animation blocks and also animation attributes(if you wish) from both of them.
Do not remove control codes.


Codeclass2

  • Posts: 42
Yeah, i get it, removed animation scripts from movement behaviour.
Making your script atm, little question: how to make "=" blocks? Like "current animation of self = running", for example.

DeckBlack

  • Posts: 159
Flow -> Comparision ->  1Anything = 2Anything