- Home /
How do I fake gravity when I disable unity's gravity?
I have gravity disabled for my rigidbody because my game its gravity direction can change and one player can be on a different gravity direction as another. I have a object made out of meshes and I want it to fall apart when I instantiate this object and collapse in the gravity direction of my choice.
I am using the script below but somehow the effect is never the same as when the rigidbody uses unity its gravity.
Its slower and does not entirely break apart when I use my code. Changing my gravity amount does not seem to have any effect and I tried using different force modes. So how do I fake the same gravity or how can i apply different gravity directions as unity only supports one gravity at a time?
#pragma strict
private var currentGravDirection :Vector3;
private var gravityAmount :float = 20;
private var rRigidbody :Rigidbody;
private var usephys :boolean = false;
//--------------------------------------------------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------------------------------------------------
function Awake() :void
{
rRigidbody = rigidbody;
}
//--------------------------------------------------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------------------------------------------------
function FixedUpdate ()
{
if(usephys)
{
rRigidbody.AddForce(currentGravDirection * gravityAmount, ForceMode.Force);
}
}
//--------------------------------------------------------------------------------------------------------------------------------
//
//--------------------------------------------------------------------------------------------------------------------------------
function SetGravDirection (gravDir :Vector3) :void
{
currentGravDirection = gravDir;
usephys = true;
}
Answer by Bluestrike · Mar 22, 2013 at 12:31 PM
Ugh SendGravDirection was not called properly , I needed to use Broadcastmessage instead of sendmessage.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Faux Gravity Prolem? #2 2 Answers
Apply gravity 2 Answers
Unity4 GetComponent(CharacterMotor) not working 1 Answer
Other gravity direction in box collider 0 Answers