- Home /
help with roll a ball scripting
if someone would be kind enough to post the corect script for the roll a ball tutorial because the one that is given in the tutorial dosnt seem to work
I have never seen that tutorial... Are you talking about the RollerBall? And what problems are you having??
@Zitoox I am talking about the roll a ball tutorial on there website and when I put the correct script in it says there is a compile error and in the console it says the referenced script on this behavior (game object player) is missing and I don't know what to do
Do the script have a variable in wich you need to drag the character? $$anonymous$$aybe the problem is that. You could also try to tag your character as Player or just rename it to player.
I'm having the same problem. I'm on a $$anonymous$$ac running Unity 5.5.0f3 Personal. Checked my code and it seems exactly the same as the second video, yet it doesn't do anything and I get the same errors as Chrispy7502 described. Sure, I could copy the code – but I want to know what happened so that I can avoid the error in the future. Could it be that the tutorial is only checked with version 5? Doubtful, but I thought I'd ask. Here's what I have: using UnityEngine; using System.Collections;
public class PlayerController : $$anonymous$$onoBehaviour {
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.AddForce (movement);
}
}
I can't seem to get it to work.
Answer by Chrispy7502 · Oct 06, 2016 at 07:51 AM
@Zitoox I don't want to drag the player I want to use certain keys to move it but it doesn't clarify which keys it's supposed to use and the ball is already named player
Answer by JScotty · Oct 06, 2016 at 09:09 AM
[RequireComponent(typeof(Rigidbody))]
public class PlayerController : MonoBehaviour {
public float speed = 5.0f;
private Rigidbody body;
void Start () {
body = GetComponent<Rigidbody>();
}
void FixedUpdate (){
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
body.AddForce (movement * speed);
}
}
//or
[RequireComponent(typeof(Rigidbody))]
public class PlayerController : MonoBehaviour {
public float speed = 5.0f;
private Rigidbody body;
void Start () {
body = GetComponent<Rigidbody>();
}
void FixedUpdate () {
float moveHorizontal = 0;
float moveVertical = 0;
if(Input.GetButtonDown(KeyCode.A)) // if keybutton down
moveHorizontal = -1;
else if(Input.GetButtonDown(KeyCode.D)) // if keybutton down
moveHorizontal = 1;
if(Input.GetButtonDown(KeyCode.S)) // if keybutton down
moveVertical = -1;
else if(Input.GetButtonDown(KeyCode.W)) // if keybutton down
moveVertical = 1;
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
body.AddForce (movement * speed);
}
}
Hope this helps you out a bit
Your answer
Follow this Question
Related Questions
Character triple+ Jumping: Please Help! 0 Answers
Roll a Ball wont roll? 1 Answer
Roll a Ball Tutorial problem 1 Answer