Adam
Adam

Reputation: 3

Should I use a Unity RigidBody for my rolling sphere player?

I'm just starting with Unity/C# but I've done some programming before. I've created a very basic prototype; a scene with some platforms at the same depth and my "player" is a sphere object. It's instantiated at runtime by a custom player controller script and I've implemented gravity, acceleration, a "rolling effect" (rotating the sphere on the z-axis using eulerAngles) and collision detection with the platforms by using Rays/RayCast, in a player physics object attached to the player.

Would I have been better off just using a RigidBody on the sphere, applying a torque to the ball when the player moves right/left and letting Unity handle its rolling/movement? Is there any reason not to use a RigidBody? (Or have I just wasted an evening?:))

Upvotes: 0

Views: 6301

Answers (2)

Vackup
Vackup

Reputation: 652

If you are making a game with platforms and a rolling ball, I recommend you to take a look a "Roll The Ball" at the Unity Asset Store.

Here you have a link to the creator website http://www.lemodev.com/products/roll-the-ball.php where you can find the link to download it

The product includes all the things needed for a ball control game, such as:

player control, sound manager, coin/point manager, jump booster, speed booster, teleporter, music, 3D interacting menu, textures fonts, which all easily can be changed to fit your game.

Controls: You control the camera with the mouse and move the ball with WSAD or the arrow keys.

The ball movements is controled by physics.

To win, collect all the coins and reach the door. There are 6 pre-made levels in the package.

Upvotes: 0

Joetjah
Joetjah

Reputation: 6132

Actually, the advantage of Unity3D is that the IDE allows you to easily implement all those factors by 'just' putting a RigidBody in the scene and a standard script. Unity3D takes care of all those things like gravity and acceleration. You would have been better off using the built-in scrips and elements and changing the factors you'd like to see different.

Even so, it's good that you have programmed it all manually. It gives you a nice practice into 3D programming. But Unity3D takes care of that already so it might have been a wasted evening I'm afraid.

As an addition, when you have an object with the player movement script and a rigidbody, all public variables in the scripts are visible in the editor. That means you can easily change things like gravity or speed.

What I'd have done to achieve what you made, was adding all those objects you described, attach a PlayerMovement script to your sphere, attach RigidBody's to all objects, setting the planes to a fixed location (to prevent them dropping by gravity or, when you've set gravity to 0, to prevent them from flying away when your player collides with them thus giving them a force-push), and edit the things you'd like to see different in the editor or in the script itself.

As an addition to your rolling physics (I might have initially understood the question wrong), you'd still be better off adding a Rigidbody (rolling is all done and implemented so it looks naturally), and give the object a force in some direction, by using AddForce.

Upvotes: 1

Related Questions