How to make character move relatively to the world and not the camera

– Introduction –
YOU CAN SKIP THIS. Essentially, pressing W makes your character go forward. Cool, but the way it moves “forward” means it moves “away from the camera”. If you are making a cool game where the camera is fixed and focuses on your character, let’s say you suddenly change camera positions, since you continue holding W, the character will make an awkward turn away from the camera since their movement is relative to it.

– Why is this information out here? –
Let’s say for some reason you want the character to move relative to the world when you press W or ASD. This basically means the character will move a constant direction in the robloxian space even if your camera moves anywhere.

– I HAVE FOUND THE SOLUTION –
After tiring digging and further research on the PlayerModule script (not really, it took like 2 minutes of looking), Line 18 of the BaseCharacterController, you will find this setting which presents itself very intuitively:

self.moveVectorIsCameraRelative = true

yep, that’s it. See ya.

– ADDITIONAL NOTES –
[] The ancestry of the script goes: Player > PlayerScripts > PlayerModule > ControlModule > BaseCharacterController
[] The PlayerModule will be hidden until the game is ran
[] The location of this setting may be subject to change in Roblox Updates, so don’t be discouraged if you don’t find it

9 Likes

I have not learned how to make the character move relative to the world and not the camera. Could you elaborate?

you jus have to find this line in the BaseCharacterController script (which its ancestry and where it can be found is listed under Additional notes):

self.moveVectorIsCameraRelative = true

and then turn it off

self.moveVectorIsCameraRelative = false

When I change this value, it doesn’t save. I see it keeps switching back everytime I open the script. Here’s a fixed tutorial:


Introduction

Skip to next section if you understand already!

Basically, moving forward means it moves “away from the camera”. If you are making 2.5D game (3D, but only allows 2D movement), different camera angles will cause unintended behavior. This tutorial will keep the movement consistant for all camera angles. This should only be used for these types of games, or in Isometric games.

Solution

After restlessly digging and researching on the PlayerModule (well, it took 2 minutes), I found that line 18 of the BaseCharacterController. You will find this setting which presents itself very intuitvely:

self.moveVectorIsCameraRelative = true

Looks about right! So how do we change it?

Hardcoded Steps

1: Start a Studio Playtest
2: Find the module at game.Players.LocalPlayer.PlayerScripts.PlayerModule
3: Copy this, end the playtest, then paste it in StarterPlayer.StarterPlayerScripts
4: Open the script PlayerModule.ControlModule.BaseCharacterController
5: Update line 18 to set moveVectorIsCameraRelative to false.
6: Test to see if it works.

This will work, but it doesn’t feel right. Now every character starts off like this, and this can be confusing. What if you wanted it only in certain zones? These next steps will fix that.

Modular Steps

1: Add a LocalScript in StarterGui, or StarterPlayer.StarterCharacterScripts
2: Set the code:

local PlayerModule = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))
-- TODO: 
-- Obsword, try to figure out how to set that variable through this script!

3: Test to see if it works.

1 Like

Thanks for writing out the HARDCODED STEPS for the others, I apologise for my vagueness. However, about the MODULAR STEPS, the ability to toggle this setting with custom scripts is well beyond my coding knowledge — I can only assume that you will need to copy paste an altered version of the original script, the alteration being setting up a function to change the setting (how someone will achieve that is up to their study and addition to the script).

But anyway, thanks for further elaboration. This should be the end of the thread, for now. :sunglasses:

Thanks for this. I’ve been looking for a solution for this problem myself. By the way, haven’t we met before?

After a little bit of tinkering, it’s not that I want the character to move relatively to the world. It’s that when the camera swaps to a different location, I want the character to move relative to the previous camera’s location until they stop moving. Then they can move relative to the new camera’s location.

This has still been helpful though, so thank you.

1 Like

Hey, did you manage to figure out a solution to this?
I’ve got the same problem- I want the player to continue in the same direction they were going in before the camera changed until they stop- but I can’t figure it out!!
Thanks :slight_smile:

Hi! It’s been 2 months since you posted your message, but no. I never managed to figure out a solution (partly because I got lazy and stopped working on my project), I’m pretty sure you may need to mess around with angles in the player controller, but I’m not qualified enough to expand on that.

Notably, if you implement tank controls, this problem doesn’t exist because movement is based on where your player is facing anyway. There’s a script on devforum somewhere that you can just copy and paste, if you search for it…

1 Like