Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed May 01, 2013 at 05:30 PM by Julien-Lynge for the following reason:

Not appropriate for UnityAnswers

avatar image
-1
Question by GenOli · May 01, 2013 at 05:23 PM · c#javascript

[C#] PlayerRelativeControl conversion errors

I've been trying to convert the code from the Penelope(?) tutorial to CSharp from JavaScript also known as the mobile touchpad controls.

I get these two errors when trying to play:

 transform.positionWithLocalOffset assign attempt for 'Player' is not valid. Input positionWithLocalOffset is { NaN, NaN, NaN }.
 UnityEngine.CharacterController:Move(Vector3)
 PlayerRelativeControl:Update() (at Assets/Scripts/PlayerRelativeControl.cs:80)

 transform.localPosition assign attempt for 'CameraOffset' is not valid. Input localPosition is { NaN, 1.000000, -0.069555 }.
 UnityEngine.Transform:set_localPosition(Vector3)
 PlayerRelativeControl:Update() (at Assets/Scripts/PlayerRelativeControl.cs:91)
 


Here is the code so far:

 using UnityEngine;
 using System.Collections;
 
 [RequireComponent( typeof( CharacterController ) )]
 public class PlayerRelativeControl : MonoBehaviour
 {
         public Joystick moveJoystick;
         public Joystick rotateJoystick;
         public Transform cameraPivot;
         public float forwardSpeed = 6;
         public float backwardSpeed = 3;
         public float sidestepSpeed = 4;
         public float jumpSpeed = 4;
         public float inAirMultiplier = 0.25f;
         public Vector2 rotationSpeed = new Vector2( 50, 25 );
         
         private Transform thisTransform;
         private CharacterController character;
         private Vector3 cameraVelocity;
         private Vector3 velocity;
         
         void Start ()
         {
                 thisTransform = (Transform)GetComponent( typeof(Transform) );
                 character = (CharacterController)GetComponent( typeof(CharacterController) );
         }
         
         void OnEndGame()
         {
                 moveJoystick.Disable();
                 rotateJoystick.Disable();
                 this.enabled = false;
         }
 
         void Update ()
         {
                 Vector3 movement = thisTransform.TransformDirection( new Vector3( moveJoystick.position.x, 0, moveJoystick.position.y ) );
                 movement.y = 0;
                 movement.Normalize();
                 
                 Vector3 cameraTarget = Vector3.zero;
                 Vector2 absJoyPos = new Vector2( Mathf.Abs( moveJoystick.position.x ), Mathf.Abs( moveJoystick.position.y ) );
                 if( absJoyPos.y > absJoyPos.x )
                 {
                         if( moveJoystick.position.y > 0 )
                         {
                                 movement *= forwardSpeed * absJoyPos.y; 
                         }
                         else
                         {
                                 movement *= backwardSpeed * absJoyPos.y;
                                 cameraTarget.z = moveJoystick.position.y * 0.75f;
                         }
                 }
                 else
                 {
                         movement *= sidestepSpeed * absJoyPos.x;
                         cameraTarget.x = -moveJoystick.position.x * 0.5f;
                 }
                 
                 if( character.isGrounded )
                 {
                         if( rotateJoystick.tapCount == 2 )
                         {
                                 velocity = character.velocity;
                                 velocity.y = jumpSpeed;
                         }
                 }
                 else
                 {
                         velocity.y += Physics.gravity.y * Time.deltaTime;
                         cameraTarget.z = -jumpSpeed * 0.25f;
                         movement.x *= inAirMultiplier;
                         movement.z *= inAirMultiplier;
                 }
                 
                 movement += velocity;
                 movement += Physics.gravity;
                 movement *= Time.deltaTime;
                 character.Move( movement );
                 
                 if( character.isGrounded )
                 {
                         velocity = Vector3.zero;
                 }
                 
                 Vector3 pos = cameraPivot.localPosition;
                 //Debug.Log(pos.x)
                 pos.x = Mathf.SmoothDamp( pos.x, cameraTarget.x, ref cameraVelocity.x, 0.3f );
                 pos.z = Mathf.SmoothDamp( pos.z, cameraTarget.z, ref cameraVelocity.z, 0.5f );
                 cameraPivot.localPosition = pos;
                 
                 if( character.isGrounded )
                 {
                         Vector3 camRotation = rotateJoystick.position;
                         camRotation.x *= rotationSpeed.x;
                         camRotation.y *= rotationSpeed.y;
                         camRotation *= Time.deltaTime;
                         thisTransform.Rotate( 0, camRotation.x, 0, Space.World );
                         cameraPivot.Rotate( camRotation.y, 0, 0 );
                 }
                 
                 
         }
 }
 
Comment
Add comment · Show 2
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 Julien-Lynge · May 01, 2013 at 05:34 PM 0
Share

@GenOli, Your question (as it appears now) is not appropriate for UnityAnswers. It has the following problems:

  • No discernable question has been asked / not enough information. We cannot help you unless you tell us what isn't working, what you've already tried, and what you expect from the community.

  • Question is not of interest to other Unity users. Questions on UnityAnswers should be broadly applicable beyond your specific project.

  • Question is a 'fix my code for me' question. UnityAnswers (UA) is not Quality Assurance (QA) - it is up to you to write and bugfix your own code.

Please see the FAQ for more information on UnityAnswers standards for new questions: http://answers.unity3d.com/page/faq.html

avatar image GenOli · May 01, 2013 at 05:49 PM 0
Share

For anyone needing help with this script.

I've moved discussion to forums:

http://forum.unity3d.com/threads/180587-C-PlayerRelativeControl-conversion-errors

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Convert this Javascript into C#? 1 Answer

Get game component type? 1 Answer

Calling C# Classes from JS 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