Hi, good afternoon. Can anyone help me with a movement issue my character is having? When i press Play , my character starts moving on its own backwards, but when i move my camera around the player moves with the camera. I checked and the camera is not the pone causing the problem, but i'm having second thoughts. Can anyone help me, or am I not making sense? Thanks.
#Having problems with character movement
1 messages · Page 1 of 1 (latest)
post your !code and relevant screenshots
Use the methods the bot describes: [How to post code](#💻┃code-beginner message)
go to the link... paste your code.. and hit the save icon..
the URL will refresh and give u a new one just copy and paste the url here
https://paste.myst.rs/ is my favorite...
https://paste.mod.gg/tveqhzgdnrzz/0
https://paste.mod.gg/cvvzfdsbrlmh/0
https://paste.mod.gg/zggakoixvbnc/0
Okey, thanks for the video any ways i figured out now. Im sending you the movement script and the camera script im using for this proyect. The weirdest thing is it only happens to me this problem, the other people im working with, in this proyectn dont seem to have this problem. Or occasionally have
A tool for sharing your source code with the world!
A tool for sharing your source code with the world!
A tool for sharing your source code with the world!
for screenshots u can use Win + Shift + S and then drag a box over the screen sections
it'll store it in ur clipboard and u can just Ctrl+V to paste it
that's how they'll always ask you to share big scripts/code
okey
The weirdest thing is it only happens to me this problem, the other people im working with, in this proyectn dont seem to have this problem.
umm.. that is odd
that definitely shouldnt be the case
i have a video if you need more info
let me look over the code real quick.. (im just a basic coder) im not an advanced user like alot of these other guys.. soo ill try my best to see what the issue may be... but i cant promise anything
the video would help explain what u mean better..
might as well just add that too since this is your own thread
can you share a screenshot of the Hierarchy.. (the structure of ur player)
the video is in spanish because im from argentina xd just in case
do you know anyone who is more advanced in programming to help me out?
just checked your code, basically your movement script only works at the start of the game, meaning that if your pressing "W" at the start it will forever move forward
the first link
exactly
like in ur Update() loop
u can cache the camera there that makes sense..
but not ur movement / Input
okey, i'll try to comment it and see what happens
replace start() with "update()"
i think that camera code is just setting up a state.. in Start()
to be honest.. these keywords don't even exist in the script
like what is leftRightFordBack ?
i think it stores the direction of the player
like 1 stands for left, 2 for right and so on
i guarentee if i paste that into my IDE its gonna blow up
lol sorry
its okay
none of these variables are created..
thar variable comes from the class CameraControllerClass, that PlayerCameraController inherates from
yup.. i was a bit confused.. since it was broken up in different scripts
that Start() method is fine then..
it is a bit complicated for a beginner.. ngl..
public class BasicMover : MonoBehaviour
{
public float moveRate = 5f;
private Vector3 moveAxis;
void Update()
{
HandleInput();
HandleMovement();
}
void HandleInput()
{
moveAxis.x = Input.GetAxisRaw("Horizontal");
moveAxis.z = Input.GetAxisRaw("Vertical");
}
void HandleMovement()
{
transform.position += moveAxis * moveRate * Time.deltaTime;
}
}``` a beginner script would look more like this 😅
Update runs -> first it calls the HandleInput() method.. getting ur input.. WASD
-> then it calls HandleMovement() which uses the input it assigned to moveAxis to move the transform/player
in ur MovePlayer() function it forces the movement even at zero Input
hi guys, im working on this proyect with JOTA and im here to help explain better whats going on
so basically this part of the code was intencionally used to set where the camera started looking
i believe its the Camera initialization thats messing with it when combined with the MovePlayer() script
okey
what if u did
if (moveDirection.sqrMagnitude > 0.01f)
{
transform.forward = camForward;
}```
just so the direction is only manipulated when ur moving
unless that messes with ur desired mechanics
TLDR:
Your movement code still moves the player when you aren't pressing anything, because gravity + camera direction gets blended into the movement direction.
That's why he "walks backward with the camera.
ahh,
sorry where should i put this?
soo better yet.. just think of it like this
Seperate your two systems..
Movement -> only when Input exists
Rotation -> always allowed
if (moveAxis.sqrMagnitude < 0.01) return;
// regular movement```
^ that way if ur movement magnitude isn't strong enough.. (not moving) it skips the rest of that function..
and then ur rotation can just be its own thing
haven't thought about it
yea i believe this is just a structural problem..
just the way the rotation and movement are tied into each other
makes conditions (edge-cases) where u have unexpected movement
okey
so i would probably have it broken up like
if( theres input)
-> do all ur movement and i guess even with the rotation is fine
else (if theres no input)
-> just do the rotation without any of the movement
but sorry I don't really have the time needed to actually test and dig thru the code like I would normally do..
🍀 good luck guys.. atleast now you got a thread going that you can refer to if u need to come back and ask for help
dont worry, you've helped enough