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 P4r4d0x · May 19, 2013 at 03:07 PM · charactercontrollernoobwalls

CharacterController going trought walls.

First of all, I need to say that I´m new to Unity. I created a "map" in blender and imported it to Unity as a .blend file, after it a CharacterController was created, w/ a camera and "walking and looking" scripts. Everythings works fine and smoothly but my character keep going trough the walls of the map. I´ve tried using RigidBody, every kind of "---"Collider but the CharacterController keep going trough. Sorry for asking something that must be very basic for all of you, but I couldn´t find any solution on the WEB. Please help =)

Comment
Add comment · Show 5
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 ExTheSea · May 19, 2013 at 03:43 PM 0
Share

Is there a collider on the wall and if is make sure it's not a trigger?

Also how are you moving your character controller? With the standard charactermotor or a custom script?

avatar image ExTheSea · May 20, 2013 at 12:42 PM 0
Share

Well if you're using the Character Controller you should make sure you use charactercontroller.move to move the CC http://docs.unity3d.com/Documentation/ScriptReference/CharacterController.$$anonymous$$ove.html . Also make sure the wall has a collider.

avatar image P4r4d0x · May 20, 2013 at 09:05 PM 0
Share

The wall has: -$$anonymous$$esh Collider -Rigid Body


I´m moving my CharacterController with a custom script =)

avatar image ExTheSea · May 21, 2013 at 04:11 PM 0
Share

In that custom script: Do you move the player using something like:

transform.position +=.......;

or do you use something like:

charactercontroller.$$anonymous$$ove(...);

?

Only the last option will let the player react to collision so making him not go through walls.

avatar image P4r4d0x · May 21, 2013 at 05:32 PM 0
Share

Oh thanks a lot! I´ll try to use "charactercontroller.$$anonymous$$ove();" The custom script that I was using: #pragma strict

function Start () {

}

function Update () { if (Input.Get$$anonymous$$ey("w")){ transform.Translate(0,0,1);} if (Input.Get$$anonymous$$ey("s")){ transform.Translate(0,0,-1);} if (Input.Get$$anonymous$$ey("a")){ transform.Translate(-1,0,0);} if (Input.Get$$anonymous$$ey("d")){ transform.Translate(1,0,0);} }

2 Replies

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

Answer by ExTheSea · May 21, 2013 at 05:40 PM

Ok so after looking at your script i can asure you that your problems come from transform.Translate. When you use transform.Translate or something like transform.position .... your transform will ignore collisions.

The basic rule for movement with collision-recognition is: If it's a CharacterController use CharactorController.Move or something equal and if it's a rigidbody use rigidbody.AddForce or something equal.

I'm gonna convert my comment to an answer because i'm certain that it will work and if you still have a problem with your script then please just go ahead and ask.

I had a little time left so i converted your movement script to use CharacterController.Move();

 var GameobjectwithCharacterController : Gameobject;
 var controller : CharacterController;
 function Start () {
 controller= GameobjectwithCharacterController.transform.GetComponent(CharacterController)
 }
 
 function Update () {
  if (Input.GetKey("w")){ controller.Move(Vector3.forward);}
  if (Input.GetKey("s")){ controller.Move(-Vector3.forward);}
  if (Input.GetKey("a")){ controller.Move(-Vector3.right);}
  if (Input.GetKey("d")){ controller.Move(Vector3.right);}
 }

Warning: Code is untested.

Also you should change the variable name for the gameobject or use somthing like transform, transform.root or transform.parent.

PS: When it comes to CharacterController-Movement I would always recommend the FPSWalkerEnhanced: http://wiki.unity3d.com/index.php?title=FPSWalkerEnhanced

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 P4r4d0x · May 22, 2013 at 05:26 PM 0
Share

It worked man ^^ Your script helped me a lot! And the best of all: you explained everything. Now I understand, very interesting =) Thank you very much indeed.

avatar image ExTheSea · May 22, 2013 at 05:54 PM 0
Share

I'm glad it worked. Could you now please accept the answer using the tick below the thumbs up/down buttons to mark the question as solved.

Good luck with your project :)

avatar image
0

Answer by GamezAtWork · May 20, 2013 at 05:01 AM

Is the normals in blender pointed in the right direction? I had that problem once until I inverted some of the normals...

If not, perhaps you could create "invisible" wall colliders?

Comment
Add comment · Show 3 · 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 ExTheSea · May 20, 2013 at 12:41 PM 0
Share

Was it really the thing with the normals that helped you when you had the problem because the normals don't have anything to do with the character controller. I would guess you did something else too.

avatar image Wesley Kam · May 20, 2013 at 03:34 PM 0
Share

Well, the normals dictate whether there is collision, from the last I recall.

Went to do a doublecheck as well, created a vertical plane and walked my charactercontroller through both sides. You can't go through from the visible side, but you can walk through the invisible side.

Of course, we have to check on his side first.

avatar image ExTheSea · May 20, 2013 at 03:42 PM 0
Share

So you're talking about a mesh collider right? In that case maybe it's dependent on normals but i would recommend not to use mesh collider if possible. For example if your' making a wall i would just attach a box collider to it. $$anonymous$$akes the collision faster.

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

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

Related Questions

I need Ready Characters. Help me !!! 1 Answer

First Person Character Controls, How? 1 Answer

Passing through walls. 2d toolkit 1 Answer

Cloud recognition in Vuforia 0 Answers

General Unity 2D Character/Environment Control Questions 2 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