Other
need help with rolling ball camera script!
Hello, i need help with my game, my camera rotates only left and right but not up and down. And when i turn my camera left and press W it goes forward but not where my camera is looking. To see what im saying you can download the game on: https://wi8games.itch.io/rollin-free. All i need is to rotate my camera 360 degrees and when i turn my camera left or right i want a ball to go where camera is facing. I need this really fast because the game is out already.
my camera script:
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class CameraMovement : MonoBehaviour {
public float turnSpeed = 7.0f;
public GameObject DeathScreen;
public Transform player;
public Transform PauseMenu1;
public float height = 2f;
public float distance = 5f;
private Vector3 offsetX;
void Start()
{
offsetX = new Vector3(0, height, distance);
}
void Update()
{
PauseDeathScreen();
}
void LateUpdate()
{
offsetX = Quaternion.AngleAxis(Input.GetAxis("Mouse X") * turnSpeed, Vector3.up) * offsetX;
transform.position = player.position + offsetX;
transform.LookAt(player.position);
if (PauseMenu1.gameObject.activeInHierarchy)
{
turnSpeed = 0;
}
else
turnSpeed = 7.0f;
}
void PauseDeathScreen()
{
if (DeathScreen.gameObject.activeInHierarchy)
{
turnSpeed = 0;
}
}
}
My player controller script:
using System.Collections; using UnityEngine.UI; using UnityEngine; using UnityEngine.SceneManagement;
public class PlayerController : MonoBehaviour { public float JumpHeight = 500; public float speed; public float maxSpeed; public Text countText;
public string nextLevelName;
public int coinCountToNextLevel;
private Rigidbody rb;
private int count;
private Transform camTransform;
public jojstick joystick;
public float slowDownFactor = 0.05f;
public float slowdownLenght = 0.05f;
void Start()
{
rb = GetComponent<Rigidbody>();
count = 0;
SetCountText();
}
void FixedUpdate()
{
Vector3 dir = Vector3.zero;
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
//dir.x = joystick.Horizontal();
//dir.z = joystick.Vertical();
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.AddForce(movement * speed);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Pick Up"))
{
other.gameObject.SetActive(false);
count = count + 1;
SetCountText();
}
}
void SetCountText()
{
countText.text = "Coins: " + count.ToString();
}
void Update()
{
if (rb.velocity.magnitude > maxSpeed)
{
rb.velocity = Vector3.ClampMagnitude(rb.velocity, maxSpeed);
}
if (count >= coinCountToNextLevel)
{
Debug.Log("Loading Next Scene");
SceneManager.LoadScene(nextLevelName);
Cursor.lockState = CursorLockMode.Confined;
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
SlowDownTheTime();
NormalizeTime();
//Jump();
}
//void Jump()
//{
//if (Input.GetKeyDown(KeyCode.Space))
//{
//rb.AddForce(Vector3.up * JumpHeight);
//}
//}
void SlowDownTheTime()
{
if (Input.GetKeyDown("e"))
Time.timeScale = slowDownFactor;
Time.fixedDeltaTime = Time.timeScale * .02f;
}
void NormalizeTime()
{
if (Input.GetKeyDown("r"))
Time.timeScale = 1;
}
}
Follow this Question
Related Questions
Camera filters broke FPS Controller (Unity 5) 0 Answers
How to change direction of RayCast based on camera angle? 0 Answers
2 player Roll a Ball 0 Answers
Camera movement problem 0 Answers
How to LOCK/STOP Rotation on Main Camera as child of Prefab? 0 Answers