Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by MooseTrap · Mar 29, 2010 at 10:10 PM · 2dphysicscharacterrolling

"wheel" character

Hi guys,

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by e-bonneville · Mar 29, 2010 at 11:02 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:

var speed = 5;

function Update () { transform.Rotate(Vector3.right Time.deltaTime speed); }

Simply put this on your wheel, and it should rotate. Another approach is to add a Wheel Collider, and rotate it using this script:

var speed = 5;

function Update () { collider.motorTorque = speed; }

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image e-bonneville · Mar 30, 2010 at 12:50 AM 0
Share

By the way, if this works for you, think about upvoting it so other people in your situation can find a (working) answer faster.

avatar image e-bonneville · Mar 30, 2010 at 12:51 AM 0
Share

Unless, of course, it works but you don't like it.

avatar image
0

Answer by MooseTrap · Mar 30, 2010 at 06:55 AM

(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:

var speed = 5; var jumpSpeed = 8.0; var gravity = 20.0;

private var moveDirection = Vector3.zero; private var grounded : boolean = false;

function Update () { if (grounded) { // We are grounded, so recalculate movedirection directly from axes moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, 0); moveDirection = -transform.TransformDirection(moveDirection); moveDirection *= speed; }

 // Apply gravity
 moveDirection.y -= gravity * Time.deltaTime;

 // Move the controller
 var controller : CharacterController = GetComponent(CharacterController);
 var flags = controller.Move(moveDirection * Time.deltaTime);
 grounded = (flags & CollisionFlags.CollidedBelow) != 0;
 transform.Rotate(Vector3.right * Time.deltaTime * speed);

}

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!

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image qJake · Mar 30, 2010 at 07:07 AM 0
Share

Code is more readable if you surround it with

 [...] 
tags. ;)
avatar image MooseTrap · Mar 30, 2010 at 07:30 AM 0
Share

Ah cheers. I used , I didn't realise I needed

 as well... No wonder it didn't look right!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Unity HingeJoint2D issues when Flipping ( Negative Scaling ) 1 Answer

Character Joints, twist and swing 0 Answers

Physics in 2d arkanoid. Tangential and normal velocity 1 Answer

Sphere Goes Crazy 3 Answers

2d - calculating velocity needed to pass by point 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges