#Having problems with character movement

1 messages · Page 1 of 1 (latest)

bitter flame
#

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.

viscid mica
#

post your !code and relevant screenshots

bitter flame
#

sorry but im new at this

viscid mica
#

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

bitter flame
#

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

viscid mica
#

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

viscid mica
bitter flame
#

okey

viscid mica
#

that definitely shouldnt be the case

bitter flame
#

i have a video if you need more info

viscid mica
#

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)

bitter flame
#

do you know anyone who is more advanced in programming to help me out?

neat raft
viscid mica
#

is it not in update? rofl

#

i haven't checkd yet

neat raft
#

the first link

viscid mica
#

oh yea bro.. so Start() only runs 1 time..

#

when the script first exists..

neat raft
viscid mica
#

like in ur Update() loop

#

u can cache the camera there that makes sense..

#

but not ur movement / Input

bitter flame
#

okey, i'll try to comment it and see what happens

viscid mica
#

wait

#

this is his movement

#

it is in Update()

neat raft
#

replace start() with "update()"

viscid mica
#

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 ?

neat raft
viscid mica
#

theres no declaration of those booleans

#

yea but they dont exist

neat raft
#

like 1 stands for left, 2 for right and so on

viscid mica
#

i guarentee if i paste that into my IDE its gonna blow up

neat raft
#

this is the most complicated script i think

#

i dont really know

bitter flame
neat raft
viscid mica
#

none of these variables are created..

bitter flame
#

thar variable comes from the class CameraControllerClass, that PlayerCameraController inherates from

viscid mica
#

nvm i found it

viscid mica
#

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

vale hawk
#

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

viscid mica
#

i believe its the Camera initialization thats messing with it when combined with the MovePlayer() script

vale hawk
#

okey

viscid mica
#

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

vale hawk
#

okey

#

gimme a sec and i'll try it out

viscid mica
#

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.

vale hawk
#

ahh,

vale hawk
viscid mica
#

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

vale hawk
#

haven't thought about it

viscid mica
#

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

vale hawk
#

okey

viscid mica
#

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

vale hawk
#

dont worry, you've helped enough