Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 segahogzombie · Aug 04, 2015 at 08:21 PM · prefabplayerclipping

Why is my player clipping through walls?

Hey I'm trouble with my player clipping though walls!

Problem : My player clips though walls but also has no physics even when rigidbody attached!

Maybe Solution : I have my player stuck on one layer of Y axis so i assume i strict something to prevent it!

Image of gameplay : alt text

You can see that the Player is clipped through the wall (No he doesnt have a spawn issue) But you need more screenshots or a video of the stuff i did comment below!

P.S -I want the script returned of the solution you made not just tell me the problem because im very new to unity 5 and i first join on unity 4 which i had a major gap between trying unity out!

Please be sure to make it in #c but if you cant make it into javascript which is kind of hard for me use.

Here is the script!

using UnityEngine; using System.Collections;

public class Move : MonoBehaviour { bool facingRight; // Use this for initialization void Start () {

  }
  
  // Update is called once per frame
  void Update () {
      if (Input.GetKeyDown (KeyCode.A)) {
          transform.right = new Vector3(-1, 0, 0);
          facingRight = false;
      }
      else if (Input.GetKeyDown (KeyCode.D)) {
          transform.right = new Vector3(1, 0, 0);
          facingRight = true;
      }
      float translate = Input.GetAxis("Horizontal");
      
      if(!facingRight)
          transform.Translate (Vector3.right * -translate * 5 * Time.deltaTime);
      else
          transform.Translate (Vector3.right * translate * 5 * Time.deltaTime);
  }

}

capture.png (306.8 kB)
Comment
Add comment · Show 3
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 Cherno · Aug 04, 2015 at 08:51 PM 0
Share

Okay, first of all: What are these lines:

 transform.right = new Vector3(-1, 0, 0);


supposed to do? You can't just set the transform.right vector, it's only meant to be read so you get a direction vector perpendicular to transform.forward, etc.

Now about your problem. Your actor has a rigidbody; Does he have the right one? If you have a 3D environment, he needs a normal RB. If it's a 2D environment, he needs a RigidBody2D. The RB also may not be set to Is$$anonymous$$inematic = true. The actor also needs a suitable collider (BoxCollider or BoxColider2D, for example). The collider may not be set to IsTrigger = true. Similarly, the walls needs the right colliders too; Box Collider or BoxCollider2D, respectively (just an example). The wall colliders also may not be set to IsTrigger = true. Finally, The layers of both the actor and the wall objects need to be able to interact; this is set under Edit->ProjectSettings->Physics or Physics2D.

avatar image maccabbe · Aug 05, 2015 at 12:44 AM 0
Share

transform.right=new Vector3(-1, 0, 0); does set the direction Vector (albeit poorly since it can rotate freely among that axis). So assu$$anonymous$$g your collider is symmetrical it shouldn't be causing a problem.

$$anonymous$$ost likely the problem that you are using transform.Translate ins$$anonymous$$d of rigidbody.$$anonymous$$ovePosition. If you want objects to collide you should use rigidbody.$$anonymous$$ovePosition.

avatar image zach-r-d · Aug 05, 2015 at 12:55 AM 0
Share

Is the rigidbody kinematic? $$anonymous$$inematic rigidbodies ignore collisions when moving.

Also, please remember to use the "101010" button to format your code.

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Spawning Player After Player Choice. 1 Answer

Move Player to new scene without it resetting. 1 Answer

What to set to make a Instantiated prefab a collider to trigger and event? 1 Answer

Player object carried from scene to scene 1 Answer

Instantiate a prefab and follow player position in runtime? 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