Roll a ball - the ball does not move??
hello,
I'm totally new to Unity and via the tutorials I'm trying to setup the first Roll a ball project. I have setup according to the tutorial the various aspects. Bu t I cannot move the ball one single inch.
below you can find the code that I have used. Whatever I doo the ball does not move.
either I'm missing something or I made an error but I seem not able to find it.
thanks for your help.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playercontroler : MonoBehaviour {
public float speed;
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 * speed);
}
}
Answer by rettichmann · Dec 21, 2016 at 03:44 PM
Hi there! I wrote comments to the problem parts.
// Added default value.
public float speed = 5.0f;
private Rigidbody rb;
// Start function has to be capitalized: start() -> Start()
void Start()
{
rb = GetComponent<Rigidbody>();
}
// FixedUpdate function has to be capitalized: Fixedupdate() -> FixedUpdate()
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.AddForce(movement * speed);
}
Answer by wimvb · Dec 21, 2016 at 04:52 PM
Thank you for pointing this out to me. It is working now.
Answer by unity_ez_E0yv7ONiGZA · Oct 02, 2021 at 12:52 PM
Mine wasn't working either, so I looked through my inspector to see what wasn't connecting...
Under Player Input I had no action applied. I clicked on the little dot on the side of it and found InputActions (Input Action Asset) and selected it. Now controls are applied and are working. !!!
Answer by JD009 · Oct 02, 2021 at 02:45 PM
Thanks, I had already found out about it. I had faced the same problem.
Your answer
Follow this Question
Related Questions
rollaball floating ball 1 Answer
Why am i getting a Null Referencce Expectation in roll a ball? 1 Answer
camera rotate and follow the ball 0 Answers