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 Tekksin · Dec 30, 2013 at 05:22 PM · 2dcollisionissuewalls

Wall collision problems!!

I am having some serious problems with the way my character controls. I have a custom code that isn't complex at all, so it's not the character controller preset. Anyways, whenever the player hits a wall, it kinda vibrates against it, trying again and again to go through it. I'd rather the player run into the wall, and just be forced to stop moving.

I tried writing something in the OnCollisionEnter function about when the player hits the wall to reduce the speed to 0, but then the player cant move. I even set it up so that if the character hits it and the speed is dropped to zero, that when the player turns around, it can accelerate in the turned-around direction.

Does anybody have some techniques to make a character whose collision isn't done through ray casting, but rather all just collision boxes, STOP colliding strangely with walls? I'll link you to a video to show what is happening.

http://www.youtube.com/watch?v=pcSJFEiOyYE

Also, here is my code:

 private var done = false;
 var spawnPoint : Transform;
 var speed : int = 5;
 var jumpSpeed: float = 8;
 var isgrounded : boolean = true;
 var isRight : boolean = true;
 var LevelComplete : boolean;
 var canMove: boolean = true;
 
 function Start () {
 }
 
 function Update () {
     Movement();
     textureChanges();
 }
 
 function Movement (){
 if(!LevelComplete){        
     Camera.main.transform.position = new Vector3(transform.position.x, 1, transform.position.z + 30);
 
     if(canMove){
 //        if(Input.GetAxis("Horizontal")){
 //            transform.Translate(Vector3(Input.GetAxis("Horizontal") * speed * Time.deltaTime, 0, 0));
 //        }
         var colliderBox = gameObject.GetComponent(BoxCollider); //controlls collider box size
         var AT = gameObject.GetComponent(AnimateTexture); //Store AnimateTexture Script
         
         if(Input.GetKey("a")){ //Player moves left
                 AT.rowNumber = 1;
                 transform.Translate(Vector2.right * speed * Time.deltaTime);
                 isRight = false;
             } else if(Input.GetKey("d")){
                 AT.rowNumber = 1;
                 transform.Translate(-Vector2.right * speed * Time.deltaTime);
                 isRight = true;
             } else { //Player is not moving
                 AT.rowNumber = 0; //Change to idle animation!
             }    
         if(isgrounded == true){
             if(Input.GetKeyDown("space")){
                 AT.rowNumber = 3; //Player jumping animation
                 rigidbody.velocity += Vector3.up * jumpSpeed;
                 Physics.gravity = Vector3(0, -85, 0);
             }
         }
         if(isgrounded == false){
                 colliderBox.center = Vector3(0.03, -0.08, 0);
                 colliderBox.size = Vector3(.5, .7, .5);
             }
             else if(Input.GetKey("s")){
             AT.rowNumber = 4; //Player squats down
             colliderBox.center = Vector3(0.03, -0.39, 0);
             colliderBox.size = Vector3(0.44, 0.18, 1);
         }    
             else {
         colliderBox.center = Vector3(0.03, -0.2965, 0);
         colliderBox.size = Vector3(0.44, 0.37, 1);
         }
     }
 }
     
 }

Any suggestions?? This jagged hitting crap is so annoying, and I have no idea why the character is registering as on the ground when it's clearly not (allowing more jumps to happen). sigh.

I AM NOT USING A CHARACTER CONTROLLER!!!!! Also, yes, I have tried changing the physics material on the walls. Nothing works..

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 Spinnernicholas · Dec 30, 2013 at 05:26 PM 0
Share

I believe the CharacterController script has fields to fix this. Read into the CharacterController again.

avatar image Tekksin · Dec 30, 2013 at 05:28 PM 0
Share

I'm not using the character controller though. I specifically noted that this has nothing to do with it. I'll look at it again, but seriously, it's so unrelentingly complicated that I have no idea what I'm looking at.

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Remludar · May 30, 2015 at 11:31 AM

Put the movement code in FixedUpdate()

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 SkrillexNukehulk · Dec 18, 2016 at 09:00 PM 0
Share

Thank you so much, I know this topic is old, but this fixed my problem!

avatar image
-1

Answer by Tekksin · Dec 30, 2013 at 06:29 PM

oh crap, sorry the video was private lol, I changed the setting, you all should be able to see it now. And yes, it's 2D...

Anyways, I'd rather understand exactly what's happening with my character, instead of relying on some taxing preset that barely does what I need it to.

Thanks for the down vote for me being honest, btw. Real mature. edit: I wrote a code that stops the jittering from happening. And it doesn't involve the evil character controller.

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

Answer by Spinnernicholas · Dec 30, 2013 at 05:28 PM

Use the CharacterController provided by Unity. It has controls to handle collision jitter.

[OLD] In the CharacterController, Min Move Distance and Skin width have to do with collision jitter.

Comment
Add comment · Show 7 · 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 Tekksin · Dec 30, 2013 at 05:31 PM 0
Share

so you're saying reference what that script says about skin width? because I'm not using the character controller.

edit: just searched for the word "skin" in all the javascript files in the character controller assets, and couldn't find anything =_=

edit again: I found this in one of the scripts.. Is it something I should look into? it's admittedly very confusing. I'm not a coding master or anything.

 function OnControllerColliderHit (hit : ControllerColliderHit) {
     if (hit.normal.y > 0 && hit.normal.y > groundNormal.y && hit.moveDirection.y < 0) {
         if ((hit.point - movement.lastHitPoint).sqr$$anonymous$$agnitude > 0.001 || lastGroundNormal == Vector3.zero)
             groundNormal = hit.normal;
         else
             groundNormal = lastGroundNormal;
         
         movingPlatform.hitPlatform = hit.collider.transform;
         movement.hitPoint = hit.point;
         movement.frameVelocity = Vector3.zero;
     }
 }
avatar image Tekksin · Dec 30, 2013 at 05:43 PM 0
Share

honestly, I have no idea how to pick that apart and use it. at all. :|||||||||

avatar image Spinnernicholas · Dec 30, 2013 at 06:10 PM 0
Share

Lol, sorry, I thought you were using the CharacterController, i didn't really look at your code. You should consider using the CharacterController. It is a script provided by Unity to handle exactly what you are trying to do. It's in the components menu in the menubar. You can either use it as a starting point, or you can create another script to interact with it.

avatar image Spinnernicholas · Dec 30, 2013 at 06:11 PM 0
Share

And, it is a great example of really well built code.

avatar image Tekksin · Dec 30, 2013 at 06:14 PM 0
Share

I know all about it. There's a reason I'm not using it. I wanted a custom collision. I wrote my own script to have a box collider ins$$anonymous$$d of the annoying pill one. The pill made the character not feel like a traditional 2D one. But this jittery wall crap is really limiting my design set up.

Show more comments

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

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

Related Questions

Multiple Cars not working 1 Answer

2D game, going through walls 1 Answer

Passing through walls. 2d toolkit 1 Answer

How to change the color of the ball after hitting square? 5 Answers

Unity2D Collision is bugged 0 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