hi.. i'm trying to code Arkanoid in Unity, and i'm not really sure how to do the ball movement thing the best way. searching on the web, i found this post (its a post about the Pong ball movement): http://answers.unity3d.com/questions/28037/question-pongball-to-change-direction.html i prety much tryed to do everything like advised in the post, but it's not working (ball never actually behaves the right way) the code i'm using for the ball is this one: PHP: var velocity : Vector3; function Update() { transform.Translate(velocity * Time.deltaTime, Space.World); } function OnTriggerEnter(other : Collider) { //All collision objects must be oriented to face the play area velocity = Vector3.Reflect(-velocity, other.transform.forward); } i tried changing other.transform.forward to transform.up and everything else but nothing worked. so my question is, how i would implement the ball movement the best way.. if unity physics can do everything for me, i would like to do that. if a raycast is the better solution, then i would try do that... please advice regards
maybe you can use Vector3.Distance to calculate the dist is like it <=0 then call the reflect function
this is what i did: set Drag and Angular Drag of your ball to 0. created bouncy physics material (u have similar in unity asets): Dynamic Friction :0 Static Friction: 0 Bounciness: 1 Friction Combine: Minimum Bounce Combine: Maximum -- and everything else to 0! Than on Project settings -> Physics set Bounce Threshold to 0. If u don't do that and your ball movement speed is slow it will stay stuck in walls. now just set velocity in desired direction and ball will bounce perfectly from all colliders. No need for calling update method to handle your physics. One more thing I did was to make sure that ball position and velocity in z direction is 0 in OnCollisionExit method. And one more tip. If you are using velocity you don't need to use Time.deltaTime. I just learned that recently
2 phreak: wow, your information is priceless.. i spent all day long, trying to figure out, why ball bouncing wrong sometimes.. but now looking like it's prefect.