If the transform.right property is Vector3(1,1,0) then your ball will go 45 degrees to the left.Īnd again it's a sloppy approximation and probably you will end up using your boxcollider bounds and maybe transform.up as well in order to achieve perfect collisions. For example, if your ball falling 90 degrees downwards and your brick's transform.right is Vector3(1,0,0), then your ball will go upwards the exact way it came. The transform.right property of your bricks will determine the virtual domain of the box collider. If these assumptions are correct then we will start by considering all the bricks are lines and compute the reflected direction of the ball by using the transform.right property of your bricks. You said your bricks have box colliders, I assume you don't have jagged edges on your bricks. I think there is another way to get over this. You collect each collision's data in OnCollisionEnter and average their position and direction to a final one.This will give you a very sloppy&unstable approximation of what you should expect. In your Unity project's Hierarchy view, right-click and select 3D Object > Capsule to create what you'll bestow movement upon. If you want to avoid writing your own physics, or you want to stick with Unity's physics, you can use some averaging with your collision data. Player Movement in Unity Using a Rigidbody and Collider Now that you know the names of the axes, you can use them to control player movement. Also, you will have to write an own script to check which blocks are affected when the ball collides with the collider. For info, the grounds have mesh collider for the two on the right. The spheres have rigidbodies using gravity and a sphere collider. As you can see in the video, when I change the height to 30, it works. You will have to generate the Mesh / Path yourself using a script. When rigidbody objects are falling from high position (300 in my test), the ground collision doesn't works, the objects falls through ground. That would likely be a MeshCollider (when you use 3d physics) or a PolygonCollider2D (when you use 2d physics). When you have two or more adjacent blocks, you will need to merge them into one object with one collider. If you want to use the Unity physics engine (maybe adding some more detailed physics might give an interesting new spin on the old Arcanoid concept), then you will have to work around that quirk in the physics engine by building your own colliders. If you want to make an authentic Arcanoid clone, all the more complex nuances of the physics engine would be switched off anyway and all that's left to do is moving the ball by a constant velocity vector and changing that velocity vector on collisions. When a rigidbody collides with the edge between two box-colliders, Unity will register it as a collision with the edge of one collider and give you a bounce-angle which you would not expect.Įither you ditch the Rigidbody on the ball, turn all the colliders into trigger-colliders, and implement the ball-physics yourself. As of version 5.3.4, this is an edge-case the Unity physics engine does not handle correctly. When you have a bunch of adjacent box-colliders and expect that they behave like a continuous wall, then unfortunately they won't.
0 Comments
Leave a Reply. |