Hi everyone, i’m trying to adapt the part from the ‘2d roguelike’ tutorial series about raycast/linecast collision detection from its initial 2D sprites to 3D.
I am unfortunately getting the following error:
error CS0029: Cannot implicitly convert type `bool' to `UnityEngine.RaycastHit'
This is the extract of code i am using (even though i cut out the irrelevant parts concerning the issue):
using UnityEngine;
using System.Collections;
public abstract class Movement : MonoBehaviour
{
public LayerMask blockingLayer;
private BoxCollider boxCollider;
private Rigidbody rigidB;
protected virtual void Start ()
{
boxCollider = GetComponent<BoxCollider>();
rigidB = GetComponent<Rigidbody>();
}
protected bool Move (int xDir, int yDir, int zDir, out RaycastHit hit)
{
Vector3 startPos = transform.position;
Vector3 endPos = startPos + new Vector3(xDir, yDir, zDir);
boxCollider.enabled = false;
hit = Physics.Linecast(startPos, endPos, blockingLayer);
boxCollider.enabled = true;
if (hit.transform == null)
{
StartCoroutine(SmoothMove(endPos));
return true;
}
return false;
}
Basically, from the original tutorial, i changed/skipped the 2D parts for the 3D equivalents.
I switched Vector2 to Vector3 and added the int for another axis.
I replaced the error free (i think at least)
out RaycastHit2D hit
with
out RaycastHit hit
and
hit = Physics2D.Linecast
with
hit = Physics.Linecast
Anyways, im new to Unity3D, CSharp, and the Forum too. I tried all day to figure out the reason for the error but with no success. Sorry if i might be a bit derpy concerning the issue, so please be gentle ;p
Help in trying to fix the error in code and or eliminating my misunderstandings of the concept are greatly appreciated.