Need Raycast2d to point where my ship is looking
making a 2d go around gamealt text I need a raycast2d to always point where the ship is pointing. The problem is that it always points to the right, left, up or down but not where my ship is pointing.
public float Velocity = 20;
public LayerMask wathtoHit;
public float maxRayDistance = 25;
void Update()
{
if(Input.GetKey("a")){
transform.RotateAround(Vector3.zero, Vector3.back, Velocity * Time.deltaTime);
}
if(Input.GetKey("d")){
transform.RotateAround(Vector3.zero, Vector3.forward, Velocity * Time.deltaTime);
}
if(Input.GetButton("Fire1")){
print("shot");
}
//this is where its called the function saying to position of the ray on the ship and where to point the ray
raycast(transform.position, Vector2.***!WheredoIPoint?!***);
}
void raycast(Vector2 origin, Vector2 direction){
//Ray2D ray = new Ray2D(transform.position, transform.position);
RaycastHit2D hit = Physics2D.Raycast(origin, direction, maxRayDistance, wathtoHit);
Debug.DrawLine(origin, direction + Vector2.up * maxRayDistance, Color.red);
if(hit.collider != null){
print("hit something" + hit.collider.name);
}
}
reference.png
(12.8 kB)
Comment
Your answer
Follow this Question
Related Questions
Need a Raycast2d to point where my ship is looking 0 Answers
Some questions about 2d games in unity 2 Answers
Checking for Raycast distances not working as expected. 0 Answers
Feild of view only wokring in specific areas of the scene 0 Answers
C# 2D Top down game how to detect if objects are touching while they can pass through each other? 1 Answer