- Home /
Ball rolls, but how to get it to jump? Parsing error. Non programmer.
I am trying to get a rigid body ball to be contralled via input and jump.
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public float speed;
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rigidbody.AddForce(movement * speed * Time.deltaTime);
}
}
var jumpSpeed : float = 8.0;
var gravity : float = 20.0;
var rotateSpeed : float = 3.0;
private var moveDirection : Vector3 = Vector3.zero;
function Update()
{
if (Input.GetButton ("Jump"))
{
moveDirection.y = jumpSpeed;
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
controller.Move(moveDirection * Time.deltaTime);
}
The ball rolls fine, which I followed from a tutorial. When I put the "jump code" in - copied from another answer, which supposedly worked - I get a parsing error on lines 20,19. I am NOT a programmer and I realize this is a ridiculous question for those who know what's up. If any one could point out my issue, that would be great.
TIA
If the code posted above is your whole script copied and pasted, then you copied the "jump code" outside of class, after closing curly bracket.
Answer by Apsylus · Aug 26, 2013 at 09:53 PM
As well as the answer from Jamora, another problem your having is that the two examples you've merged to make your code have been written in different programming languages.
Notice that the first part sets variables using : "float moveHorizontal = Input.GetAxis("Horizontal");" and the second uses "var jumpSpeed : float = 8.0;"
and the first time that the 2nd language is used is at the point where your getting an error.
Good catch, I saw UnityScript on line 20 and automatically assumed all of it would be in US.
Answer by Jamora · Aug 26, 2013 at 09:14 PM
If this is the contents of your whole script, your class ends at line 18 (the second } ). Which causes the compiler to not recognize anything after that. Remove that curly bracket and put one at the very end of the script so that everything is included within the class.
Thanks for the input peeps. So even when I properly include the class, it doesn't matter because the languages are simply different? Such scrub am I....
Ah, I made the bracket changes to include the classes, but even if I include everything in the class, it's still DOA because the languages are simply different? I'm such a scrub, lol. Thanks for the input peeps, I appreciate it.
You need to fix the syntax depending on whether your file is a .cs or a .js file.
I would imagine it's a C# file because the original class is a C# one... You'll need to changes line 20-26 as follows:
float jumpSpeed = 8.0f;
float gravity = 20.0f;
float rotateSpeed = 3.0f;
private Vector3 moveDirection = Vector3.zero;
void Update()