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 Mexallon · May 11, 2013 at 10:29 PM · c#collisionnormals

Normals not perpendicular to surface?!

Hello, this is my first question here in this community. I've already searched for my problem for a while and the documentation for unity wasnt that helpful (again).

Ok here's my Problem. I'm trying around with unity and programmed a little script that lets balls bounce of walls. The balls got a rigidbody and the walls got a box collider each. I've tested everything that came into my mind (for about 4hours now) but the normals seem not perpendicular to the walls on the top and the left. If I increase the velocity of a ball the bending gets even worse. It always ends up the balls just bouncing in 180° of a wall.

May the problem be that iam setting the velocity within the OnCollisionEnter event? dunno

Here's the Code I'm using. I hope you guys can help me out I'm kind of depressed right now :

     void OnCollisionEnter(Collision c){
         if(c.gameObject.name=="GameWall"){
             Debug.DrawRay(c.contacts[0].point, c.contacts[0].normal, Color.red, 6);
             Vector3 inDirection = gameObject.transform.forward;
             Vector3 inNormal = c.contacts[0].normal;
             Vector3 outDirection = Vector3.Reflect(gameObject.transform.forward, inNormal) * speed;
             gameObject.rigidbody.velocity = outDirection;
             lastNormal = inNormal;
             lastCollisionPosition = c.contacts[0].point;
             gameObject.transform.LookAt(gameObject.transform.position + gameObject.rigidbody.velocity);
        }
     }

alt text

(visualized via Debug.DrawRay(c.contacts[0].point, c.contacts[0].normal, Color.red, 6)

normals.png (344.8 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by sparkzbarca · May 12, 2013 at 03:21 AM

dont go with "seem" check.

Debug.DrawRay(c.contacts[0].point, c.contacts[0].normal,Colors.red,5)

or something like that. basically draw a debug ray and make sure you have debug button enabled in gameplay view of editor so you can see the widgets.

I think your problem is the contacts.normal is a local normal not a global normal and you need to use transform.TransformDirection to make the local normals be properly oriented because the indirection of transform.forward is global and the normal is local.

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 Mexallon · May 12, 2013 at 10:36 AM 0
Share

Hey there. Thanks for the answer. Ok "seem" may not be the correct word. They are wrong, I am already using Debug.DrawLine in the update function with "lastNormal" variable. Though I don't think its a problem of local or world space. The normals look just fine on most of my gamewalls, everything works just as expected, it seems to depend on the "GameWall" prefeb itself. I've already deleted, rotated, repositioned the walls and everything nothing changed.

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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Object following a path and colliding with other objects with physics. 1 Answer

Any way to ignore collision between rigidbodies and colliders/character controllers? 1 Answer

How do I both align my character with the normals of a slope AND rotate him in the direction of movement? 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