Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 /
This question was closed Mar 27 at 11:13 AM by scorpionassassin for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by scorpionassassin · Oct 28, 2021 at 05:07 PM · vector3screen

damage direction

how can i make damage direction like this if get hit from front show image1,if hit right show image2?

 public Image direction;
 
 void update(){
      Vector3 targetPos = target.transform.position;
      Vector3 screenpos = Camera.main.WorldToScreenPoint(targetPos);
 ...
 }
Comment
Add comment · Show 3
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 bdubbert · Oct 28, 2021 at 10:16 PM 0
Share

How are you "hitting" something? Raycasts? Collisions? Tell me what a "hit" is and I can tell you how you can tell what direction it came from

avatar image scorpionassassin bdubbert · Oct 29, 2021 at 12:39 PM 0
Share

with collision.only show Four directions image. like this link text

avatar image MSavioti · Oct 29, 2021 at 03:34 AM 0
Share

If I understood it right, you want to show a certain Image if the hit came from something in front of you that is being shown on camera and another image if the hit came from somewhere not shown on your camera. Is this right?

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by bdubbert · Oct 29, 2021 at 08:08 PM

First find the point of contact - for example

 Raycast:
 if(Physics.Raycast(..., out hit, ...){hitPoint = hit.Point;}
 
 Collision
 void OnCollisionEnter(Collision col){ hitPoint = col.GetContact(0); }
 

Then find the direction between your player and the hit point

 Vector3 direction = hitPoint - player.transform.position;

Then figure out which direction most matches the direction to your hit point

 float frontDot = Vector3.Dot(direction, player.transform.forward);
 float rightDot = Vector3.Dot(direction, player.transform.right);
 
 if(Mathf.Abs(frontDot ) > Mathf.Abs(rightDot )){
     if(frontDot > 0) ShowFrontCollisionImage();
     else ShowBackCollisionImage();
 } else{
     if (rightDot > 0) ShowRightCollisionImage();
     else ShowLeftCollisionImage();
 }

Then just right up the code to show the correct image from those functions

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

Follow this Question

Answers Answers and Comments

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

Slow WorldToScreenPoint () 0 Answers

Angle between 2 GameObjects and center of screen 2 Answers

Is it possible to keep the same Vector3 value using ScreenToWorldPoint with the camera moving? 0 Answers

how to drop an object when the object is set in Camera.main.ScreenToWorldPoint 0 Answers

A better script for a machine gun? 1 Answer


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