- Home /
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;
}
}
}
Could it be that these numpad keys are being detected as arrow keys, which by default go into the 'Horizontal' / 'Vertical' axes?
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 ;)
Your answer
Follow this Question
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