#unity3d #c#-4.0 #raycasting
#unity3d #c #-4.0 #raycasting
Вопрос:
Как это могло произойти? Я уже несколько раз переписывал код Raycast, но вот текущая итерация:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RaycastTest : MonoBehaviour {
//width will control the distance of the two rays' direction from each other
//range will control the collision range
public float width, range;
//will take width and control bias in the furture
float b;
void Start()
{
}
void Update () {
//loop from negative one to positive one to add left and right rays in the future
for (int i = -1; i < 3; i = 2)
{
//commented line segment showing how bias will work to control the angle of the ray
//! cant do any of that yet because this ray doesn't work
Ray ray = new Ray(transform.position, /*(transform.forward transform.right/2 * i) / 3*/ transform.forward);
RaycastHit hitInfo;
if (Physics.Raycast(ray.origin, ray.direction, out hitInfo, range))
{
Debug.DrawLine(ray.origin, hitInfo.point, Color.red);
}
else
{
Debug.DrawLine(ray.origin, ray.direction * range, Color.green);
}
}
}
}
Проблема, вероятно, либо в строке 24, либо в 27, но я до сих пор понятия не имею, как это происходит.
РЕДАКТИРОВАТЬ: я проверил это, установив для направления луча значение константы: (-1, 0, 0) (глобальный левый), и проблема не устранена, так что, вероятно, проблема с объявлением луча в строке 24.
Ответ №1:
Я забыл добавить преобразование в debug.drawline в else