• 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 Tylor · Mar 02, 2011 at 11:27 PM · glitchwallx-axis

Collision error for the x axis

Ok so im making a 2D/3D platforming game, Im just working through concepts right now and the top and bottom of my level have correct collision however i can just phase through walls of the x axis. Any edge of a block on the x axis is walk throughable. Ive never seen this happen. Can someone help please?

edit (moved from comment)
I am using Translate

if (Input.GetKey("d")) {
    transform.Translate(-Vector3.left * speed * Time.deltaTime);
}
if (Input.GetKey("a")) {
    transform.Translate(-Vector3.right * speed * Time.deltaTime); 
}

Comment
Add comment · 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 by0log1c · Mar 02, 2011 at 11:36 PM 1
Share

what about the z-axis? Does every GameObject have Colliders/CharacterControllers? NOT set to trigger? Are you using .Translate to move the character(no collision detection)? Is the character or the wall extremely thin and/or moving extremely fast. Collision detection set to 'Continuous?' for a try?

It seems pretty odd that only the x-axis is affected and not the z nor y. I'd like to make sure you double-checked everything else first :)

avatar image Joshua · Mar 02, 2011 at 11:41 PM 0
Share

Agree with BY0LOG1C, it seems odd. Have you also checked that your character has a non-kinematic rigidbody?

avatar image Tylor · Mar 03, 2011 at 12:04 AM 0
Share

Everything has collisions, No triggers are set, However i am using Translate,

if (Input.Get$$anonymous$$ey("d")) { transform.Translate(-Vector3.left speed Time.deltaTime); } if (Input.Get$$anonymous$$ey("a")) { transform.Translate(-Vector3.right speed Time.deltaTime);

which I feel is incorrect by what you have said.

avatar image Tylor · Mar 03, 2011 at 12:46 AM 0
Share

What other movement method is there?

avatar image Bunny83 · Mar 03, 2011 at 01:12 AM 0
Share

I guess you have no problems with the z-axis because it's a 2D platform game and you move only along the x-axis (and y of course), right?

Show more comments

1 Reply

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

Answer by Bunny83 · Mar 03, 2011 at 01:04 AM

Well if you use a CharacterController use the Move method of this one. If you don't use the CharacterController you need at least a kinematic Rigidbody at your object or there will be no collision detection at all.


edit
To restrict movement of a rigidbody to x and y (clamp z to 0) just correct the position every frame. You can do multiple movements in one frame so this can be seperated from the actual movement:

rigidbody.MovePosition(new Vector3(0,0,-transform.position.z));

This will move the object back to z == 0 whenever it would move in z direction.

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 Tylor · Mar 03, 2011 at 01:27 AM 0
Share

I saw that but it that is for 3D movement, I need something that would only allow x axis movement.

avatar image Bunny83 · Mar 03, 2011 at 02:10 AM 0
Share

It will be always 3D since Unity3D is a 3D game engine. Physx which cares for collision and collision responde also works in a 3D environment and will always be 3D. You can just ignore physics and do your own collision checks with raycasts but you will loose the realistic looking physics since you have to take care about everything yourself. The better way is to use physics and restrict the movement yourself.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Passing through wall 1 Answer

Prevent cube from going inside walls? 2 Answers

Quickly spinning player glitches through walls 2 Answers

Why does this happen,Why does this happen every time I open Unity 0 Answers

I cannot see everything in my inspector and Unity will not let me add more than one transition from any animation at any given time 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