Just wondering what the best method would be, for controlling a character that is basically just a wheel, in a 2.5D environment.
My aim is to have it move in two dimensions (move left and right whilst rolling, fall down, but not move away or towards camera), and if possible be affected by physics.
I've been able to achieve basic functionality using the capsule collider, this gives me the basic movement, but no rolling, and no real physics.
I've been reading tutorials such as the 2d Game Tutorial, and the 3D platformer tutorial, but I'm having trouble determining what my workflow should be.
Cheers in advance!
asked Mar 29 '10 at 10:10 PM
If you're using a capsule collider, you can rotate the wheel via script. If you want cool physics, add a rigidbody, which uses PhysX. Here's a script that'll rotate your wheel:
Simply put this on your wheel, and it should rotate. Another approach is to add a Wheel Collider, and rotate it using this script:
You can add WheelColliders from the Physics option under Add Component. Create an empty GameObject. Then, add a WheelCollider and this script to it. Move the wheelcollider to your wheel, and make it a child if the wheel. Note: Wheelcolliders do not do the graphics for you. What you want to do, if you're using the wheelcollider is to remove the collider from your wheel, and put the first script on it. That will ensure it rotates, but doesn't do any physics or interact with the terrain. Hope this helps!
P.S. This doesn't do any of the character controlling for you - just the physics. If you want the wheelspeed to be modifiable, try using an if input statement to detect which arrow is pressed, and to increase the speed based on that.
answered Mar 29 '10 at 11:02 PM
(code wouldn't fit in comment)
Cheers. I'm having a bit of trouble getting this to work though? Where should this code be? I've made a movement script for the character, attached a rigidbody, and included the first code snippet in the script. My object hierarchy is: Game Object - Using this as container, script is attached here) Player Prefab - No script or animation Weapon with Mouse-Aim Probably (definitely!) a n00b error.. I'm very new to scripting. Code is posted below:
Is there a way to restrict the player's rotation? At the moment the character is ever-so-slowly pivoting towards the camera.
I read something about "Configurable Joints". Is this something I should look into for this type of character..? I believe this was used in the 2d platform tutorial for the rocket. If this should be a new question I can repost, but I think it ties into this one.
Thank you for your help!