Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by faye921 · Feb 06, 2013 at 01:22 AM · character controllerbox collider

Character Controller for quadruped character

Hello I am trying to add a character controller to a fox character, currently I am using the Character controller but as this is capsule shaped it does not work for my character, is there a way I can change the shape of the controller, flip it or connect a box collider to the controller (I'm sorry for the question I'm new to Unity)

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

1 Reply

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

Answer by aldonaletto · Feb 06, 2013 at 01:05 PM

Unfortunately, the CharacterController is always an upright capsule collider - you can't replace it with a box collider or horizontal capsule, nor add other colliders to it: the CharacterController "thinks" that it's colliding with the other colliders, and stands still or moves to stupid directions.
The best you can do with a CharacterController is to adjust its height and radius so that it becomes a sphere (radius = height/2). If this doesn't work fine in your case, a possible solution is to use a Rigdbody character: try a box collider with the wiki script RigidbodyFPSWalker - this script requires a capsule collider, but you can remove this restriction like below:

 var speed = 10.0;
 var gravity = 10.0;
 var maxVelocityChange = 10.0;
 var canJump = true;
 var jumpHeight = 2.0;
 private var grounded = false;

 // capsule collider removed from this line:
 @script RequireComponent(Rigidbody)
  
 function Awake ()
 {
     rigidbody.freezeRotation = true;
     rigidbody.useGravity = false;
 }
  
 function FixedUpdate ()
 {
     if (grounded)
     {
         // Calculate how fast we should be moving
         var targetVelocity = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
         targetVelocity = transform.TransformDirection(targetVelocity);
         targetVelocity *= speed;
  
         // Apply a force that attempts to reach our target velocity
         var velocity = rigidbody.velocity;
         var velocityChange = (targetVelocity - velocity);
         velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange);
         velocityChange.z = Mathf.Clamp(velocityChange.z, -maxVelocityChange, maxVelocityChange);
         velocityChange.y = 0;
         rigidbody.AddForce(velocityChange, ForceMode.VelocityChange);
  
         // Jump
         if (canJump && Input.GetButton("Jump"))
         {
             rigidbody.velocity = Vector3(velocity.x, CalculateJumpVerticalSpeed(), velocity.z);
         }
     }
  
     // We apply gravity manually for more tuning control
     rigidbody.AddForce(Vector3 (0, -gravity * rigidbody.mass, 0));
  
     grounded = false;
 }
  
 function OnCollisionStay ()
 {
     grounded = true;    
 }
  
 function CalculateJumpVerticalSpeed ()
 {
     // From the jump height and gravity we deduce the upwards speed 
     // for the character to reach at the apex.
     return Mathf.Sqrt(2 * jumpHeight * gravity);
 }


Comment
Add comment · Show 5 · 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 faye921 · Feb 06, 2013 at 01:57 PM 0
Share

I think I roughly understand I am using the PlatformController script and tried applying this but when I do the character can't move the running animation will play but he can't jump either, I can't paste all of the PlatformController script here as it won't fit but I basically changed the bottom of it // Require a character controller to be attached to the same game object @script RequireComponent (Rigidbody) @script AddComponent$$anonymous$$enu ("2D Platformer/Platformer Controller") (Rigidbody originally being CharacterController) Hopefully you know of the script I mean (was originally from that 2D gameplay tutorial with Lerpz)

Thank you for your help sorry for all the questions. (I would paste the code but its about 360 lines)

avatar image aldonaletto · Feb 06, 2013 at 10:04 PM 0
Share

The script above is for a first person character, and can't substitute the PlatformController. I'll check the PlatformController and return soon.

avatar image faye921 · Feb 07, 2013 at 06:58 PM 0
Share

I think what I actually need is a mesh collider to work within the script not a box collider (although a box collider would work fine)I've tried this but it still doesn't work... heres the platform script (i havent edited this version)link text

platformcon.txt (11.4 kB)
avatar image aldonaletto · Feb 09, 2013 at 12:19 PM 0
Share

@faye921, the PlatformController is very complex - modifying it may result in weird collateral effects.
In your case, I suggest to use a CharacterController with radius = height/2: the collider size may be adjusted to cover the character length (tail to nose) or height. Both cases impose limitations, of course, but any character in real games uses a simplified collider (like a capsule): mesh colliders are too expensive!

avatar image faye921 · Feb 09, 2013 at 06:40 PM 0
Share

Yeah I think I'll just have to make the controller a bit taller, thanks for the help anyway.

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

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Collision between Character Controller and Box Collider 2 Answers

Non Capsule Character Controller? 1 Answer

My character controller falls through a box collider 2 Answers

Not colliding with a box collider? 2 Answers

Flying object when I put the Character Controller 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