Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink

You are not connected. Please login or register

Unity Ninja Unity 3D Forum » HELP » Help (General) » Set Camera Target Error ..

Set Camera Target Error ..

View previous topic View next topic Go down  Message [Page 1 of 1]

1 Set Camera Target Error .. on Fri Jun 17, 2016 5:18 pm

Garzec


Member [Lv. 2]
Member [Lv. 2]
Hi,
im new to programming and to Unity. i created a Gamepad control and a script for the player and for the camera.

In the camera script i try to set the target of the camera but a error appears.

UnityEngine.CharacterController can not converted into Spieler. Of course i know its a mistake between the types. Spieler is the players class.

The mistake appears in the camera script at the method "SetCameraTarget" at the if-statement...

But i dont know how to fix it. Here the script of my player and my camera. it would be awesome if someone would know how to fix the mistake Smile

Code:

public class Spieler : MonoBehaviour
{
    // Deadzone
    public float inputDelay = 0.1f;
    // Bewegungsgeschwindigkeit
    public float forwardVel = 12;
    // Geschwindigkeit beim Umdrehen
    public float rotateVel = 100;
    // Hält die Position für die nächste Rotation
    private Quaternion targetRotation;
    // Rigidbody
    private Rigidbody rBody;
    // Input Bewegung
    private float forwardInput;
    // Input Drehung
    private float turnInput;
    public Quaternion TargetRotation
    {
            get
            {
                    return targetRotation;
            }
    }
    private void Start()
    {
            targetRotation = transform.rotation;
            if (GetComponent<Rigidbody>())
                    rBody = GetComponent<Rigidbody>();
            forwardInput = turnInput = 0;
    }
    private void GetInput()
    {
            forwardInput = Input.GetAxis("LeftJoystickVertical");
            turnInput = Input.GetAxis("LeftJoystickHorizontal");
    }
    private void Update()
    {
            GetInput();
            Turn();
    }
    private void FixedUpdate()
    {
            Run();
    }
    private void Run()
    {
            if (Mathf.Abs(forwardInput) > inputDelay)
            {
                    // Bewegen
                    rBody.velocity = transform.forward * forwardInput * forwardVel;
            }
            else
            {
                    // 0 Velocity
                    rBody.velocity = Vector3.zero;
            }
    }
    private void Turn()
    {
            if (Mathf.Abs(turnInput) > inputDelay)
            {
                    // Faktor lässt den Spieler flüssig drehen
                    targetRotation *= Quaternion.AngleAxis(rotateVel * turnInput * Time.deltaTime, Vector3.up);
            }
            transform.rotation = targetRotation;
    }
}

Code:

public class Kamera : MonoBehaviour
{
    // Ziel
    public Transform target;
    //
    public float lookSmooth = 0.09f;
    // Kameraentfernung vom Ziel
    public Vector3 offSetFromTarget = new Vector3(0, 6, 8);
    // Einschränkung der Kamera auf der X-Achse
    public float xTilt = 10;
    private Vector3 destination = Vector3.zero;
    // Referenz zum Spieler
    private Spieler charController;
    private float rotateVel = 0;
    private void Start()
    {
            SetCameraTarget(target);
    }
    private void SetCameraTarget(Transform t)
    {
            target = t;
            if (target != null)
            {
                    if (target.GetComponent<CharacterController>())
                            charController = target.GetComponent<CharacterController>();
            }
    }
    private void LateUpdate()
    {
            // Bewegen
            MoveToTarget();
            // Rotieren
            LookAtTarget();
    }
    private void MoveToTarget()
    {
            // Kamera bewegen
            destination = charController.TargetRotation * offSetFromTarget;
            destination += target.position;
            transform.position = destination;
    }
    private void LookAtTarget()
    {
            // Kamera rotieren
            float eulerYAngle = Mathf.SmoothDampAngle(transform.eulerAngles.y, target.eulerAngles.y, ref rotateVel, lookSmooth);
            transform.rotation = Quaternion.Euler(transform.eulerAngles.x, eulerYAngle, 0);
    }
}

View user profile

2 Re: Set Camera Target Error .. on Mon Aug 08, 2016 10:33 am

jakeyiii


Member [Lv. 3]
Member [Lv. 3]
Hello

We see that you have some issues with your project/script, however we can help you for a price. If you would like us to work for you then please feel free to contact us at http://RenntekStudios.co.uk or on Skype at RenntekStudios thanks

Our prices are very cheap. Little errors we can fix for free, otherwise projects we can discuss prices. Hope you get in touch shortly thank you...

View user profile

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum