Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 sbalaniqf · Aug 16, 2015 at 08:24 AM · begginerperpendicular

Finding the normal/perpendicular

So i've seen a bunch of questions similar to this, but much more complicated and i've not been able to discern the answer, so i'm asking again.

I'm not very experienced so simpler is better:).

Basically i'm trying to make a tennis game, but for now i'm just trying to make a wall return the ball to me. I've managed to make it do that by hard coding the return vector:

 void OnCollisionEnter(Collision collision) {
         GameObject ball = collision.gameObject;
         ball.GetComponent<Rigidbody>().velocity = new Vector3(0,8,-8);
     }
 

What i'm trying to do now, is if I change the angle of the collider, the ball should bounce perpendicular to the wall. Because the vector is hard coded, regardless of where the ball is facing the ball bounces back the same.

I've tried using Vector3.cross to try to dynamically get the perpendicular vector (then I can add force to maniuplate how strongly it comes back), but my problem is, I dont now how to get the two sides of the walls as vectors.

Comment
Add comment · Show 2
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 16, 2015 at 09:01 AM 0
Share

You can use Vector3.Reflect. Note that the Collision class also includes an array of hits, each one of which has a normal variable that returns the normal vector3 of the hit triangle.

avatar image Glurth · Aug 16, 2015 at 02:37 PM 1
Share

I think Cherno's suggestion will be the most practical way to get what you are looking for. But wanted to answer this question....

I dont now how to get the two sides of the walls as vectors.

I'm going to make a couple of assumptions: without rotation, the wall faces the screen directly: in other words- it is defined in model-space as lying on the XZ plane. In THIS default orientation, the vectors for 2 wall sides are(1,0,0) and (0,0,1).

Now that we have the two vectors, in model space, we need to orient them appropriately in worldspace.
wall.transform.roatation will give the orientation of the wall in worlspace.
We can multiply this rotation Quaternion by our wall-side-vector in modelspace, to get the wall-side-vector in worldspace.

 Vector3 verticalSide= wall.transform.roatation * Vector3(1,0,0);  //order matters in transform arithmatic)
 Vector3 horizSide= wall.transform.roatation * Vector3(0,0,1);  

As you noted, the cross product of these two vetors will be the normal of the wall. Note: you could also compute or note(0,1,0) the normal in model space, and rotate just that one vector.

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

A object and another object has keep perpendicular. 1 Answer

Quest Tips `n` Tricks 0 Answers

Best overloded method match for CS1502 2 Answers

Having trouble increasing the spawning speed of explosions 0 Answers

Getting perpendicular direction vector from surface normal 2 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