unity3d - Object Collision Issue - Weird Behaviour - Unity -
i wondering if give me hand problem i'm having objects , collisions in unity.
i have sphere object being controlled users phone's accelerometer. sphere moves around fine once hits wall sphere starts acting weird. pulls in direction of wall collided with, starts bouncing, , overall not responsive anymore movement of phone.
any idea why happening?
here script used control player's sphere.
using unityengine; using system.collections; public class playercontroller : monobehaviour { public float speed; void update() { vector3 dir = vector3.zero; dir.x = input.acceleration.x; dir.z = input.acceleration.y; if (dir.sqrmagnitude > 1) dir.normalize(); dir *= time.deltatime; transform.translate(dir * speed); } void ontriggerenter (collider other) { if (other.gameobject.tag == "pickup") { other.gameobject.setactive(false); } } }
that happens because object has 'rigidbody' component, and, suppose, it's not kinetic rigidbody. basically, behaves should: real physical object not pass through object, basic behaviour of physics engine. however, since don't operate physics-based object using forces, manually change it's position, break level of abstraction. in result, move object inside wall, , can't out.
use applyforce method instead. if want pull or push object (instead of move, contradicts fact these objects managed physics) in direction every frame, should use forcemode.acceleration
(or forcemode.force
, if want effect depend on mass) every physics frame, means have use fixedupdate
method instead of update
.
Comments
Post a Comment