- Home /
space shooter tutorial, cannot move player
Hi was wondering if someone could help me with this, ive just started the space shooter tutorial, Ive got to step 6 "moving the player", I did the first part of the code
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
void fixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rigidbody.velocity = movement;
}
}
no compile errors of any kind, when I go to play mode with the "game" window selected, I cannot move the player with the keyboard, ive tried using the arrow keys and wsad, the ship just stays in one spot with the engine running. Thank you
Can you just make the mass of rigidbody really small(like 0.001), cause the rigidbody,velocity = movement just gives a very small value that can hardly move the gameobject. Another way is to multiply a speed to the movement. like rigidbody.velocity = movement * 100;
Answer by robertbu · Mar 04, 2014 at 06:14 AM
Your issue is that 'fixedUpdate' should be 'FixedUpdate' with an upper case 'F'. Case matters in C#, and it is pretty easy to incorrectly the name of a callback.
Oh my god, THAN$$anonymous$$ YOU! That was it!
I contacted Unity to update the tutorial video as the video shows it as 'fixedUpdate'. I'm not sure if the $$anonymous$$ac version of $$anonymous$$onoDevelop is not canse sensitive in C# or (more likely) that the video is using a different script but talk about a rage inducing road block!
I have the same problem and I checked this but I have done it with caps. dont know whats wrong.
UPDATE: figured it out. I expected it to be mouse controlled. it is keyboard controlled. (thanks for mentioning that).
Hi in my case none of the above helped. I had to do this:
rb.velocity = movement * 35;
as mentioned here: https://answers.unity.com/questions/1273468/space-shooter-tutorial-player-wont-move-1.html
Hope it isn't a coding issue that's gonna bite me down the line...
:)
Your answer
Follow this Question
Related Questions
Opening a door at proximity 2 Answers
How can i do so when my car moves an object follows it? 1 Answer
3rd person player 0 Answers
Directional Movement - Input position calculation? 2 Answers
Player moving opposite direction when there is a new touch. 2 Answers