Cant crack the code - Sword Attack

brett-nortonbrett-norton Member, BASIC Posts: 64

Hi All

A little background first, Im half way through a side scroll i have player moving right and enemys spawning off screen running to the left. I have an invisible sword spawn in front of player to kill the enemys, if the enemys hit the player he looses - 10 health.

But problem being i can get the enemy to die without taking the player health also here is the code.

Invisible Sword

Constrain self position X to Game.player.locationX + 150
Rule if game.touchweapon is false- do - destroy actor

Touch weapon ( touch button to activate sword attack " invisible Sword" )

Rule when touch is pressed - set - game touch weapon to true - or else - false
Timer - After 0.05 seconds - set - game.touchweapon - to - false

Enemy

Set - self.motion.linear.velcoityX tzo - 400
When actor colides with invisible sword - do - set self.motion.linear.velocityX - to - 0

Rule If self.motion.linear.velocityX = 0 - do - Death animation
Rule if self motion.linear.velocityX = 0 - do - change attribute game.determineifdead to true
Rule if self motion.linear.velocityX < 0 - do - change attribute game.determineifdead to false

Player

Rule if game.touchweapon is true - do - spawn actor "invisible sword"
Rule when actor colides with enemy and game.determineifdead is false - do - set game.health to game.health-20

Hope that makes sense, Thanks in advance.

Comments

  • NalycanNalycan Member, PRO Posts: 96

    Maby its not working because of GS delay. Put a timer in the collision rule, say 0,2sec. just to make sure "determineifdead" is triggered.

    Hope it helps, and good luck

  • brett-nortonbrett-norton Member, BASIC Posts: 64

    Will give that a try tommorow Lycan thanks for input, i will give you update on your solution. Would you suggest a better way to kill enemys with sword? And loose health when touched i cant seem to get my head around it.

    I was also thinking maybe dont make player and enemy touch and have an invisible ememy actor constrained to the visible enemy and let that do the colision part which can be destroyed when hit with invisible sword but leaving visible enemy behind to activate and animate the death scene.

  • NalycanNalycan Member, PRO Posts: 96

    You could do... When enemy touch sword, spawn die-actor and destroy enemy actor.

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited March 2017

    I see you issue in the touchweapon rule. You are using the else section which means when touch is released it turns to false. Does it have to stay touched for the sword to stay active? If not, remove that else code. Also, I would use a step integer instead of bolleans for stuff like that. It streamlines the code and avoids Logic collisions. Also you can do a sword attack with an animation instead. See my video series on custom collision shape animations.

  • brett-nortonbrett-norton Member, BASIC Posts: 64

    It Worked Awesome, Thanks for your time GS Guru.

Sign In or Register to comment.