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 LeetRooster · Jul 21, 2013 at 02:50 AM · 2dcollisioncharactercontrollerwalls

Passing through walls. 2d toolkit

Sorry for asking another question about this topic. There seem to be many and from what I've looked through and tried I haven't got the results I've wanted yet.

I've created a few sprites on screen with 2d toolkit. I want one box to act as a wall and be impassable to the player. Instead the player passes right through it. Am I taking the right approach here? Or will this not work at all. I've seen some people talking about using rays and calculating collisions themselves to support this. But this just seems a little overkill and I expected more basic Unity features to handle this.

I've created a script, where I move the player's characterController in Update (If I'm not mistake it belongs here rather than FixedUpdate. FixedUpdate is used if your applying forces to move the rigidbody. Correct me if I am wrong.).

The way I thought to do it was to make the wall sprite: - A static collider (BoxCollider) - no rigidbody

The player has: -a CharacterController(its collider) - a rigidbody with no gravity. isKinematic is unchecked.

 using UnityEngine;
 using System.Collections;
 
 
 public class Controls : MonoBehaviour {
 
     public int xSpeed = 32;
     public int ySpeed = 32;
     protected CharacterController control;
     
     // Use this for initialization
     void Start () {
         control = GetComponent<CharacterController>();
         if (control == null) {
             Debug.LogError("No character controller set for '" + name + "'");
         }
     }
     
     
     // Update is called once per frame
     void Update () {
         float xTrans = Input.GetAxisRaw("Horizontal") * xSpeed;
         float yTrans = Input.GetAxisRaw("Vertical")  * ySpeed;
         xTrans *= Time.deltaTime;
         yTrans *= Time.deltaTime;
         Vector3 move = new Vector3(xTrans, yTrans, 0);
         control.Move(move);
     }
 }
 
Comment
Add comment · Show 1
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 LeetRooster · Jul 21, 2013 at 03:43 AM 0
Share

Solved, by default there is no Z depth on sprites that come out of 2d toolkit. You need to turn this on.

Found a "silent film" explaining this

http://www.youtube.com/watch?v=29zU5jz4S8w

1 Reply

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

Answer by LeetRooster · Jul 21, 2013 at 04:33 AM

Solved, by default there is no Z depth on sprites that come out of 2d toolkit. You need to turn this on.

Found a "silent film" explaining this

http://www.youtube.com/watch?v=29zU5jz4S8w

However, it turns out you shouldn't use the character controller for a lot of 2d use cases (platformers for example). Since it requires that you also use a capsule collider when you often will want a box collider.

http://forum.unity3d.com/threads/75327-Changing-character-Controller-to-a-box-collider

I did my movements using forces on the rigidbody and managed to keep a box collider working. One other issue that seems to be important is to make sure that you add a good amount of z size to the colliders. I was keeping all my colliers with a z size of 1. With a z size of 1 I was often passing through my walls. I made them a bit larger (32, which gave me sprite cubes of 32x32x32) and they seem to be working better. I'm just wondering if unity isn't super great at handling small box sizes with collisions.

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

15 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

Related Questions

2D game, going through walls 1 Answer

Collision with obstacles while constant moving forward 1 Answer

Unity 4.3 CharacterController collision with physics 2D not working 1 Answer

CharacterController "breaks" collision, goes haywire 2 Answers

Wall collision problems!! 3 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