# Math: setting velocity to 0 along a specific angle

Get help using Construct 2

### » Wed Feb 12, 2014 8:38 pm

Hello all,

I have a math question for those of you who are gifted in the area. I can't find it through google because I am not sure how to ask the question.

Basically the problem is this: I have a physics object with velocity x,y. Because I need to know it's velocity relative to an arbitrary axis I calculate that and store it as Xg,Yg (it's based on the direction gravity is pulling where Yg relates to relative up/down). I calculate Xg,Yg based on polar projections using GravityAngle. Now here is what I need to do- I check Xg and if it is under a certain threshold I need to set it to zip, but the only way I can do that is by setting the objects velocity which is stored as x,y. what is the equation to alter the objects velocity in x,y such that Xg will be 0 and Yg will remain the same, and vica versa?

Thanks
B
34
S
12
G
2
Posts: 566
Reputation: 5,282

### » Wed Feb 12, 2014 8:43 pm

I just realized if I can calculate arbitrary Xg,Yg from x,y based on angle of gravity then I can calculate x,y from Xg,Yg after making necessary changes. Do you think this is the best way to do it?
B
34
S
12
G
2
Posts: 566
Reputation: 5,282

### » Wed Feb 12, 2014 8:53 pm

As it so happens I've been messing with such math lately. Calculating the velocity along an axis is a "vector projection" and looks like this:
[code]velocity_along_angle = velocityX*cos(angle)+velocityY*sin(angle)[/code]
Then you can set the velocity to only be along that axis with:
set velocity to: ( velocity_along_angle*cos(angle), velocity_along_angle*sin(angle) )
B
97
S
36
G
131
Posts: 5,513
Reputation: 83,464

### » Thu Feb 13, 2014 6:02 am

Thanks, I learned about rotation matrices and stuff today from an electrical engineer but this is a lot more simple. I need to learn this
B
34
S
12
G
2
Posts: 566
Reputation: 5,282