- Home /
push crate - works in editor, not on device
This is a script to push a crate in the direction the camera is facing. Works fine in the editor. It does nothing on the device. I hate bugs where it works in one instance but not another! Any help much appreciated.
function PushCrate (){
if (Vector3.Distance(Hit.collider.gameObject.transform.position, Player.position)>8.0) return;
isPushing = true;
Crate = Hit.collider.gameObject;
var cam : Transform = Camera.main.transform;
var cameraRelative : Vector3 = cam.TransformDirection (Vector3.forward);
// Apply a force relative to the camera
Crate.rigidbody.AddForce (cameraRelative * 10);
}
code here
Answer by Eric5h5 · Jun 27, 2011 at 03:10 PM
If you're calling that from Update, then differences in framerates would cause different behavior on different devices. (By the way, you can just use cam.forward
instead of cam.TransformDirection (Vector3.forward)
.)
Answer by Recluse · Jun 27, 2011 at 03:46 PM
Thanks Eric. Should I be calling the PushCrate function from Fixed Update?
Btw, I found multiplying the force tenfold got the crates moving on the iPhone!
Yu can add comments to answers ins$$anonymous$$d of writing new answers.