- Home /
Space Shooter Tutorial; Player won't move as shown at 7:05 in the Tutorial Video
It pains me to come here but I am unable to figure out how to move the Ship in the Space Shooter. I have followed the video and changed the script as per the Upgraded Guide on ownCloud and looked on the forums for fixes but cannot figure it out. When I hit 'play' it enters play mode so there's no compiler errors but if I press W,A,S,D or Up, Down, Left, Right the Ship won't budge.
The Script is attached to the Player and 'Is Kinematic' is unchecked. If you need further information to aid in your answer I would be happy to provide it.
My Code is this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
private Rigidbody rb;
private void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("moveHorizontal");
float moveVertical = Input.GetAxis("moveVertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.velocity = movement;
}
}
I'm sorry to repeat a question that's been asked a lot but I'm having a lot of trouble figuring this out, I'm new to coding and it's confusing jumping from the outdated video tutorial, the Upgrade Guide and forums. I just get lost. And I want to figure this out before moving onto 'Speed' section the video.
Answer by unit_nick · Oct 13, 2017 at 03:56 AM
Lines 14 & 15. There are no axis named "moveHorizontal" & "moveVertical". Try "Horizontal" & "Vertical" in the GetAxis()
Answer by TBART82 · Oct 13, 2017 at 03:59 AM
@PotatOS432 So I entered your code into Unity and I found the issue. There is no Axis named "moveHorizontal" and "moveVertical". If you go to 'Edit -> Project Settings -> Inputs' you will see there are two axis called "Horizontal" and "Vertical" these are the ones you want to use. So:
Change
float moveHorizontal = Input.GetAxis("moveHorizontal");
float moveVertical = Input.GetAxis("moveVertical");
To
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Hopefully this helps!
TBART82
Answer by PotatOS432 · Oct 15, 2017 at 12:30 AM
@unit_nick , @TBART82 I feel so stupid rn haha. this worked, thank you for your help! Now i can continue :)