Error: BCE:0019:'AddSkidMark" is not a member of 'Object'.

I’ve been steadily converting the Unity car script to work for mobile and I am down to 2 errors. Can someone tell me why I am getting the error below? Thanks

			//create skid marks				
			if(slip>0.75  skidmarks != null)
				w.lastSkidMark=skidmarks.AddSkidMark(hit.point,hit.normal,(slip-0.75)*2,w.lastSkidMark);
			else
				w.lastSkidMark=-1;
		}
		else w.lastSkidMark=-1;
	}
	totalSlip/=wheels.length;
}

It doesn’t know what class the object “skidmarks” is of, so it’s assuming the common base “Object”.

Wherever it is that you’re assigning “skidmarks” in the first place you need to make sure that the type is “SkidMarks” (or whatever the appropriate class is, can’t tell from what you’ve posted) and that you’re casting to that type.

If you post up the code where you make the variable skidmarks and assign to it we can probably help you fix it. :slight_smile:

@angrypengui - here’s the full code
It was part of a buggy car I bought from Asset Store.

//maximal corner and braking acceleration capabilities
var maxCornerAccel=10.0;
var maxBrakeAccel=10.0;

//Mass
var mass = 1500;

//coefficient of drag
var drag = 0.05;

//center of gravity height - effects tilting in corners
var cogY = 0.0;

//engine powerband
var minRPM = 700;
var maxRPM = 6000;

//maximum Engine Torque
var maxTorque = 400;

//automatic transmission shift points
var shiftDownRPM = 2500;
var shiftUpRPM = 5500;

//gear ratios
var gearRatios = [-2.66, 2.66, 1.78, 1.30, 1.00];
var finalDriveRatio = 3.4;

//a basic handling modifier:
//1.0 understeer
//0.0 oversteer
var handlingTendency = 0.7;

//graphical wheel objects
var wheelFR : Transform;
var wheelFL : Transform;
var wheelBR : Transform;
var wheelBL : Transform;

//suspension setup
var suspensionDistance = 0.3;
var springs = 1000;
var dampers = 200;
var wheelRadius = 0.45;


private var queryUserInput = true;
private var engineRPM : float;
private var steerVelo = 0.0;
private var brake = 0.0;
private var handbrake = 0.0;
private var steer = 0.0;
private var motor = 0.0;
private var skidTime = 0.0;
private var onGround = false;
private var cornerSlip = 0.0;
private var driveSlip = 0.0;
private var wheelRPM : float;
private var gear = 1;
private var skidmarks;
private var wheels : WheelData[];
private var wheelY = 0.0;

//Functions to be used by external scripts 
//controlling the car if required
//===================================================================

//return a status string for the vehicle
function GetStatus(gui : GUIText) {
	gui.text="v="+(rigidbody.velocity.magnitude * 3.6).ToString("f1") + " km/h\ngear= "+gear+"\nrpm= "+engineRPM.ToString("f0");
}

//return an information string for the vehicle
function GetControlString(gui : GUIText) {
	gui.text="Use arrow keys to control the jeep,\nspace for handbrake.";
}

//Setup main camera to follow vehicle
function SetupCamera() {
	if(Camera.main.GetComponent(SmoothFollow)!=null)
	{
		Camera.main.GetComponent(SmoothFollow).enabled=true;
		Camera.main.GetComponent(SmoothFollow).target=transform;
		Camera.main.GetComponent(SmoothFollow).distance=7;
		Camera.main.GetComponent(SmoothFollow).height=3;
	}
	Camera.main.transform.parent=null;
}

//Enable or disable user controls
function SetEnableUserInput(enableInput)
{
	queryUserInput=enableInput;
}

//Car physics
//===================================================================

//some whee calculation data
class WheelData{
	var rotation = 0.0;
	var coll : WheelCollider;
	var graphic : Transform;
	var maxSteerAngle = 0.0;
	var lastSkidMark = -1;
	var powered = false;
	var handbraked = false;
	var originalRotation;
};

