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 /
avatar image
0
Question by JoshMBeyer · Mar 28, 2014 at 07:53 PM · inputaxisissueget

Problem with input code for a camera follow/rotate script

I am trying to make the camera follow the sphere, but let me pivot the camera around it. I have this script but when trying to set up the controls I am having an issue. The spherecontroller, and the camerafollow script. I have input settings added "82" and "46" representing "82" the 8 and 2 key. "46" the 4 and 6 key on numbpad. One the positive and other the negative button. But they act as if they are the same as Input.GetAxis("Horizontal" and "Vertical"). What is the problem? here is my scripts

 using UnityEngine;
 using System.Collections;
 
 public class CameraFollow : MonoBehaviour
 {
   public Transform target;
     public float distance = 20.0f;
     public float zoomSpd = 2.0f;
  
     public float xSpeed = 240.0f;
     public float ySpeed = 123.0f;
  
     public int yMinLimit = -723;
     public int yMaxLimit = 877;
  
     private float x = 0.0f;
     private float y = 0.0f;
  
     public void Start () {
         Vector3 angles = transform.eulerAngles;
         x = angles.y;
         y = angles.x;
  
         // Make the rigid body not change rotation
         if (rigidbody)
             rigidbody.freezeRotation = true;
     }
  
     public void LateUpdate () {
         if (target) {
             x -= Input.GetAxis("82") * xSpeed * 0.02f;
             y += Input.GetAxis("46") * ySpeed * 0.02f;
  
             y = ClampAngle(y, yMinLimit, yMaxLimit);
  
             distance -= Input.GetAxis("Fire1") *zoomSpd* 0.02f;
             distance += Input.GetAxis("Fire2") *zoomSpd* 0.02f;
  
             Quaternion rotation = Quaternion.Euler(y, x, 0.0f);
             Vector3 position = rotation * new Vector3(0.0f, 0.0f, -distance) + target.position;
  
             transform.rotation = rotation;
             transform.position = position;
         }
     }
  
     public static float ClampAngle (float angle, float min, float max) {
         if (angle < -360.0f)
             angle += 360.0f;
         if (angle > 360.0f)
             angle -= 360.0f;
         return Mathf.Clamp (angle, min, max);
     }
 }
 

 using UnityEngine;
 using System.Collections;
 
 public class SphereController : MonoBehaviour {
 
     ///This is the SphereController script.
     ///This governs the behaviour of the sphere gameobject.
     ///All of the values are public at this moment so they are easily 
     ///adjustable through the inspector without having to change any coding.
 
     //The constant forward speed.
    // public float sphereSpeed;
     //The user controlled left and right speed.
     //public float leftRightSpeed;
 
     //Win or Loss.
     public bool win;
     public bool gameOver;
 
     //The constant forward speed.
     public float sphereSpeed = 1;
     //The user controlled left and right speed.
     public float leftRightSpeed = 1;
  
 
     // Update is called once per frame
     void FixedUpdate () {
        rigidbody.AddForce(Input.GetAxis("Horizontal") * leftRightSpeed, 0, 0);
  
        rigidbody.AddForce(0, 0, Input.GetAxis("Vertical") * sphereSpeed);
     }
 
 
     void Update () 
     {
 
         if (transform.position.z >= 19)
         {
             win = true;
             //Disable movement of the sphere.
             //Here we could load a different scene. Win screen, highscore screen, etc.
             this.gameObject.GetComponent<SphereController>().enabled = false;
         }
     }
 
 }
 
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 Dave-Hampson ♦♦ · Apr 01, 2014 at 03:14 PM 0
Share

Could it be that these numpad keys are being detected as arrow keys, which by default go into the 'Horizontal' / 'Vertical' axes?

avatar image thornekey · Apr 01, 2014 at 04:15 PM 0
Share

just have the camera in an empty object then drag the camera out a certain amount (like 10 units) then rotate the empty game object.. (the empty should be a the center of the thing u want to rotate around).. then just make a code to rotate the empty on Y axis. it will appear to pivoty it around the object ;)

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

22 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

New Input axis with Numpad Keys 2 Answers

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers

Input axes freeze from opposite input rather than cancel out! 1 Answer

Creating an input manager that supports axis 0 Answers

How to get an axis without defining it in the InputManager 0 Answers


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