Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2013
    Posts
    2

    Practical Game Development Unity 2.1 Error in PlayerController.cs

    I have a problem in PlayerController.cs, on line 55, please anyone who knows my mistakes please let me know where is my false, before I thank you..

    using UnityEngine;

    namespace Assets.Code
    {
    public class PlayerController
    {
    private readonly Player _player;

    private float
    _baseVelocity,
    _targetVelocity,
    _variableVelocity;

    public Vector3 MousePosition{ get; private set; }

    public float CurrentVelocity { get; private set; }

    public float MaxVariableVelocity { get; set; }

    public float MinimumVelocity { get; set; }

    public float Acceleration { get; set; }

    public float VelocityDamp { get; set; }

    public float RotationSpeed { get; set; }

    public float UseRelativeMovement { get; set; }

    public float MouseSensitivity { get; set; }



    public PlayerController(Player player)
    {
    MaxVariableVelocity = 20;
    Acceleration = 70;
    VelocityDamp = 20;
    RotationSpeed = .03f;

    MouseSensitivity = new Vector2(700, 700);
    UseRelativeMovement = false;

    _player = player;
    }

    public void Update()
    {
    Screen.lockCursor = UseRelativeMovement;

    if (UseRelativeMovement)
    {
    MousePosition + -new Vector3(
    Input.GetAxis("Mouse X") * Time.deltaTime * MouseSensitivity.x,
    Input.GetAxis("Mouse Y") * Time.deltaTime * MouseSensitivity.y);
    }
    else
    MousePosition = Input.mousePosition;

    UpdatePosition();
    UpdateRotation();
    }

    private void UpdatePosition()
    {
    _variableVelocity = Mathf.Clamp(
    _variableVelocity + Input.GetAxis("Vertical") * Time.deltaTime * Acceleration,
    0,
    MaxVariableVelocity);

    _targetVelocity = _variableVelocity + MinimumVelocity;

    CurrentVelocity = Mathf.Lerp(CurrentVelocity, _targetVelocity, Time.deltaTime * VelocityDamp);

    _player.transform.Translate(
    0,
    0,
    CurrentVelocity * Time.deltaTime,
    Space.Self);
    }

    private void UpdateRotation()
    {
    var mouseMovement = (MousePosition - (new Vector3(Screen.width / 2f, Screen.hi / 2f))) * .2f;

    if (mouseMovement.sqrMagnitude >= 1)
    _player.transform.Rotate(new Vector3(-mouseMovement.y, mouseMovement.x, 0) * RotationSpeed);
    }
    }
    }
    Click image for larger version. 

Name:	Screen02.jpg 
Views:	193 
Size:	221.1 KB 
ID:	73941Click image for larger version. 

Name:	Screen01.jpg 
Views:	184 
Size:	166.4 KB 
ID:	73942

  2. #2
    Join Date
    Aug 2004
    Posts
    21
    on line 53 you have "MousePosition + -new Vector3(" swap the - for an =.

  3. #3
    Join Date
    Jun 2012
    Location
    probably at a PC
    Posts
    309
    Yeah, it should be '+=' not '+ -'.

    Note: just replacing the '-' with '=' will not do it. '+' and '=' need to be combined to form a different operator than '+' or '=' are on their own.


    Note2: if you didn't know this and couldn't even recognize that '+ -new' is absolute gibberish by just looking at it, I strongly recommend that you go watch the C# 101 for absolute beginners videos. That should help you get familiar with the core basics of C#/programming.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •