Movement Problem
Very 1st time using Unity. Im following the tutorial for this space shooter Click Here
I understand unity 5 has some new differences. Im have trouble fixing the script to be able to move and text player movement. The update site is here Look for 05 chatpter: movement
Here's the text i have using UnityEngine; using System.Collections; [System.Serializable] public class Boundary { %|858674557_1|% } public class PlayerController : MonoBehaviour { private Rigidbody rb; void Start() { rb = GetComponent<Rigidbody>(); } void FixedUpdate() %|-67900437_4|% %|1347400558_5|% float moveVertical = Input.GetAxis("Vertical"); Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical); %|-1583380458_8|% rb.position = new Vector3 ( Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax), 0.0f, Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax) ); rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt); } }
Here's the error im now receiving
Could someone help me by inserting the correct code so i can plug in test, while learning it. Like i said im very new and confused. Thx
Answer by nappdaddy2000 · Jan 26, 2016 at 06:42 PM
Im cleaning up the code to help you read it
using UnityEngine;
using System.Collections;
[System.Serializable]
public class Boundary
{
public float xMin, xMax, zMin, zMax;
}
public class PlayerController : MonoBehaviour
{
private Rigidbody rb; void Start() { rb = GetComponent<Rigidbody>(); }
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.velocity = movement * speed;
rb.position = new Vector3
(
Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax),
0.0f,
Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax)
);
rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt);
}
}
Sorry this is the error im getting
Assets/Done/Done_Scripts/Done_Evasive$$anonymous$$aneuver.cs(6,43): error CS1519: Unexpected symbol `boundary' in class, struct, or interface member declaration
Your answer
Follow this Question
Related Questions
Can anyone help me with a simple JS wait problem 0 Answers
camera moving in mouse direction 0 Answers
Compiler error 0 Answers
Moving RigidBody Smoothly 0 Answers
Character movement 1 Answer