i’m trying to complete the ball movement tutorial in unity because i’m new to it as well as coding in general and no matter what i seem to do i cant get the ball to move. its not telling me i have any errors, but i must be doing something wrong.
here is my work so far:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playercontroler : MonoBehaviour {
public float speed;
private Rigidbody rb;
public float Horizontal { get; private set; }
public float Vertical { get; private set; }
void Start ()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(Horizontal, 0.0f, Vertical);
rb.AddForce (movement);
}
}
if i can get some help i would greatly appreciate it.
Line 19 is your problem. You want the data from the input keys, but you’re using variables with private setters and never initializing them. This defaults them to 0 so you’re imparting no direction on the ball, and you have no control over that value externally.
It should look like this.
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
My ball won’t roll!!! To say that I am frustrated is an understatement. I am following the tutorial exactly. Had a friend review my code. Even fixed space between "newVector3( " as shown in the previous help area. I would appreciate a review and recommendation, please. And, Thank you.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerControllerMine : 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.AddForce (movement);
}
}