- Home /
help don't know whats wrong
i started following a tutorial for a car game but it is in js and i am converting it to c# but i ran into a problem here is the code
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class AICar : MonoBehaviour {
List<Transform> path;
public Transform pathGroup;
public float maxSteer = 150.0f;
public WheelCollider wheelFL;
public WheelCollider wheelFR;
private Vector3 steerVector;
public int currentPathObject;
private float newSteer;
// Use this for initialization
void Start () {
GetPath();
}
void GetPath(){
Transform[] path_objs;
path_objs = pathGroup.GetComponentsInChildren<Transform>();
path = new List<Transform>();
foreach (Transform path_obj in path_objs) {
if(path_obj != pathGroup) {
path.Add( path_obj );
}
}
}
// Update is called once per frame
void Update () {
GetSteer();
}
void GetSteer () {
steerVector = transform.InverseTransformPoint(Vector3(path[currentPathObject].position.x, transform.position.y, path[currentPathObject].position.z)); // this line is causing the problems.
newSteer = maxSteer * (steerVector.x / steerVector.magnitude);
wheelFL.steerAngle = newSteer;
wheelFR.steerAngle = newSteer;
}
}
the errors are as follows
Assets/Scripts/AI Scripts/AICar.cs(38,63): error CS0119: Expression denotes a type', where a
variable', value' or
method group' was expected
Assets/Scripts/AI Scripts/AICar.cs(38,41): error CS1502: The best overloaded method match for UnityEngine.Transform.InverseTransformPoint(UnityEngine.Vector3)' has some invalid arguments Assets/Scripts/AI Scripts/AICar.cs(38,41): error CS1503: Argument
#1' cannot convert object' expression to type
UnityEngine.Vector3'
any help is appreciated.
Answer by RudyTheDev · Jan 05, 2014 at 08:12 PM
In C#, you have to use new Vector3(...
not Vector3(...
to make a new instance of something.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How can I get a character to patrol and follow terrain? 1 Answer
Health not being subtracked. 1 Answer
AI in unity, need help 1 Answer