Question by
BlackHants · Sep 03, 2015 at 05:06 AM ·
errormovementjumpingcompiler error
COMPILER ERROR NOT FOUND
I was trying to make my player move and jump but I made a mistake that I can't found. Removing the part that makes the player jump, there's no compiler error, but when I play, after a time it falls into left.
public float speed;
private Rigidbody rb;
private Vector3 movement;
private int jumping;
void Start ()
{
rb = GetComponent<Rigidbody>();
}
void Update ()
{
if (Input.GetKeyDown ("space"))(jumping = false){
Vector3 jump = new Vector3 (0.0f, 500.0f, 0.0f);
GetComponent<Rigidbody> ().AddForce (jump);
jumping = true;
}
}
void LateUpdate ()
{
if (jumping = true) {
jumping = false;
}
}
void FixedUpdate ()
{
// Store the input axes.
float h = Input.GetAxisRaw ("Horizontal");
float v = Input.GetAxisRaw ("Vertical");
Move (h, v);
}
void Move (float h, float v)
{
movement.Set (h, 0f, v);
movement = movement.normalized * speed * Time.deltaTime;
rb.MovePosition (transform.position + movement);
}
The player is a capsule with a ball as head. The scales are 1;1;1 (capsule/body) and 1.245381 (sphere/head). The sphere is 1.35 up to the center of the capsule.
Comment
Are you sure there's no compiler error ? private int jumping;
then you're trying to use it as a bool
.
if (Input.Get$$anonymous$$eyDown ("space"))(jumping = false){
missing some operator like && or ||
if (jumping = true) {
should be
if (jumping == true) {
Answer by Positive7 · Sep 03, 2015 at 02:50 PM
public float speed;
private Rigidbody rb;
private Vector3 movement;
private bool jumping;
void Start ()
{
rb = GetComponent<Rigidbody>();
}
void Update ()
{
if (Input.GetKeyDown ("space") && jumping == false){
Vector3 jump = new Vector3 (0.0f, 500.0f, 0.0f);
GetComponent<Rigidbody> ().AddForce (jump);
jumping = true;
}
}
void LateUpdate ()
{
if (jumping == true) {
jumping = false;
}
}
void FixedUpdate ()
{
// Store the input axes.
float h = Input.GetAxisRaw ("Horizontal");
float v = Input.GetAxisRaw ("Vertical");
Move (h, v);
}
void Move (float h, float v)
{
movement.Set (h, 0f, v);
movement = movement.normalized * speed * Time.deltaTime;
rb.MovePosition (transform.position + movement);
}