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. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Is there any way I can apply a force vector at a certain location on a physics mesh?

Discussion in 'DOTS Physics' started by Kmsxkuse, Jan 23, 2020.

  1. Kmsxkuse

    Kmsxkuse

    Joined:
    Feb 15, 2019
    Posts:
    196
    I was following this wonderful tutorial linked below that used the old rigidbody based physics and I reached the point where buoyant force is applied at the center of every calculated subtriangle of the boat/block model's mesh.

    However, it does not seem like an equivalent method or even ability to do so is found in DOTS Physics. At least in my quick scan of the functions a PhysicsBody and PhysicsMass typed variable has to offer.

    Tutorial: https://www.habrador.com/tutorials/unity-boat-tutorial/3-buoyancy/

    In particular this section:
    Code (CSharp):
    1. // Calculate the buoyancy force
    2. Vector3 buoyancyForce = BuoyancyForce(rhoWater, triangleData);
    3.  
    4. // Add the force to the boat
    5. boatRB.AddForceAtPosition(buoyancyForce, triangleData.center);
    Current direct conversion from Mono to DOTS (I keep writing ECS) process (nonfunctional): https://github.com/Kmsxkuse/ProjectBoxes/blob/master/Assets/Scripts/Buoyancy.cs
     
  2. Nothke

    Nothke

    Joined:
    Dec 2, 2012
    Posts:
    112
    There are extensions to do that in Unity.Physics.Extensions. Note that you will need the PhysicsVelocity, PhysicsMass, Translation and Rotation components to perform it.

    Code (CSharp):
    1. using Unity.Physics.Extensions;
    2. ...
    3. physicsVelocity.ApplyImpulse(physicsMass, translation, rotation, impulse, point);
    Note that "impulse" is force in time, so you'll need to multiply the force with deltaTime.

    There is an alternative extension using a PhysicsWorld and a rigidbody index.