Cheap gravity script

hi,

I understand that Unity’s Gravity calculation for Rigidbodies is quite expensive for mobiles devices. I was wondering if there is a work-around to this, possibly a script simulating the same effect / acceleration?

var velocity: Vector3 = Vector3(5, 5, 0);

var gravity: float = 9.8;

function Update(){ 

// apply gravity 

velocity.y -= gravity * Time.deltaTime; 

// calculate new position

transform.position += velocity * Time.deltaTime;

}

Calculating gravity effects is the cheapest part - the big problem comes from collision detection and reaction to collisions, other tasks that the management of a rigidbody requires.

If you want to simulate gravity in a simple object, just calculate its movement frame by frame:

var velocity: Vector3 = Vector3(5, 5, 0);
var gravity: float = 9.8;

function Update(){
  velocity.y -= gravity * Time.deltaTime; // apply gravity 
  transform.position += velocity * Time.deltaTime; // calculate new position
}

This simple code will make the object to which it’s attached to describe a ballistic trajectory. Collisions aren’t detected, but maybe a good compromise could be achieved by adding a kinematic rigidbody to the object and setting its collider to trigger, then using OnTriggerEnter to detect collisions.