Obstacle Game problem movement

I am missing something. I have followed along with the discussions and been able to do the challenges. The problem I have is something that seems out of my control. In moving my character, I have the x and z axes used properly ( I think) but when I start my game without even touching the keyboard let alone the WASD keys, I have my character sliding diagonally to the left on my screen. I don’t know why that is happening and nothing was mentioned about it in the course to this point (or at least I did not understand what may cause this).

My Visual Studio Code is this:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class Mover : MonoBehaviour

{

  • [SerializeField] float moveSpeed = 10f;*

  • // Start is called before the first frame update*

  • void Start()*

  • {*

  •            *
    
  • }*

  • // Update is called once per frame*

  • void Update()*

  • {*

  •    float xValue = Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed;*
    
  •    float zValue = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed;*
    
  •    transform.Translate(xValue,0,zValue);*
    

Thanks for any help.

1 Like

Hi Richard,

Unfortunately, something seems to have gone wrong with the formatting of your code. Please follow this instruction: How to apply code formatting within your post.

Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture? And have you already tried to add Debug.Logs to your code to see what is going on during runtime? Maybe the GetAxis method do return a value higher or lower than 0f during runtime. That’s impossible to tell, though, without logging the output into your console.

Thanks for the info on “How to apply code formatting within your post.” I did not know that!

As far as I can tell, my coding is exactly the same as in the lecture. I will try to find the Debug.Logs and see what they are doing. I am using Unity 2020.2.5f1 if that is a possible reason (it is newer than the one used in the course).

Here is a picture of my code maybe you can see the other problem I have that pops up every time I start Visual Studio Code.

This is the whole error log that displays each time I start Visual Studio in unity:

Starting OmniSharp server at 2/24/2021, 8:20:56 AM

Target: i:\Unity2\Unity 3D\Simple Obstacle Course\Simple Obstacle Course.sln

OmniSharp server started.

Path: c:\Users\Owner\.vscode\extensions\ms-dotnettools.csharp-1.23.9\.omnisharp\1.37.6\OmniSharp.exe

PID: 17260
    Starting OmniSharp on Windows 6.2.9200.0 (x64)
    DotNetPath set to dotnet
    Located 3 MSBuild instance(s)

        1: Visual Studio Community 2017 15.5.27130.2010 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin"

        2: Visual Studio Build Tools 2019 16.7.30413.136 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin"

        3: StandAlone 16.8.0 - "c:\Users\Owner\.vscode\extensions\ms-dotnettools.csharp-1.23.9\.omnisharp\1.37.6\.msbuild\Current\Bin"
    Registered MSBuild instance: Visual Studio Build Tools 2019 16.7.30413.136 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin"
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionOptionsProvider, Order: 0
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider, Order: 140
    Detecting Cake files in 'i:\Unity2\Unity 3D\Simple Obstacle Course'.
    Could not find any Cake files
    Detecting projects in 'i:\Unity2\Unity 3D\Simple Obstacle Course\Simple Obstacle Course.sln'.
    Queue project update for 'i:\Unity2\Unity 3D\Simple Obstacle Course\Assembly-CSharp.csproj'
    Detecting CSX files in 'i:\Unity2\Unity 3D\Simple Obstacle Course'.
    Could not find any CSX files
    Configuration finished.
    Omnisharp server running using Stdio at location 'i:\Unity2\Unity 3D\Simple Obstacle Course' on host 16524.
    Loading project: i:\Unity2\Unity 3D\Simple Obstacle Course\Assembly-CSharp.csproj
    The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks
    Failed to load project file 'i:\Unity2\Unity 3D\Simple Obstacle Course\Assembly-CSharp.csproj'.

i:\Unity2\Unity 3D\Simple Obstacle Course\Assembly-CSharp.csproj

C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(1177,5): Error: The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks

    Attempted to update project that is not loaded: i:\Unity2\Unity 3D\Simple Obstacle Course\Assembly-CSharp.csproj

Your code looks fine. Did you log xValue and zValue into your console? If so, what was the output during runtime?

Only if one of these factor is 0, the result will be 0: Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed;

I don’t understand what you mean by:

“Did you log xValue and zValue into your console?”

Where would I have logged in one of those values?

In your Update method. For example like this:
Debug.Log("xValue: " + xValue);

Hi Richard_Rayer

Do you have any other input devices (other than mouse and keyboard) connected to your PC such as any type of gamepad or joystick based input device?

I only ask as the Input.GetAxis() will try read from any generic USB controller device that has some sort of axis based input, and if one of those devices is sending a slight signal, Unity will pick up on it.

I know its an odd question but I thought I’d best ask just to eliminate that possibility :slight_smile:

1 Like

Yes, I have an XBox Controller, a logitech g yoke controller and logitech g rudder controller any of which could be leaking a signal. I will pull them one at a time to see if one of them is the culprit.

Thanks for the suggestion!

Uh, that looks new to me so I have not got an Update method and I don’t remember that in any of the lectures. I will have to go back and listen to the lectures again I guess.

:face_with_raised_eyebrow:

YOU NAILED IT!!! :sunglasses:

Thanks, as it turns out when I detached the xBox controller and tried the game, BINGO everything worked as expected. (I know - it only makes a yellow box move left and right and forward and back. But it does it at my command using a s w d on the keyboard.)

Hats off to you! “Ta Da”

1 Like

:unamused: I tried to go to the next lecture and I just ran the game to see it work and there it was again, something is moving the game player without input. I guess I will try pulling all 3 of my USB controllers when I work on this and see if that helps.

Yep, that is what I had to do. Touchy, Touchy, system I guess.

Just saw this and was going to suggest this, I have a Logitech joystick which causes this to happen in many mainstream games, it is actually more common than you think.

Thanks for the info. I did disconnect all the USB controllers when working in Unity and it did the trick.

I’m glad that solved it for you :+1: :slight_smile:

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

Privacy & Terms