UnityNinja Community
Would you like to react to this message? Create an account in a few clicks or log in to continue.

UnityNinja CommunityLog in

UnityNinja - Video Game Development Community, including Resources, Forums, Marketplace & More.


descriptionSet Camera Target Error .. EmptySet Camera Target Error ..

more_horiz
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);
    }
}

descriptionSet Camera Target Error .. EmptyRe: Set Camera Target Error ..

more_horiz
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...
privacy_tip Permissions in this forum:
You cannot reply to topics in this forum
power_settings_newLogin to reply