2D Platformer Shooting - Raycast Issue
I am having trouble shooting a ray from a Child object of the Player, in a direction for a certain distance. What keeps happening is, the ray shoots from the player, but it goes to a predetermined point. So I could be moving and facing right, and if I pass the predetermined point, the ray shoots left. Always to the exact same point, and the point it's shooting to is different for every direction. This is the code I have for when the player is facing right.
if (faceDir == faceDirection.Right) {
Vector2 firePointPosition = new Vector2(firePoint.position.x, firePoint.position.y);
RaycastHit2D hit = Physics2D.Raycast (firePointPosition, transform.right, 10, whatToHit);
Debug.DrawLine (firePointPosition, aimingPosition*10, Color.cyan);
if (hit.collider != null) {
Debug.Log ("Test");
Debug.DrawLine (firePointPosition, hit.point, Color.red);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612064928im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Enemy is shooting the opposite direction of player 1 Answer
Select from multiple character to move 0 Answers
One 2D Raycast Not Stopping Even Though Others Do? 0 Answers
How to Raycast 2D Diagonally instead of Horizontal on a Platformer game. 0 Answers
Need help making a ledge climber. The problem, transform.position always returns to vector( 0, 0) 0 Answers