I’m having a few issues with the following script. When I try to run it, I get the compiler errors CS1513 and CS1002 at 19,20 (which is Raycast Hit out) as said in the title. I’ve tried putting them in wherever I can and have not been able to find a fix. As far as me and AI are concerned, there should be no issues. Any help would be appreciated.
P.S. It’s not an issue with rb.AddForce as that worked before when I put otherObject.transform.position instead of hit.point.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public Rigidbody rb;
public GameObject otherObject;
void Start()
{
rb = GetComponent<Rigidbody>();
}
public void ApplyForce()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit out;
if (Physics.Raycast(ray, out hit))
{
Vector3 otherPosition = hit.point;
Vector3 direction = otherPosition - transform.position;
rb.AddForce(direction * -1000f);
}
}
}
Neither you nor the AI counts. Only what the compiler says counts.
The complete error message contains everything you need to know to fix the error yourself.
The important parts of the error message are:
the description of the error itself (google this; you are NEVER the first one!)
the file it occurred in (critical!)
the line number and character position (the two numbers in parentheses)
also possibly useful is the stack trace (all the lines of text in the lower console window)
Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.
Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly?
All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.
Remember: NOBODY here memorizes error codes. That’s not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.
You sometimes have to tell the AI that there is a problem in order for it to find the problem. That said I handed the script to ChatGPT’s free tier (GPT-3.5) and it pointed out that there was an error in it without prompting. Here’s its response.
I wonder when they ban ChatGPT here. It’s banned in Stack Overflow. Because the definition of AI is that it can successfully mislead people (Turing test), hence AI is a liar by definition.
So, in this case, ChatGPT misled you into believing that your code is valid. Had you asked the compiler, he would have spoken the truth.