I've got a little problem with my script (movement)

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.

Optimize Jumping:

Just an idea would be to use Input.GetKey instead of Input.GetButtonDown, I’m not completely certain as to which is better, but I personally always tend to use Input.GetKey

KeyCode jumpButton = KeyCode.Space; // Keyboard example
KeyCode jumpButton = KeyCode.JoystickButton0; // Controller example (Xbox Controller A button)

bool jumpPressed = Input.GetKey(jumpButton);

(Full list of Controller Keys)


Idea for your World Rotation:

(I hope your world isn’t very big by the way…)

So, what if you had everything in the world that you want to rotate attached as a child to an empty gameobject (let’s call this everythingObject). And then you attach the everythingObject as a child to the player. Then to rotate the world around the player you can just change the LocalRotation of the everythingObject.

Though, to do this would also require you to change your player movement a little; so instead of moving the player it’s now moving the LocalPosition of the everythingObject - and it’s moving it in the opposite direction that you’d generally move the player on a ‘normal world’ (giving the same effect as normal movement).

Again, just an idea …but I hope it helps nonetheless :slight_smile: