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 bassguitarist48 · Nov 14, 2012 at 07:48 PM · collisioncharacter

Character Collision Issue

I created my own, simple movement script in Unity. However, collision does not seem to be working. The cube this script it applied to has a box collider and so do the objects I want it to collide with. The cube just passes right through though. Thoughts?

 var moveSpeed:float = 1;
 
 function Update () {
 var h = Input.GetAxis("Horizontal") * moveSpeed * Time.deltaTime;
 var v = Input.GetAxis("Vertical") * moveSpeed * Time.deltaTime;
 
 transform.position += transform.TransformDirection(Vector3(h,0,v));
 }
Comment
Add comment · Show 2
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 bassguitarist48 · Nov 14, 2012 at 08:17 PM 0
Share

Adding a Rigidbody Component to the cube works. However, I don't want it to be a rigidbody. Is there some really simple thing I'm overlooking???

avatar image whydoidoit · Nov 14, 2012 at 09:16 PM 0
Share

Check out this tutorial on Unity Gems - basically make your rigidbody kinematic or if you are using a character controller then move it with Simple$$anonymous$$ove

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by kromenak · Nov 14, 2012 at 11:57 PM

LONG EXPLANATION

An important thing to realize is that a "collider" in Unity is nothing more than a coded description of an area in 3D space. For example, there is nothing explicitly solid about a box collider; it is just a position vector and a size vector that can be taken to represent a box of a certain size at a certain position in the 3D world.

You'll notice in your code above that you are simply updating transform.position in response input. Nothing in your code is checking to see if a collider is in the way and responding appropriately. In fact, the code required to check for colliders and respond appropriately can be split into collision handling and physics code, both of which are fairly complicated and probably not things you'd want to code yourself - they could potentially be huge chunks of code!

Most likely, you are expecting Unity to handle collisions for you, but the only way it can do that is if you are using a Rigidbody or a Character Controller. A Rigidbody will give you both collision and physics functionality, while a character controller seems to mainly be collision detection. Both these components do the work of detecting colliders in the environment and disallowing movement when there is a collision.

SHORT ANSWER

You can use CharacterController.Move to move while also taking collisions into account. When you call Move, the Character Controller will attempt to move if there is space, or stop moving if there is a collider in the way.

If you use a Rigidbody with Kinematic turned on, you'll get collisions and physics when things hit, but you will still be able to move through static colliders - probably not what you are looking for.

Comment
Add comment · 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

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

11 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 avatar image

Related Questions

My character jumps occationally when against a wall? 2 Answers

collision problem - only one sided (plane-like object) 2 Answers

Cubes wont Collide 1 Answer

Make the character move a certain direction on collision 2 Answers

Problems When Shooting Multiple Enemies round about 4 times 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