Player Movement Bug when using 'ControlRemover.CS'

Hello! This course has been amazing, I’m learning a lot so thank you! I was getting a weird behavior from the cinematics ‘Intro Sequence’ only when using the events and the control remover script , not sure if others were as well and I’m having a hard time debugging.

When that script is used, which stops the player movement and any actions while the timeline sequence plays, once the timeline cinematic finishes my player is moving weird when clicking the mouse to go to a spot, the player might go a different direction or return back to a spot after trying to move them. The raycast seems to not be working and the player does not move where I want.

This issue only occurs when having the control remover script turned on which is puzzling me because I used the exact same code as the lesson and updated the Cancel method in the Fighter class so I can’t figure out what the issue is. Seems something wrong when enabling controls back on, The player moves fine if I allow the controller to stay on during the cinematic clip but obviously that wouldn’t be wanted.

Any suggestions or thoughts would be awesome, let me know if I can explain better anything.

Thank you!

Dan

It almost sounds like the raycast is responding to the wrong camera…

Let’s check a couple things to be sure… Paste in the text of your CinematicControlRemover.cs and your PlayerController.cs and we’ll take a look.

Hey Brian, thanks for reaching out! Good point it does seem to be with the camera because when I test it by turning the virtual cinemachine camera off and using the portals, it doesn’t have this issue.

I have a camera tagged MainCamera but the cinemachine follow camera on the player is untagged. My PlayerController is calling Camera.main like below. Should I manipulate the tags somehow or call it differently in code?

private static Ray GetMouseRay()
{
return Camera.main.ScreenPointToRay(Input.mousePosition);
}

I’ll have to check the course project, but I’m pretty sure the Main Camera is the one with the Cinemachine Brain on it.

Ok cool that’s where the main camera is tagged to so it’s not that. Seems to be when the player transform is being followed by the virtual camera. If I have it follow ‘none’ there is no issue but obviously then I am not following the player. It affects the player upon entering any portal (to new scene or to cut scene). I have to delete player in scene and readd the prefab to reset the raycast to working properly, but then entering a new portal/scene it bugs out again.

Here’s the full movement script in player controller,

private bool InteractWithMovement()
{

            RaycastHit hit;
            bool hasHit = Physics.Raycast(GetMouseRay(), out hit);
            if (hasHit)
            {
                if (Input.GetMouseButton(0))
                {
                mover.StartMoveAction(hit.point, 1f);
                Debug.Log(hit.collider.name);
                }
                return true;
            }
            return false;
        
    }

    private static Ray GetMouseRay()
    {
        return Camera.main.ScreenPointToRay(Input.mousePosition);
    }

Make absolutely sure that no other camera has the MainCamera tag on it, just the Cinemachine Brain.

If that’s not the issue, I’ll need to take a look at your project. Zip it up and upload it at https://gdev.tv/projectupload and I’ll take a look at it.

I am working on this, I assure you. At this point, I’m puzzled as well, as the point is the correct location, but the command sent to Mover appears to be different.

Ok, I found the problem. There is a script on the Main Camera “SimpleCameraController”. I hadn’t thought of it, because I didn’t realize you were using the URP instead of the “standard” renderer (That’s not a problem, as long as you convert your materials properly). The URP sample scene adds a SimpleCameraController script that is interfering with the Cinemachine Brain. Removing this component fixed the issue.

1 Like

Thank you so much Brian! Learning more about URP didn’t know that could be an issue. Thanks for helping out!!

Later versions of Unity actually allow you to skip including all of the tutorial assets that come with the URP default scene. I’ve used URP exclusively for almost 2 years, and the first thing I do on a new project is clear out all those unneeded assets.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms