- Home /
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
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
Your answer
![](https://koobas.hobune.stream/wayback/20220612150410im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
2D Raycast not working 1 Answer
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