Functions and Rigibodies

Modern games lag terribly. I’m aiming for a great performance. Update is called every frame and FixedUpdate is called every fixed frame. Should rigidbody transforms be changed inside of functions such as this one?

private var hit : RaycastHit;
private var forward : Vector3;
function Update() {
     if (Input.GetButtonDown("Fire1"))
          RayFire();
}

function RayFire() {
     forward = transform.TransformDirection(Vector3.forward);
     if (Physics.Raycast(transform.position, forward, hit, range)) {
          rigibody.AddForceAtPosition(forward * force, hit.point);
     }
}

Hi Corey
All rigidibodies functions should be called from FixedUpdate. The code you wrote is right, but try to rename Update with FixedUpdate like this example:

function FixedUpdate() {
     if (Input.GetButtonDown("Fire1"))
          Fire();
}

function Fire() {
     if (Physics.Raycast (transform.position, forward, hit, range)) {
          rigibody.AddForceAtPosition(forward * force, hit.point);
     }
}

Remember that FixedUpdate doesn’t use Time.deltaTime but Time.fixedDeltaTime