# Maths junkies, I need you!

Get help using Construct 2

### » Mon May 27, 2013 2:15 pm

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!
B
5
S
1
Posts: 85
Reputation: 545

### » Mon May 27, 2013 3:31 pm

@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 helpsAphrodite2013-05-27 15:37:20
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
54
S
23
G
18
Posts: 2,123
Reputation: 17,200

### » Mon May 27, 2013 3:52 pm

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.Magistross2013-05-27 15:54:28
B
81
S
33
G
27
Posts: 1,029
Reputation: 21,143

### » Mon May 27, 2013 6:13 pm

Thanks guys, it works a charm!
B
5
S
1
Posts: 85
Reputation: 545

### » Mon May 27, 2013 6:21 pm

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?
B
5
S
1
Posts: 85
Reputation: 545

### » Mon May 27, 2013 6:33 pm

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.
B
5
S
1
Posts: 85
Reputation: 545

### » Mon May 27, 2013 6:40 pm

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?
B
5
S
1
Posts: 85
Reputation: 545

### » Mon May 27, 2013 6:43 pm

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
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
54
S
23
G
18
Posts: 2,123
Reputation: 17,200

### » Mon May 27, 2013 6:52 pm

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!
B
5
S
1
Posts: 85
Reputation: 545