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 Aslan · Apr 21, 2011 at 09:12 AM · collisioncollidercharactercontrollerlocomotion

Deform Charater controler Collider acording to stance

I've been messing around with character controller and it's colliders

The idea is to deform the collision on the character when the characters changes stance (i.e stand, crouch, Prone etc.)

I've tried adding different colliders to the characters bones. but the character also makes use locomotion, so the rays casted from locomotion starts clashing with the colliders.

I've also tried scripting to the character controller to change size when the character changes stance, but with no results.

Any suggestion is appreciated. :)

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
1
Best Answer

Answer by Cyb3rManiak · Apr 21, 2011 at 12:55 PM

I don't know if it will play well with locomotion or not, but I've tried it, and scripting the character controller collider DOES work... At least changing the height and center of the collider.

I created a small example project, but can't upload it here, so if you need it send me your email using a private message or something.

The code attached to my character controller:

using UnityEngine; using System.Collections;

public class Crouch : MonoBehaviour { public Transform tHead;

 private Vector3             _v3InitialPosition;
 private Vector3             _v3CrouchingPosition;
 private CharacterController _characterController;
 private float               _fInitialControllerHeight;
 private float               _fCrouchingControllerHeight;
 private Vector3             _v3InitialControllerCenter;
 private Vector3             _v3CrouchingControllerCenter;

 void Start()
 {
     _v3InitialPosition = tHead.localPosition;
     _v3CrouchingPosition = _v3InitialPosition + Vector3.down;
     _characterController = GetComponent(typeof(CharacterController)) as CharacterController;
     _fInitialControllerHeight = _characterController.height;
     _fCrouchingControllerHeight = _fInitialControllerHeight - 1f;
     _v3InitialControllerCenter = _characterController.center;
     _v3CrouchingControllerCenter = _v3InitialControllerCenter + Vector3.down * 0.5f;
 }

 void Update () 
 {
     if (Input.GetKeyDown(KeyCode.Space))
     {
         tHead.localPosition = _v3CrouchingPosition;
         _characterController.height = _fCrouchingControllerHeight;
         _characterController.center = _v3CrouchingControllerCenter;
     }

     if (Input.GetKeyUp(KeyCode.Space))
     {
         tHead.localPosition = _v3InitialPosition;
         _characterController.height = _fInitialControllerHeight;
         _characterController.center = _v3InitialControllerCenter;
     }
 }

}

Comment
Add comment · Show 1 · 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 Aslan · Apr 23, 2011 at 08:19 AM 0
Share

Thanks your answer, i've tried this now and it's works, but when ever i apply it my character ended up falling throw the floor.

But I don't need this function any more as i started adding Collision boxes as Triggers ins$$anonymous$$d(and shrinking the Character controller) which solved most of the problems i had with the Colliders.

Thanks anyways.

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

OnCollisionEnter does not work 4 Answers

OnCollisionEnter Push Object Problem 0 Answers

Collision CharacterController vs CharacterController 2 Answers

Generated Terrain not colliding! HALP. 0 Answers

Making Colliders/Triggers or Rigidbodies move a Character Controller 5 Answers


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