Question by
ZANGELDOR · Oct 15, 2016 at 04:07 PM ·
c#space shooterspaceship
Project Space Shooter: My ship won't move!
Hi, I am about half-way through the space shooter project, and my ship will not move. I have checked my 'movement' code over and over but it still doesn't work. Here is my 'player' script so far:
using UnityEngine;
using System.Collections;
[System.Serializable]
public class Boundary
{
public float xMin, xMax, zMin, zMax;
}
public class PlayerController : MonoBehaviour {
public float speed;
public float tilt;
public Boundary boundary;
public GameObject shot;
public Transform shotSpawn;
public float fireRate;
float nextFire;
void Update ()
{
if(Input.GetButton("Fire1") && Time.time > nextFire)
{
nextFire = Time.time + fireRate;
Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
}
}
void fixedUpdate ()
{
**float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
GetComponent<Rigidbody>().velocity = movement * speed;**
GetComponent<Rigidbody>().position = new Vector3(
Mathf.Clamp(GetComponent<Rigidbody>().position.x, boundary.xMin, boundary.xMax),
0.0f,
Mathf.Clamp(GetComponent<Rigidbody>().position.z, boundary.zMin, boundary.zMax)
);
GetComponent<Rigidbody>().rotation = Quaternion.Euler(0.0f, 0.0f, GetComponent<Rigidbody>().rotation.x * -tilt);
}
}
Can someone please help me find out what is wrong? Thanks.
Comment
Your answer
Follow this Question
Related Questions
[Solved] I am trying to build a space sim/ shooter type game. 1 Answer
Trail effect for non-moving object 2 Answers
space shooter tutorial help 0 Answers
game objects leaving trail of it's self 1 Answer
Java to C# Translation 1 Answer