微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

即使光线沿矢量方向起作用,光线投射目标也不会与父对象一起移动

如何解决即使光线沿矢量方向起作用,光线投射目标也不会与父对象一起移动

Object facing left at the center of the scene,with the raycast cast with ray of transform.position,transform.forward

Object facing left at the edge of the scene with the same ray,ray still casts to the same point even though the point is being called as a direction

这怎么可能发生?我已经重写了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行的Ray声明的问题。

解决方法

我忘了在else中将转换添加到debug.drawline

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。