Maths junkies, I need you!

0 favourites
  • 9 posts
From the Asset Store
Here is the wonderful & amazing script for your website or fun with maths.
  • Hi!

    This is something I've asked for help with in a previous thread (Recoil!), but I've come up with a new way of doing it... And I need some maths.

    So in order to create some recoil for my weapons I need to propel the player in the opposite angle to that which the weapon was fired.

    I figure I can do this using Platform.VectorX and VectorY, but I need to know how to get the correct X and Y values/ratio to give the player depending on the angle which the weapon was fired.

    So...

    If Angle is 0 then I want player propelled VectorX -100 Y 0

    If Angle is 180 then propel VectorX 100 Y 0

    If Angle is 45 then propel VectorX -100 Y 100

    If Angle is 135 then propel Vectox 100 Y 100

    But I need to know the formula than I can use to calculate the X and Y for all directions. I'm sure there must be one. It's maths after all!

  • Santhenar

    I guess, as you did, you'd better propel the player of:

    VectorX = -100*cos(Angle)

    VectorY = -|+100*sin(Angle) (not sure if it - or +)

    But as you described it, it seems more like:

    VectorX = -100*floor(cos(Angle))

    VectorY = -|+(100*sqrt(2))*sin(Angle) (again, not sure if - or +)

    Hope that helps

  • A simple reversal of the cos and sin will do the trick.

    VectorX = ImpulseStrength * -cos(Angle)

    VectorY = ImpulseStrength * -sin(Angle)

    Where ImpulseStrength is an arbitrary value of how powerful the recoil will be.

  • Thanks guys, it works a charm!

  • Well actually, it doesn't quite work...

    When being propelled in the Y axis it works fine.

    However when being propelled along the X axis it still doesn't give the player the momentum that I want. The player will be propelled the number of pixels required, and then appears to hit an invisible wall.

    This is particularly apparent when being propelled at a 45degree angle wherein the player will hit the invisible wall and then the Y axis momentum will cause them to slide up said invisible wall.

    Can anyone think of a way to make it so that the player gets the same movement momentum that they would if I was just using platform controls?

  • Also, using this method cancels all other momentum... Not sure how to get around it. But it would be nice if you could use it to "rocket jump" by pointing it at the floor without it cancelling your horizontal momentum.

  • Hmm... If I had playerXvelocity and PlayerYvelocity variables then I could do all movement using that, and that would make the recoil system easier.

    Although it seems that would mean that I'd have to not use the platform behaviour for movement at all. Which would mess up the fact that my character can currently accelerate to high speeds and then brake very quickly.

    Hmmm..... I would have thought that the Platformer behaviour would have Xvelocity and Yvelocity variables already, in order to make it work.

    But how do I access them?

  • Xvelocity and Yvelocity are exactly the speed in X and Y, maybe you should add a value to them, instead of set a new value

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • SOLVED IT.

    Step 1 - add the new vectorX and Y to the current VectorX and Y, as aphrodite says.

    Secondly, my platformer deceleration was higher than my gravity, which is why there was the disparity between the X and Y effects.

    Now it works wonderfully!

    Cheers!

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