#EVERYTHING STOPPED WORKING

1 messages · Page 1 of 1 (latest)

safe cargo
#

My game was working perfectly. then I pasted maybe 10 lines of code from ChatGPT and Visual Studios asked if I wanted to resave as Unicode. I didn't know what this meant so I clicked cancel and undid the changes by chat, but now NOTHING works. The player cant move anymore, doesn't teleport to spawn, is frozen in place, and so on. I'm completely lost on what to do, I tried resaving the file with ENCODING as Unicode, didn't fix it.

gleaming stone
#

start by checking your console window for errors of any kind

swift cave
#

are you getting any errors

#

whoops wasn't scrolled down

safe cargo
#

There isn't even any errors to go off of

#

I tried pasting all the code into a new "PlayerScript2" file in case the issue was the file itself and then deleted the old one, but the problem still persists

gleaming stone
#

if there's no errors the next step is to check that the code is actually running

#

add some Debug.Log statements into your movement code

#

and make sure they're printing at runtime

safe cargo
#

[PlayerScript] Start: rb=OK, bodyType=Dynamic, gravityScale=4, simulated=True, constraints=FreezeRotation UnityEngine.Debug:Log (object) PlayerScript:Start () (at Assets/Scripts/PlayerScript.cs:73)
[PlayerScript] Start: animator=OK, playerSpawn=OK, groundCheck=OK UnityEngine.Debug:Log (object) PlayerScript:Start () (at Assets/Scripts/PlayerScript.cs:80)

heres some debug log stuff I ran. When I try to move left or right it flips the sprite so it seems like the code is running

gleaming stone
#

we're more interested in the movement code

#

To be honeest, looking at your code, I'm not actually seeing anything that would move the player under normal circumstances

#

Oh I see here:

        float moveInput = horizontalInput;
        rb.linearVelocity = new Vector2(moveInput * speed, rb.linearVelocity.y);```
#

make sure this is running

#

and make sure moveInput and speed are not zero

safe cargo
#

I have this under the horizontal input but nothing is showing up in the consol:

   if (!movementCheckLogged && Mathf.Abs(moveInput) > 0.01f && rb != null && Mathf.Abs(rb.linearVelocity.x) < 0.001f)
   {
       Debug.LogWarning($"[PlayerScript] Movement input detected (moveInput={moveInput}) but rb.linearVelocity.x is {rb.linearVelocity.x}. Rigidbody2D bodyType={rb.bodyType}, gravityScale={rb.gravityScale}, simulated={rb.simulated}, constraints={rb.constraints}");
       movementCheckLogged = true;
   }
gleaming stone
#

just put if (Mathf.Abs(moveInput) > 0.01)

#

what you have right now is only ever going to log once

safe cargo
#

Ok I added this

gleaming stone
safe cargo
#

Player speed: 7.5
UnityEngine.Debug:Log (object)
PlayerScript:Update () (at Assets/Scripts/PlayerScript2.cs:122)

#

The player is frozen in place however, even if floating in the air

#

Keep in mind the player shouldn't even be positioned where he is, there is a PlayerSpawn object that he sould be teleporting to at the start

#

Also the yellow warning is for the old script which I deleted

gleaming stone
# safe cargo

It will be from either:

  • Some other codee of yours that is setting the position
  • An animator component you have on it
  • Or you have the position constrained on the Rigidbody2d
#

or some combination of these three

safe cargo
#

I see, That makes sense as the animation code is playing, it just seems to be the movement left and right, and the teleport to spawn

#

I'm just so confused on how this could have happened as none of the other code was altered when I pasted the addition of "PlayerAttackUp"

gleaming stone
#

Two of the three of those reasons I just mentioned aren't even code related

safe cargo
#

my rigidbody2d only has the z component constrained, what do you mean by the animator component? What effect would that have on my player being able to move left and right

gleaming stone
#

and it will indeed do that if you have it animating the root object

safe cargo
#

Wow you were right!

#

I unchecked the animator and now the player teleports to spawn and can move

#

thats crazy, thanks so much