function Start () {
	//Destroy existing rigidbody, we don't want anyone to mess with it.
	if(rigidbody)
		Destroy(rigidbody);
	
	//setup rigidbody	
	gameObject.AddComponent(Rigidbody);
	rigidbody.mass = mass;
	rigidbody.drag = drag;
	rigidbody.angularDrag = 0.8;
	rigidbody.centerOfMass.y = cogY;
	rigidbody.interpolation = RigidbodyInterpolation.Interpolate;

	//start engine noise
	audio.loop = true;
	audio.Play();

	//setup wheels
    wheels=new WheelData[4];
	for(var i=0;i<4;i++)
		wheels[i] = new WheelData();
		
	wheels[0].graphic = wheelFL;
	wheels[1].graphic = wheelFR;
	wheels[2].graphic = wheelBL;
	wheels[3].graphic = wheelBR;

	wheels[0].maxSteerAngle=30.0;
	wheels[1].maxSteerAngle=30.0;
	wheels[2].powered=true;
	wheels[3].powered=true;
	wheels[2].handbraked=true;
	wheels[3].handbraked=true;

	for(w in wheels)
	{
		if(w.graphic==null)
			Debug.Log("You need to assign all four wheels for the car script!");
		if(!w.graphic.transform.IsChildOf(transform))	
			Debug.Log("Wheels need to be children of the Object with the car script");
			
		w.originalRotation=w.graphic.localRotation;

		//create collider
		var colliderObject = new GameObject("WheelCollider");
		colliderObject.transform.parent = transform;
		colliderObject.transform.localPosition = w.graphic.localPosition;
		w.coll = colliderObject.AddComponent(WheelCollider);
		w.coll.suspensionDistance = suspensionDistance;
		w.coll.suspensionSpring.spring = springs;
		w.coll.suspensionSpring.damper = dampers;
		//no grip, as we simulate handling ourselves
		w.coll.forwardFriction.stiffness = 0;
		w.coll.sidewaysFriction.stiffness = 0;
		w.coll.radius = wheelRadius;
	}	

	//get wheel height (height forces are applied on)
	wheelY=wheels[0].graphic.localPosition.y;
	
	//find skidmark object
	skidmarks = FindObjectOfType(typeof(Skidmarks));
	
	//shift to first
	gear=1;
}

//update wheel status
function UpdateWheels()
{
	//calculate handbrake slip for traction gfx
 	var handbrakeSlip=handbrake*rigidbody.velocity.magnitude*0.1;
	if(handbrakeSlip>1)
		handbrakeSlip=1;
		
	var totalSlip=0.0;
	onGround=false;
	for(var w in wheels)
	{		
		//rotate wheel
		w.rotation += wheelRPM / 60.0 * 360.0* Time.fixedDeltaTime;
		w.rotation = Mathf.Repeat(w.rotation, 360.0);		
		w.graphic.localRotation = Quaternion.Euler( w.rotation, w.maxSteerAngle*steer, 0.0 ) * w.originalRotation;

		//check if wheel is on ground
		if(w.coll.isGrounded)
			onGround=true;
			
		var slip = cornerSlip+(w.powered?driveSlip:0.0)+(w.handbraked?handbrakeSlip:0.0);
		totalSlip += slip;
		
		var hit : WheelHit;
		var c : WheelCollider;
		c = w.coll;
		if(c.GetGroundHit(hit))
		{
			//if the wheel touches the ground, adjust graphical wheel position to reflect springs
			w.graphic.localPosition.y-=Vector3.Dot(w.graphic.position-hit.point,transform.up)-w.coll.radius;
			
			
			//create skid marks				
			if(slip>0.75  skidmarks != null)
				w.lastSkidMark=skidmarks.AddSkidMark(hit.point,hit.normal,(slip-0.75)*2,w.lastSkidMark);
			else
				w.lastSkidMark=-1;
		}
		else w.lastSkidMark=-1;
	}
	totalSlip/=wheels.length;
}

//Automatically shift gears
function AutomaticTransmission()
{
	if(gear>0)
	{
		if(engineRPM>shiftUpRPM&gear<gearRatios.length-1)
			gear++;
		if(engineRPM<shiftDownRPM&gear>1)
			gear--;
	}
}

//Calculate engine acceleration force for current RPM and trottle
function CalcEngine() : float
{
	//no engine when braking
	if(brake+handbrake>0.1)
		motor=0.0;
	
	//if car is airborne, just rev engine
	if(!onGround)
	{
		engineRPM += (motor-0.3)*25000.0*Time.deltaTime;
		engineRPM = Mathf.Clamp(engineRPM,minRPM,maxRPM);
		return 0.0;
	}
	else
	{
		AutomaticTransmission();
		engineRPM=wheelRPM*gearRatios[gear]*finalDriveRatio;
		if(engineRPM<minRPM)
			engineRPM=minRPM;
		if(engineRPM<maxRPM)
		{
			//fake a basic torque curve
			var x = (2*(engineRPM/maxRPM)-1);
			var torqueCurve = 0.5*(-x*x+2);
			var torqueToForceRatio = gearRatios[gear]*finalDriveRatio/wheelRadius;
			return motor*maxTorque*torqueCurve*torqueToForceRatio;
		}
		else
			//rpm delimiter
			return 0.0;
	}
}

//Car physics
//The physics of this car are really a trial-and-error based extension of 
//basic "Asteriods" physics -- so you will get a pretty arcade-like feel.
//This may or may not be what you want, for a more physical approach research
//the wheel colliders
function HandlePhysics () {
	var velo=rigidbody.velocity;
	var wheelRPM=velo.magnitude*60.0*0.5;

	rigidbody.angularVelocity=new Vector3(rigidbody.angularVelocity.x,0.0,rigidbody.angularVelocity.z);
	var dir=transform.TransformDirection(Vector3.forward);
	var flatDir=Vector3.Normalize(new Vector3(dir.x,0,dir.z));
	var flatVelo=new Vector3(velo.x,0,velo.z);
	var rev=Mathf.Sign(Vector3.Dot(flatVelo,flatDir));
	//when moving backwards or standing and brake is pressed, switch to reverse
	if((rev<0||flatVelo.sqrMagnitude<0.5)&brake>0.1)
		gear=0;
	if(gear==0)
	{	
		//when in reverse, flip brake and gas
		var tmp=brake;
		brake=motor;
		motor=tmp;
		
		//when moving forward or standing and gas is pressed, switch to drive
		if((rev>0||flatVelo.sqrMagnitude<0.5)&brake>0.1)
			gear=1;
	}
	var engineForce=flatDir*CalcEngine();
	var totalbrake=brake+handbrake*0.5;
	if(totalbrake>1.0)totalbrake=1.0;
	var brakeForce=-flatVelo.normalized*totalbrake*rigidbody.mass*maxBrakeAccel;

	flatDir*=flatVelo.magnitude;
	flatDir=Quaternion.AngleAxis(steer*30.0,Vector3.up)*flatDir;
	flatDir*=rev;
	var diff=(flatVelo-flatDir).magnitude;
	var cornerAccel=maxCornerAccel;
	if(cornerAccel>diff)cornerAccel=diff;
	var cornerForce=-(flatVelo-flatDir).normalized*cornerAccel*rigidbody.mass;
	cornerSlip=Mathf.Pow(cornerAccel/maxCornerAccel,3);
	
	rigidbody.AddForceAtPosition(brakeForce+engineForce+cornerForce,transform.position+transform.up*wheelY);
	
	var handbrakeFactor=1+handbrake*4;
	if(rev<0)
		handbrakeFactor=1;
	var veloSteer=((15/(2*velo.magnitude+1))+1)*handbrakeFactor;
	var steerGrip=(1-handlingTendency*cornerSlip);
	if(rev*steer*steerVelo<0)
		steerGrip=1;
	var maxRotSteer=2*Time.fixedDeltaTime*handbrakeFactor*steerGrip;
	var fVelo=velo.magnitude;
	var veloFactor=fVelo<1.0?fVelo:Mathf.Pow(velo.magnitude,0.3);
	var steerVeloInput=rev*steer*veloFactor*0.5*Time.fixedDeltaTime*handbrakeFactor;
	if(velo.magnitude<0.1)
		steerVeloInput=0;
	if(steerVeloInput>steerVelo)
	{
		steerVelo+=0.02*Time.fixedDeltaTime*veloSteer;
		if(steerVeloInput<steerVelo)
			steerVelo=steerVeloInput;
	}
	else
	{
		steerVelo-=0.02*Time.fixedDeltaTime*veloSteer;
		if(steerVeloInput>steerVelo)
			steerVelo=steerVeloInput;
	}
	steerVelo=Mathf.Clamp(steerVelo,-maxRotSteer,maxRotSteer);	
	transform.Rotate(Vector3.up*steerVelo*57.295788);
}

