How Do I Create a Spring-Like Shield Bash Move?

0 favourites
  • 3 posts
From the Asset Store
Awardkit
$5 USD
Create custom awards and achievement or use the many templates and create your own.
  • I’m trying to implement a shield bash move, which acts a little bit like a spring; when the player holds down the trigger, it draws the shield toward them. When they release it, the shield quickly surges forward so incoming projectiles can be batted away in a timed fashion.

    I’ve managed to get the basics of movement (i.e. preloading and unloading the shield) working with some events lightly adapted from dop2000 's recoil tutorial, but I’m having some difficulty in altering some of the maths functions. I’m generally happy with the trigger down movement that moves the shield towards the player.

    The lerped release is what’s confusing me; how can I alter this so that the shield quickly surges forward to its original position rather than slowly settling back into place?

    Again, I’m trying to get this to behave like a spring (or a bow string) where there’s a slower draw back and then a quick, strong release. Is there a way to have it momentarily shoot past its starting point on release a bit like a spring? I realise this might be getting into easing which is definitely beyond my ability at the moment!

    Is this even the best approach for this kind of action? Any code/events/suggestions are greatly appreciated. I've uploaded the project in case that's helpful too.

    https://www.dropbox.com/s/r46z9ma2usqrhpo/ShieldBash.c3p?dl=0

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Event 38 describes the leftward "drawing" motion, the amount moved per frame increases by 10 pixels every frame (self.recoil+10).

    Event 37 describes the reset motion, which moves it dt*6% (roughly 10% every frame at 60 fps) from the current position back towards 0 every tick.

    To have it "spring forward" you'll want the speed at which it resets to be faster than the speed at which it gets drawn back. However, since both events are running while your trigger is down and both forward and backwards movement are based on the same variable, if the reset speed is faster than the drawing speed it will just never move. You'll also want both movements described the same way either with dt or without (framerate dependant or independant), not both.

    Try something like this instead:

    + System: Every tick
    -> Shield: Move Self.Recoil pixels at angle Self.Angle+180
    
    + Player: ToolID = 1
    ----+ Gamepad: Gamepad 0 Right shoulder trigger is down
    -----> Shield: Set Recoil to lerp(Self.Recoil, 32, dt×6)
    
    ----+ System: Else
    -----> Shield: Set Recoil to lerp(Self.Recoil, 0, dt×30)
    

    Although IMO the concept of recoil isn't particularly suitable for the drawing of a bow, and using lerp for really fast motions with dt like this can possibly cause issues later in low framerate situations.

  • This is great, thank you so much for the explanation, it really helps me to understand how the events work - I’ll try your suggestion tomorrow.

    I’m definitely not married to this particular approach, I just observed from the recoil events I was using elsewhere that I might be able to repurpose it. I’m totally up for trying a different approach, especially if you think this way might lead to technical headaches later on. Not sure if you can suggest something? Maybe I overcomplicated this and should have tried something with vectors or Bullets instead?

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