acwatson421
acwatson421

Reputation: 47

Unity3D player camera error cs0119

I'm trying to write a basic script in C# to make my camera follow my player while they walk around. I'm following the 3rd camera tutorial listed here. The code is all in javascript, and while its easy to translate i'm afraid something might be missing for that reason. I'm receiving the following error:

PlayerCamera.cs(21,65): error CS0119: Expression denotes a type', where avariable', value' ormethod group' was expected

which refers to this line of code:

newPosition += Quaternion.Euler(0, yAngle, 0) * Vector3(0.0f, distanceAbove, -distanceAway);

I've already tried newing the Vector3 in line and using a separate variable to store said Vector3 before multiplying, and I've kind of run out of ideas as I'm pretty new to programming in Unity. Any and all help is appreciated!

Full code for reference:

using UnityEngine;
using System.Collections;

public class PlayerCamera : MonoBehaviour {

    public Transform player;
    public float smoothTime = 0.3f;
    public float distanceAbove = 3.0f;
    public float distanceAway = 5.0f;
    private float yVelocity = 0.0f;

    // Update is called once per frame
    void Update () {
        float yAngle = Mathf.SmoothDampAngle(transform.eulerAngles.y,
                                             player.eulerAngles.y,
                                             ref yVelocity,
                                             smoothTime);

        Vector3 newPosition = player.position;

        newPosition += Quaternion.Euler(0, yAngle, 0) * Vector3(0.0f, distanceAbove, -distanceAway);

        gameObject.transform.position = newPosition;
        gameObject.transform.LookAt(player);
    }
}

Upvotes: 0

Views: 902

Answers (2)

Niels de Schrijver
Niels de Schrijver

Reputation: 335

I might misunderstand but if you want a camera to follow your controller, why not just make it a child-object and put it in the position you want?

Upvotes: 0

Tseng
Tseng

Reputation: 64288

In C# structs (in your case Vector3) have to initialized with the new keyword.

newPosition += Quaternion.Euler(0, yAngle, 0) * new Vector3(0.0f, distanceAbove, -distanceAway);

Upvotes: 1

Related Questions