Please Help

Updated on January 3, 2018 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on January 2, 2018

I am doing the online multiplayer fps tutorial episode 5 flying/jumping but my character controller script is outdated i think because it gives me multiple errors and i cant play it because it tells me to fix the compiler errors. I used the one from the tutorial but the tutorial was made 2 years ago. Here Are my scripts i was hoping you could help me fix them

 

PlayerController

 

using UnityEngine;

 

[RequireComponent(typeof(ConfigurableJoint))]
[RequireComponent(typeof(PlayerMotor))]
public class PlayerController : MonoBehaviour {

 

[SerializeField]
private float speed = 5f;
[SerializeField]
private float lookSensitivity = 3f;

 

[SerializeField]
private float thrusterForce = 1000f;

 

[Header(“Spring settings:”)]
[SerializeField]
private JointDriveMode jointMode = JointDriveMode.Position;
[SerializeField]
private float jointSpring = 20f;
[SerializeField]
private float jointMaxForce = 40f;

 

private PlayerMotor motor;
private ConfigurableJoint joint;

 

void Start()
{
motor = GetComponent();
joint = GetComponent();

 

SetJointSettings(jointSpring);
}

 

void Update()

 

{
//Calculate movement velocity as a 3D vector
float _xMov = Input.GetAxisRaw(“Horizontal”);
float _zMov = Input.GetAxisRaw(“Vertical”);

 

Vector3 _movHorizontal = transform.right * _xMov;
Vector3 _movVertical = transform.forward * _zMov;

 

// Final movement vector
Vector3 _velocity = (_movHorizontal + _movVertical).normalized * speed;

 

//Apply movement
motor.Move(_velocity);

 

//Calculate rotation as a 3D vector (turning around)
float _yRot = Input.GetAxisRaw(“Mouse X”);

 

Vector3 _rotation = new Vector3(0f, _yRot, 0f) * lookSensitivity;

 

//Apply rotation
motor.Rotate(_rotation);

 

//Calculate camera rotation as a 3D vector (turning around)
float _xRot = Input.GetAxisRaw(“Mouse Y”);

 

Vector3 _cameraRotation = new Vector3(_xRot, 0f, 0f) * lookSensitivity;

 

//Apply camera rotation
motor.RotateCamera(_cameraRotation);

 

// Calculate the thrusterforce based on player input
Vector3 _thrusterForce = Vector3.zero
if (Input.GetButton(“Jump”))
{
_thrusterForce = Vector3.up * thrusterForce;
SetJointSettings(0f);
} else
{
SetJointSettings(jointSpring);
}

 

//Apply the thruster force
motor.ApplyThruster(_thrusterForce);

 

}

 

private void SetJointSettings(float _jointSpring)
{
joint.yDrive = new JointDrive {
mode = jointMode,
positionSpring = jointSpring,
maximumForce = jointMaxForce
};
}

 

}

 

PlayerMotor

using UnityEngine;

 

[RequireComponent(typeof(Rigidbody))]
public class PlayerMotor : MonoBehaviour
{

 

[SerializeField]
private Camera cam;

 

private Vector3 velocity = Vector3.zero;
private Vector3 rotation = Vector3.zero;
private float cameraRotationX = 0f;
private float currentCameraRotationX = 0f;
private Vector3 thrusterForce = Vector3.zero;

 

[SerializeField]
private float cameraRotationLimit = 85f;

 

private Rigidbody rb;

 

void Start()
{
rb = GetComponent();
}

 

// Gets a movement vector
public void Move(Vector3 _velocity)
{
velocity = _velocity;
}

 

// Gets a rotational vector
public void Rotate(Vector3 _rotation)
{
rotation = _rotation;
}

 

// Gets a rotational vector for the camera
public void RotateCamera(float _cameraRotationX)
{
cameraRotationX = _cameraRotationX;
}

 

// Get a force vector for our thrusters
public void ApplyThruster(Vector3 _thrusterForce)
{
thrusterForce = _thrusterForce;
}

 

// Run every physics iteration
void FixedUpdate()
{
PerformMovement();
PerformRotation();
}

 

//Perform movement based on velocity variable
void PerformMovement()
{
if (velocity != Vector3.zero)
{
rb.MovePosition(rb.position + velocity * Time.fixedDeltaTime);
}

 

if (thrusterForce != Vector3.zero)
{
rb.AddForce(thrusterForce * Time.fixedDeltaTime, ForceMode.Acceleration);
}

 

}

 

//Perform rotation
void PerformRotation()
{
rb.MoveRotation(rb.rotation * Quaternion.Euler(rotation));
if (cam != null)
{
// Set our rotation and clamp it
currentCameraRotationX -= cameraRotationX;
currentCameraRotationX = Mathf.Clamp(currentCameraRotationX, -cameraRotationLimit, cameraRotationLimit);

 

//Apply our rotation to the transform of our camera
cam.transform.localEulerAngles = new Vector3(currentCameraRotationX, 0f, 0f);
}
}

 

}

 

by the way i should be using the latest version of unity in 2018 

the console says    Assets/PlayerController.cs(16.13): error CS1056: Unexpected character `?’

and   Assets/PlayerController.cs(16.20): error CS1525: Unexpected symbol `settings’

  • Liked by
Reply
1 on January 2, 2018

Simply copying the scripts wont do you any good friend, You need to copy the console log so we can get an idea of whats wrong.

on January 3, 2018

k  ill do that

thank you very much

Show more replies
  • Liked by
Reply
Cancel