- Home /
Character controller and MouseOrbit Camera(don't work togheter)
Hi guys, sorry for my English. I will try to explain you my problem. I have my Player (a ball) with a Character controller attached and a CharacterController.Move() script attached as well. I have a Main Camera with the mouseOrbit script attached. My Main Camera looks, of course, at my Player. The problem is: when I start the game my camera starts to shake up and down continuously. And I don't know how to solve this problem. Can you please help me? Thank you!
Answer by robertbu · Mar 08, 2013 at 03:02 AM
I just put the character controller script and the mouse orbit script together in a scene, and they worked just fine. No shaking. I was using a mouse for controlling the camera and a game controller for controlling the character. As a guess, the problem you face may be because you are trying to use the mouse for both camera movement and character movement. Given your original question, my guess is that you want to use the keyboard for controlling the character? If so, change the character controller script you copied from the script reference so that the motion and turning of the character are controlled by the keyboard and then see how well you thing the two scripts work together.
I changed the sample script at CharacterController.$$anonymous$$ove() to use arrow keys. I had no issues when I combined it with the mouse orbit script:
using UnityEngine;
using System.Collections;
public class CharHandler : $$anonymous$$onoBehaviour {
public float speed = 1000.0f;
public float jumpSpeed = 11.0f;
public float gravity = 20.0f;
public float dragFactor = 0.92f;
public float rotationSpeed = 10.0f;
private Vector3 moveDirection = Vector3.zero;
void Update() {
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded) {
if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.LeftArrow))
transform.RotateAround (Vector3.up, -rotationSpeed * Time.deltaTime);
if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.RightArrow))
transform.RotateAround (Vector3.up, rotationSpeed * Time.deltaTime);
moveDirection = Vector3.zero;
if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.UpArrow))
moveDirection += transform.forward * speed * Time.deltaTime;
if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.DownArrow))
moveDirection += -transform.forward * speed * Time.deltaTime;
if (Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.$$anonymous$$ove(moveDirection * Time.deltaTime);
}
}
Answer by anderson616 · May 01, 2017 at 03:13 PM
It's been a long time but the solution is simple, just check the IsKinematic option in RigidBody that stops this madness.
Your answer
Follow this Question
Related Questions
Orbit Camera on Survival Shooter Sample Project 0 Answers
Rotate camera to object on sphere 1 Answer
Getting a scrolling camera to orbit around a circular walkway, following the player? 1 Answer
WASD Controls not in-sync with camera? 1 Answer
How do I create a camera similar to the one in th room of shadows example? 0 Answers