Hello there!
I would like to ask if is there any possible way to make a whole map rotating around the player position? I’m trying to make a very simple game where You are moving with a Ball and jumping on platforms (Also I’m a beginner so if You could add some reasons like ,why to use this code in this line" in Your answer, I would be very glad) . I don’t use here main camera as a child of the Player. I used script for it to just keep up a distance between them. So now the problem is I would like to rotate this camera on Y axis but I’m gettin a weird controller effect then. I mean, there is a change in the position of camera what makes another perspective on the player, but the controller is the same (what is not a weird thing for me cuz I just didn’t make any script for change direct of controller based on camera position), so for example, when I tap Left it moves to Right or Top. So I think a better way is to just use player as a center around which a whole map will be rotated, so I would not lose my control in the controller and make this game even more interesting. But the problem is, how to make it. Which function should I use here? My friend told me there is no way to get nor change Pivot position throught the code, but I believe I’m not the only here who wanted to create something like this, so I believe there is another way to make it out.
Well, that was the first problem which is not as important as my actually main one. I’ve made a very simple controller (just like beginners usually do) for my player. Here’s the code:
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float moveSpeed = 9.5f;
public float jumpSpeed = 1.5f;
public float gravity = 17.5f;
CharacterController controller;
Vector3 currentMovement;
void Start ()
{
controller = GetComponent<CharacterController>();
}
void Update ()
{
currentMovement = new Vector3(Input.GetAxis("Horizontal") * moveSpeed, currentMovement.y, Input.GetAxis("Vertical") * moveSpeed);
if(!controller.isGrounded)
currentMovement -= new Vector3(0, gravity * Time.deltaTime, 0);
else
currentMovement.y = 0;
if(controller.isGrounded && Input.GetButtonDown("Jump"))
currentMovement.y = jumpSpeed;
controller.Move(currentMovement * Time.deltaTime);
}
}
As You can see, it uses a CharacterController component. My only problem is how to optimize a jump option because it does not always react for some reason. And yeah, I don’t know what did I miss here so I would be glad if You share some solution.
Best regards,
Me.