- Home /
Controlling world gravity via object's y axis ; transform.up = -Physics.gravity in C# ?
Hi all, my objective is to control world gravity using the y axis of an object. The reason being is to control gravity using the tilt sensors of a mobile device. Im using GyroDroid to rotate the object containing this script.
I've looked through Unity answers, many in Java, and cant figure out what the heck I'm doing wrong. I'm an Artist so please be kind! I'm coding in C#
Here's what I have so far;
public class gravityForce : MonoBehaviour
{
private Quaternion gravityDirection;
void FixedUpdate ()
{
gravityDirection = Quaternion.FromToRotation(transform.up, -Physics.gravity);
Physics.gravity = gravityDirection;
}
}
Any advice is appreciated Thanks in advance!
Answer by S_Darkwell · Mar 08, 2015 at 02:22 AM
Try this:
gravityDirection = Physics.gravity.magnitude * -transform.up;
Physics.gravity = gravityDirection;
Hope that helps!
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
C# Check Physics.Raycast Once 0 Answers
Easiest free way to fracture mesh? 1 Answer
Problem Trying to Apply Non-Kinematic Velocity to Rigidbody 0 Answers
Question about Physics2D.Linecast 1 Answer