Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Garzec · Jun 18, 2016 at 05:43 AM · cameratargetset

Set Camera Target Error ..

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 :)

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


 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);
     }
 }
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mwnDK1402 · Jun 18, 2016 at 03:16 PM 0
Share

What is your problem? You recognise that you can't convert CharacterController to Spieler, so why are you doing it? Why is charController of the type Spieler? Please explain.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to enable a childs camera 5 Answers

Changing camera target of CarSmoothFollow ( Js to c#) 0 Answers

Show a target above the player 0 Answers

camera target keep angle and y position 1 Answer

Assign spawned object to SmoothFollow target 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges