Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by xanta · Aug 26, 2016 at 12:22 PM · vector3object position

how can i determine the back of object?

i want to make something like a backstab, it means when i am behind some object, i can deal more damage. any help would be appreciated

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 2dt · Aug 26, 2016 at 01:07 PM 0
Share

$$anonymous$$y answer wasn't totaly correct so i redo it : If your enemy and your player are looking in the same direction and your player hit the enemy, then he must be in his back. You can so do the project of the two forward (Vector3.Project(enemy.transform.forward, player.transform.forward), and what interest us is the z value: if it is 1, the player and the enemy are strictly looking in the same direction. if it > 0.5f, they are looking at the same direction with a margin of 45° if it is 0, they are looking in perpendicular directions if it is -1, the are looking in opposite directions.

So you can do something like : if(Vector3.Project(enemy.transform.forward, player.transform.forward).z>0.3f) CriticalHit();

avatar image xanta 2dt · Aug 26, 2016 at 01:32 PM 0
Share

thanks a lot. let me try it and ill give a feedback

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by ScaniX · Aug 26, 2016 at 01:13 PM

If "other" is the enemy gameObject, you can calculate the angle between the enemies forward vector and the delta vector. Comparing just the both forward vectors would not actually say anything about your position relative to the enemy. You will have the same angle if you are standing right in front of or behind the enemy.

 Vector3 delta = transform.position - other.transform.position;
 Vector3 angle = Vector3.Angle(other.transform.forward, delta);
 float backstabbiness = Mathf.Abs(angle) / 180f; // Mathf.Abs() is probably not necessary

The closer the angle gets to 180° the closer you are to be directly behind him. A backstabbiness value of > 0.7f should take him out instantly. ;)

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 TheYumma · May 18, 2017 at 06:06 PM 0
Share

thanks I'm still experimenting with what you posted since I have an Isometric view.

Just change the Vector3 angle to float angle

avatar image
0

Answer by DavidWatts · Aug 26, 2016 at 01:16 PM

you can take the dot product between the enemies forward vector and a position in space. if the dot product is greater than 0 then the position is in front and if its less than 0 then its behind.

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

7 People are following this question.

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

Related Questions

Find distance from camera perpendicularly to targets transform.right. 1 Answer

How can I create vector fields for use with the new VFX Graph? 3 Answers

Hey everyone, can someone help me to get the vertices and triangles in my Curve meshes? Every time I try I get "isReadable = false" 1 Answer

Get Face/Triangle size in world space from RaycastHit 0 Answers

Substitute transform.rotation + slerp with transform.rotate and Vector3 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