Math: setting velocity to 0 along a specific angle

0 favourites
  • 4 posts
From the Asset Store
Aliens are invading our planet! Solve the math question, and attack the alien with your laser. Covers addition, subtract
  • 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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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?

  • 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:

    velocity_along_angle = velocityX*cos(angle)+velocityY*sin(angle)

    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) )

  • 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

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