The problem that I am having is that I want to calculate the angle between my raycasts origin (the player) and the hit.point. I want my player to shoot a ray which is always at 0 degrees regardless where they stand in worldspace but this isn’t happening (as shown above).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ProjectileReflection : MonoBehaviour {
public int maxReflectionCount = 5;
public float maxStepDistance = 200;
private float angle = 0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnDrawGizmos()
{
DrawPredictedReflectionPattern (this.transform.position + this.transform.forward * 0.75f, this.transform.forward, maxReflectionCount);
}
void DrawPredictedReflectionPattern(Vector3 position, Vector3 direction, int reflectionsRemaining)
{
if (reflectionsRemaining == 0)
return;
Vector3 startingPosition = position;
Ray ray = new Ray (position, direction);
RaycastHit hit;
if (Physics.Raycast (ray, out hit, maxStepDistance))
{
direction = Vector3.Reflect (direction, hit.normal);
position = hit.point;
angle = Vector3.Angle (startingPosition, position);
print (angle);
}
else
{
position += direction * maxStepDistance;
}
Gizmos.color = Color.yellow;
Gizmos.DrawLine (startingPosition , position);
DrawPredictedReflectionPattern (position, direction, reflectionsRemaining - 1);
}
}
This is the reflection script I got. I want to check the angle of the origin of the ray (which I want to always be 0) + the angle of the hit.point (position).