I am attempting to apply custom gravity to all objects in my game. to start with all the objects should have standard (0,9,0) gravity, but as the game goes on the player has the ability to set a new ‘Down’ direction for themselves or any item/other player
so far I have
`
public class GravityScript : MonoBehaviour {
public Vector3 GravityForce;
public Vector3 tempGrav;
Vector3 newUp;
Vector3 CoG;
// Use this for initialization
void Start () {
this.rigidbody.useGravity = false;
GravityForce = Physics.gravity;
CoG= this.transform.position+this.transform.up;
Vector3 newUp = this.transform.up;
}
// Update is called once per frame
void Update () {
CoG= this.transform.position+this.transform.up;
if(Input.GetButtonDown("Fire1"))
{
RaycastHit hit=new RaycastHit();
Ray ray = new Ray(CoG, Camera.main.transform.forward);
if(Physics.Raycast(ray, out hit))
{
tempGrav = hit.normal *-10;
// tempGrav = tGrav;
newUp = hit.normal;
}
}
if(tempGrav!=GravityForce&&Input.GetButtonUp("Fire1"))
{
GravityForce = tempGrav;
}
}
void FixedUpdate()
{
rigidbody.AddForce( GravityForce * Time.fixedDeltaTime, ForceMode.Acceleration);
}
}`
it is not a simple case of inverting gravity, as it could be assigned to an angular surface. The script above only applies for modifying there own gravity, well it should I cannot seem to get it to work.
any ideas - I know I have to implement selfrighting as well - pointers on that would be good too!
Thanks