Search Unity

How to freeze axis of rigidbody in unity.physics?

Discussion in 'Entity Component System' started by Cell-i-Zenit, Jun 22, 2019.

  1. Cell-i-Zenit

    Cell-i-Zenit

    Joined:
    Mar 11, 2016
    Posts:
    290
    Question is in the title:

    I do something like this:

    Code (CSharp):
    1. Entities.WithAllReadOnly<PlayerMarker>()
    2.                 .ForEach((ref Translation position, ref PhysicsVelocity velocity, ref Rotation rotation) =>
    3.                 {
    4.                     if (Input.GetKeyDown(KeyCode.W))
    5.                     {
    6.                         velocity.Linear = math.forward(rotation.Value) * 10;
    7.                     }
    8.                 });
    How do i freeze the rotation in the X and Z axis?
     
  2. TRS6123

    TRS6123

    Joined:
    May 16, 2015
    Posts:
    246
    In the PhysicsMass component of the entity, there will be a float3 field called InverseInertia. Set the X and Z components of that field to 0.
     
    Cell-i-Zenit likes this.
  3. Cell-i-Zenit

    Cell-i-Zenit

    Joined:
    Mar 11, 2016
    Posts:
    290
    Thank you for your response... somehow my object is still a little bit tilting.. do i need to specify anything else? Do i need to apply this value every frame or is a single time enough?