Sword question

  • Hello everyone!

    I have a question.. I have this sword code in my game:

    Everything works normally, except that when i switch position while attacking, the sword waits until the blade rotation finishes and then mirrors.

    How can I make it that if I want to go left and right while swinging, the rotating blade will follow me too?

    Thanks for reading!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Do you mean that if you switch directions while the blade is swinging?

    If so, you ,may consider having the sword rotate faster, or prohibiting the player from changing direction while swinging the sword.

    But other than that, you could have an event where if the sword is rotating, and the player changes direction, to stop the rotation, set the angle of the sword to the mirrored angle (You'd have to do the math on your own, so If the sword starts at 270 and goes to 0, then you'd set the angle to (270+ (270-angle)) and then continue the rotation but to the other direction.

  • that would be cause of is rotating to rotate inverse... so if the sword is already swinging it will wait for it to stop then swap mirror/not mirror.

    try disabling 2nd condition under space was pressed.

    but looking at it more i see u have a continuous check of 30 degrees of 180 to swap to nearest position.... which would mean that ur sword during swinging is not in that 30 degrees and only when hits that spot changes. try disabling that also. one of the two creates the delay. probably the later one for sure.

  • I want to add speed levels on swinging as upgrades, so I can't just make the blade too fast unfortunately, and when i switch it still looks kind of bad. And I feel that prohibiting the player to move while swinging would limit a lot in movement, especially if jumping and swinging and trying to control not to fall to your death.

    I tried to follow your instructions and did everything except the last part. I am not that experience (or a coder) so I didn't know any good way to do it. I would appreciate a bit more help with the last part.

    Also I just saw the reply from Gamecorp just now.

    I tried both of the things that you mentioned and neither worked. When I disabled the first one, I could just infinitely swing even when it was swinging, so it was breaking the swing flow, and when i disabled the second one, the blade just stayed in the bottom and never went back to 0 so that it can create an infinite looping swing. Maybe I misunderstood what you said?

    But I feel in general that what Bionic instructed can do the work if I do it correctly. So far when I change direction, the blade just stops there and it can loop after, so I just need to add to continue mirrored from the position it stopped.

    Lastly, sorry if my post and replies are a bit confusing, English is my second language so it is harder to explain things, but I appreciate all the help from everyone :)

  • Have you considered having the sword object play a swinging animation rather than rotating the object itself? It could be done in a few events and you don't need to mess about with angles.

  • Now it is almost done so it would feel like a waste of time to start from the beginning and create an animation. But if I don't find any working solution here I guess I will try to work on that :)

  • Now it is almost done so it would feel like a waste of time to start from the beginning and create an animation. But if I don't find any working solution here I guess I will try to work on that :)

    try this capx is basically what you have, but a bit more simplified with more actions. im getting lazier by each day xD

    SwordSwing-Example.capx

    now i used a family to mirror all objects that are attached to the player, that would be the player sprite, sword or shield if u have any they can all go in that family and save u some actions from not individually adding them when u press a key.

    another important thing u need to look at is i used pin to set the position of the sword to follow the player at all times. when i pined i used position only. if you change that to position and angle glitches might appear or the entire code might not even work since it would interfere with the pin priority conditions.

  • I really appreciate the work you put into this because it looks like it took a long time, but I feel that this is an inferior version of what I have and doesn't fix my problem, just creates more. When you try to swing and switch direction it just stops the swinging or sometimes just freezes mid-air, also there is no control with the swings and you can just keep swinging infinitely, even while swinging, which is unrealistic. I am sorry if I offended you in any way, I am just being honest and trying to create a smooth experience for the player :) Except if I am using your capx incorrectly while it works correctly and it is my fault?

    _

    All I need right now from someone is to tell me in an easier way or show me how to continue the swinging after I change direction from the position it stopped, like the image below, because everything else works correctly and smoothly on what I have:

  • if u want the rotate to continue when u move left right jump etc just disable the rotate stop action on the left right arrow movement. that is all on my example. probably on your also as i see from the image. hope it solves the issue :D

  • Thanks :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)