• 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
Question by henry96 · Jan 10, 2012 at 03:43 PM · physicsrigidbodywallwalls

Rigidbody (Player) goes through wall

I have a game that player is the cube. That cube moves around like 2D side scrolling game. The cube has a rigidbody and box collider to it. When the player moves toward the wall, and touch the wall, a bit later, the player suddenly goes through the wall. I have searched this site for the solution that have written before, but what I found doesn't match my condition.

Here is my control script (shortcut) :

 transform.Translate (Vector3(Input.GetAxis ("Horizontal") * Time.deltaTime *speed,0,0),Space.World);

Here is the link to the game if you want to see the problem more clearly.

http://www.kongregate.com/games/vitou01/cube-land

Thanks in advance.

Edit :

my wall has box collider.

Comment
MNVOH

People who like this

1 Show 6
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 Muzz5 · Jan 10, 2012 at 03:45 PM 0
Share

Does your wall have a collider? Rigidbodies anywhere?

avatar image swisscoder · Jan 10, 2012 at 05:20 PM 0
Share

actually I tried your game, but never have a case where your cube goes entirely through the wall..

avatar image swisscoder · Jan 10, 2012 at 05:26 PM 0
Share

actually I found a spot.... the pushed red button below opens the first falling down block, gives me the possibility to go through the wall where the button is.

avatar image swisscoder · Jan 10, 2012 at 05:26 PM 1
Share

by the way nice idea to make those puzzles depending on the cube's color.

avatar image henry96 · Jan 11, 2012 at 05:31 AM 0
Share

@swisscoder : It goes through almost every wall. If you hold the arrow key for a long time, you will see the cube goes through the wall easily. And thx for the compliment. :D

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Oninji · Jan 10, 2012 at 05:42 PM

Transform does not call the Physic components of your rigidbody, thus it ignores all physic. Colliders are physic component, for your code to include them you must move your objects using it's rigidbody physics.

http://unity3d.com/support/documentation/ScriptReference/Rigidbody.html

ie: When I do an AI that need to have perfectly controlled movement, I manage the Velocity of the rigidbody through code.

Depending on what you want to do and your ease with physics, you may want to use the Character Controller, it's essentially a rigidbody with simplified functions to be controlled as a Character.

http://unity3d.com/support/documentation/ScriptReference/30_search.html?q=character+controller

Comment
henry96
MNVOH

People who like this

2 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 henry96 · Jan 11, 2012 at 05:41 AM 0
Share

I have tried changing the velocity of the rigidbody before. It works great. No more going through wall. However, I have trouble with control. While the cube is falling, and the button is pressed, the cube hardly want to fall. It keeps going left/right.

Here is my code I used before :

rigidbody.velocity = Vector3 (Input.GetAxis ("Horizontal") Time.deltaTime speed , 0 , 0);

Do you know how to fix this?

avatar image Oninji · Jan 11, 2012 at 06:01 AM 1
Share

It's simple, the way you currently control it. You set Y and Z velocity at 0 constantly. Z being the vertical orientation, it won't fall.

Do something like rigidbody.velocity.x = Input.GetAxis("Horizontal")*Time.deltaTime*speed;

But as I stated before, if you're not entirely sure how a rigidbody works, use a CharacterController, it's the same but a bit simplified. Unless you need extremely specific controls that are unachievable with it in some RARE cases.

avatar image henry96 · Jan 11, 2012 at 06:15 AM 0
Share

Horray!!!!!! Now the problem is solved! Thanks for your help! :D

avatar image

Answer by swisscoder · Jan 10, 2012 at 05:14 PM

If you would add the CharacterController component to the cube, you could call it's Move method. Maybe works better. http://unity3d.com/support/documentation/ScriptReference/CharacterController.Move.html

I see your camera isn't really smooth too. (Maybe you could use the methods Slerp/Lerp of Vector3, to make things smoother.)

Comment
henry96

People who like this

1 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 henry96 · Jan 11, 2012 at 05:51 AM 0
Share

I try the character controller. There is no more going through wall, which is a good thing. However, my cube lost its realistic. There is no more rotating.

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.

Update about the future of Unity Answers

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta later in June. Please note, we are aiming to set Unity Answers to read-only mode on the 31st of May in order to prepare for the final data migration.

For more information, please read our full announcement.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

ANSWER DETERMINED (CAN'T DELETE) 1 Answer

Player keeps bouncing off the walls 2 Answers

Collision.collider returns wrong object 1 Answer

Composite body physics 2 Answers

OnCollisionEnter problem 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