Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

PhysicsVelocity and rotation

Discussion in 'Physics for ECS' started by andynayrb, Jan 3, 2020.

  1. andynayrb

    andynayrb

    Joined:
    Feb 28, 2019
    Posts:
    25
    I am pretty new to physics, and I have enjoyed learning about it up to this point. So I am learning to move things around with physics. Going pretty well so far. I am stuck however at moving something forward after it rotates. I was able to get it working when using translations, but I haven't been able to find the trick with physics. I understand why it ignores the fact that it has rotated, this seems like a very common task. Is there a way to calculate the linear velocity that would be needed, offset by the angle of rotation of the object? Or is there an easier way to do it. Thanks in advance.
     
  2. TRS6123

    TRS6123

    Joined:
    May 16, 2015
    Posts:
    246
    The easiest way I can think of to do it is this (using Unity.Mathematics):
    physicsVelocity.Linear = math.forward(rotation.Value) * speed.Value;
     
    steveeHavok likes this.
  3. andynayrb

    andynayrb

    Joined:
    Feb 28, 2019
    Posts:
    25
    Thanks, that is definitely getting me moving in the right direction (pun intended). A good starting point for sure.
     
    steveeHavok likes this.