function FixedUpdate () {
	//query input axes if necessarry
	if(queryUserInput)
	{
		brake = Mathf.Clamp01(-Input.GetAxis("Vertical"));
		handbrake = Input.GetButton("Jump")?1.0:0.0;
		steer = Input.GetAxis("Horizontal");
	 	motor = Mathf.Clamp01(Input.GetAxis("Vertical"));
 	}
	else
	{
		motor = 0;
		steer = 0;
		brake = 0;
		handbrake = 0;
	}


	//if car is on ground calculate handling, otherwise just rev the engine
 	if(onGround)
		HandlePhysics();
	else
		CalcEngine();	
		
	//wheel GFX
	UpdateWheels();

	//engine sounds
	audio.pitch=0.5+0.2*motor+0.8*engineRPM/maxRPM;
	audio.volume=0.5+0.8*motor+0.2*engineRPM/maxRPM;
}


@script RequireComponent (AudioSource)

Oh right, JavaScript. I think that if you change line 60 to…

private var skidmarks : Skidmarks;

… you might be ok. I usually stick to C# though. You might also need to specify the type on line 72.

@angrypengui - it worked just perfectly! The last error I have is this one.

Assets/Buggy Vehicle/Scripts/Car.js(193,102): BCE0051: Operator ‘*’ cannot be used with a left hand side of type ‘UnityEngine.Quaternion’ and a right hand side of type ‘Object’.

Again it works fine if I am in PC/MAC mode, but as soon as I switch it to iOS. I get those two errors. One you already fixed and thanks again for the help.

 w.graphic.localRotation = Quaternion.Euler( w.rotation, w.maxSteerAngle*steer, 0.0 ) * w.originalRotation;

It’s in this function:

function UpdateWheels()
{
	//calculate handbrake slip for traction gfx
 	var handbrakeSlip=handbrake*rigidbody.velocity.magnitude*0.1;
	if(handbrakeSlip>1)
		handbrakeSlip=1;
		
	var totalSlip=0.0;
	onGround=false;
	for(w in wheels)
	{		
		//rotate wheel
		w.rotation += wheelRPM / 60.0 * 360.0* Time.fixedDeltaTime;
		w.rotation = Mathf.Repeat(w.rotation, 360.0);		
		w.graphic.localRotation = Quaternion.Euler( w.rotation, w.maxSteerAngle*steer, 0.0 ) * w.originalRotation;

		//check if wheel is on ground
		if(w.coll.isGrounded)
			onGround=true;
			
		var slip = cornerSlip+(w.powered?driveSlip:0.0)+(w.handbraked?handbrakeSlip:0.0);
		totalSlip += slip;
		
		var hit : WheelHit;
		var c : WheelCollider;
		c = w.coll;
		if(c.GetGroundHit(hit))
		{
			//if the wheel touches the ground, adjust graphical wheel position to reflect springs
			w.graphic.localPosition.y-=Vector3.Dot(w.graphic.position-hit.point,transform.up)-w.coll.radius;
			
			
			//create skid marks				
			if(slip>0.75  skidmarks != null)
				w.lastSkidMark=skidmarks.AddSkidMark(hit.point,hit.normal,(slip-0.75)*2,w.lastSkidMark);
			else
				w.lastSkidMark=-1;
		}
		else w.lastSkidMark=-1;
	}
	totalSlip/=wheels.length;
}

Well, if you read the error message it’s the same thing again. It doesn’t know what the thing on the right of the ‘’ operator is, so it’s assuming it’s an ‘Object’, and you can’t use '’ on an Object. Find out what it should be, and tell it.

SO for(w in wheels) should be

for(var w in wheels)

I noticed iOS does not like when “var” is missing from these for loops. I have no clue what I’m talking about… just an observation. Seems like it does not like the w.originalRotation, but originalRotation is a variable declared at the top. Any help angrypenguin would be most appreciated. I still have to add the iOS controls to the above code. I think I can manage that, but one thing at a time.

I wish there were a car controller for iPhone. Non on the asset store :frowning:

Add

#pragma strict

to the top of all your JavaScript files. It should help point out these things :slight_smile:

Unity’s variant of JavaScript is not quite the one known from web scripts. Be specific about data types and you’ll both get faster code and fewer errors.

Hi also I got it working with the help of you guys. To be honest I cheated I comment out *w.originalRotation;. It sucks, but I can move the car around my scene. If you could help me further I’d appreciate it. If not, thanks for all the assist.

You need to be stricter about defining datatypes. The “for(w in…” part has no indication what w is, which is why you get that error. Either define w on a line before the loop, or make it:

for(var w : WheelData in wheels)
  ...