I am new to unity and I have no idea how to add a force to an object at a position that is not (0,0,0) Relative to the object. When i started adding forces i used the function Ridgedbody.AddForce this just added a force that was relative to the game maps center location. I then used Ridgedbody.AddRelativeForce this gave the object a force but it was only able to be applied from the objects center. I have heard about AddForceAtPosition but i don’t know how to apply it, and i think it might just give a force relative to a point on the map. Here is what i have so far for my object controller.
using UnityEngine;
using System.Collections;
public class Driver : MonoBehaviour {
// Use this for initialization
void Start () {}
// Update is called once per frame
void Update ()
// roll controls
{if(Input.GetKey(KeyCode.W))
{rigidbody.AddRelativeTorque(15, 0, 0);}
if(Input.GetKey(KeyCode.S))
{rigidbody.AddRelativeTorque(-15, 0, 0);}
if(Input.GetKey(KeyCode.A))
{rigidbody.AddRelativeTorque(0, 0, 10);}
if(Input.GetKey(KeyCode.D))
{rigidbody.AddRelativeTorque(0, 0, -10);}
if(Input.GetKey(KeyCode.RightArrow))
{rigidbody.AddRelativeTorque(0, 5,0);}
if(Input.GetKey(KeyCode.LeftArrow))
{rigidbody.AddRelativeTorque(0, -5,0);}
// forward and backward controls
if(Input.GetKey(KeyCode.UpArrow))
{rigidbody.AddRelativeForce(0,0,10);}
if(Input.GetKey(KeyCode.DownArrow))
{rigidbody.AddRelativeForce(0, 0,-10);}
}}
Im Ok with my torque forces being applied from the objects center but i want my regular forces to be applied 1.5 unity distance units below the objects center. So to be spesific i want a force with a magnitude of (0,0,10) applied from a transform location of (0,-1.5,0) relative to the objects center, and another force with a magnitude of (0,0,-10) applied from a transform location of (0,-1.5,0) relative to the objects center.
I would also like to know how to how to apply torques from a none central position relative to the object as there is a good chance i will have to do this later on.