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 B-R-J · Jan 13, 2018 at 07:49 AM · raycastingraycasthit2dtransform.forward

Using Raycasts along object axis

I am implementing a simple wind blower which blows wind on mouse click on the object. I used Physics.Raycast to detect the object along the wind path. Debug.draw was used to see how the lines are drawn and test. The script is as follows.

 public class BlowingScript : MonoBehaviour {
     
     // Update is called once per frame
     void Update () {
         if(Input.GetMouseButton(0)){
 
             RaycastHit2D hit = Physics2D.Raycast (Camera.main.ScreenToWorldPoint(Input.mousePosition),Vector2.zero);
             if (hit.collider != null) {
                 if (hit.collider.CompareTag ("blower")) {
                     Debug.Log ("pressed");
                     Vector2 pos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
                     transform.position = pos;
         Debug.DrawLine (transform.position ,Vector3.up , new Color(255f,0f,0f));        // a red line
         Debug.DrawLine (transform.position ,transform.forward ,new Color(0f,255f,0f) ); //a green line
 
                 }
             }
 
         }
     }
 }

But in Run mode, the debug lines are like this alt text

what I want to do is to send the ray/line along the transform's axis (red arrow). But none of the lines are doing it How should my script change? Any comments on the problem, are highly valued.

untitled.png (26.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
Best Answer

Answer by W01Fi3 · Jan 13, 2018 at 08:05 AM

Try using Debug.DrawRay rather than DrawLine?

https://docs.unity3d.com/ScriptReference/Debug.DrawRay.html

Comment
Add comment · Show 2 · 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 W01Fi3 · Jan 13, 2018 at 08:07 AM 0
Share

Either that, or use transform.right, since transform.right is the red arrow. Transform.forward is the blue arrow

avatar image B-R-J · Jan 13, 2018 at 05:19 PM 0
Share

Yeah that was the case ! Thank you so much for helping @Wolf402 .

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

77 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

Related Questions

2D Raycast not working 1 Answer

How do I create a wide beam thats visible to the player and is stopped by barriers in my 2D stealth game? 0 Answers

Problem with custom raycast2D collision detection system. 1 Answer

Removing 2D objects on touch using Raycasting? 0 Answers

How to control multiple gradients 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