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 woodoo · Dec 10, 2014 at 04:50 AM · collisionvector3directionvector

Vector direction after collision

I'm trying to make a "hook" with some given direction and length.

Until that, okay, i get the direction from my mouse click position:

 Vector3 direction = Camera.main.ScreenToWorldPoint(Input.mousePosition);

And I need to move the "hook" head from my position to the "end" position:

 Vector3 end = direction * length;

Now, i need to add some functionality to it, which is, when the "hook" head collides with a wall (and it still has some length available), i get the resulting direction of that collision (that's what i need), multiply it to the remaining length and i have my updated end point.

I tried to do that with the Vector3.Cross(..), passing as parameters the Vector3.up and the hook current direction.

I'm not getting the result that i need, here are some examples of the direction i want:

alt text

Thanks in advance.

examples.png (13.0 kB)
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 woodoo · Dec 10, 2014 at 04:56 AM 0
Share

I found an article about that, actually i need to do some math with the "dot" function and the "wall" normal vector..

avatar image ajk48n · Dec 10, 2014 at 05:34 AM 0
Share

This page should give a good description of how to get your angle as well.

http://answers.unity3d.com/questions/317648/angle-between-two-vectors.html

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Dec 10, 2014 at 08:26 AM

Actually all you need to calculate the reflected vector is the surface normal vector (which you get from a raycast) and the Vector3.Reflect method.

ps: ScreenToWorldPoint takes the distance from the camera as z component. If you pass a Vector2 / mouse position the z value will default to 0. If you use a perspective camera that means it will always return the camera's position since at 0 distance all points meet at the same point. See the example on the documentation page. They use the cameras' near plane value. Also keep in mind that you will get a position, not a direction.

If you actually plan to do a raycast along that direction you might want to use ScreenPointToRay instead. It returns a ray that has it's origin at the camera position and a direction that points where you had your mouse position.

Comment
Add comment · 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

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

27 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 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

Slerp look at direction not working... 3 Answers

Units merge into each other with pathfinding 1 Answer

C# Raycast from Object direction (z-axis) + another Vector3 1 Answer

How to know from which direction there is a collision with an object? in C# 1 Answer

Can't change vector direction 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