Search code examples
c#unity-game-enginegame-physics

(Unity) How do I add a force to a specific point on an object?


For a game i've been making in Unity, I need to apply two forces to an object: Firstly, I need a force that pushes the object forward, I use this code for doing so:

    void FixedUpdate()
{
    if(Input.GetKey("a"))
    {
        Thruster.AddRelativeForce(0, -Thrustforce * Time.deltaTime, 0, ForceMode.VelocityChange);
    }
    if(Input.GetKey("z"))
    {
        Thruster.AddRelativeForce(0, Thrustforce * Time.deltaTime, 0, ForceMode.VelocityChange);
    }
}

Now I also want to add a sideways force, but that needs to be at a very specific place to get the vehicle feeling just the way I want it. I haven't been able to find anything on the internet about this. So the question is: how would I apply this sideways force in a specific place on the object?

I am still a beginner when it comes to Unity and coding, so please do explain what steps you would take.

Thank you in advance!


Solution

  • Checking on the internet before asking the question would give you this result:

    AddForceAtPosition()