Can't get roll-a-ball behavior script (my first script) to work...
I went through all of the instructions exactly up to this point (step 9):
Roll-a-ball step 9 video tutorial
I can't get the ball to move, nor the C# variable speed
to appear as a parameter in Unity editor (2 issues).
I tried setting the speed to 10.0f manually in the code, and the ball still won't move. There are no compilation or runtime errors.
My script is:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class NewBehaviourScript1 : MonoBehaviour
{
private float speed = 10.0f;
private Rigidbody rb;
private float movementX;
private float movementY;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
void OnMove(InputValue movementValue)
{
Vector2 movementVector = movementValue.Get<Vector2>();
movementX = movementVector.x;
movementY = movementVector.y;
}
void FixedUpdate()
{
Vector3 movement = new Vector3(movementX, 0.0f, movementY);
rb.AddForce(movement * speed);
}
}
Answer by Dsiak · Nov 24, 2021 at 12:26 AM
the variable speed isn't showing up because its a private variable, you have to either set it to public or write it like this: [SerializeField] private float speed
As for the movement its probably because the move action isn't being triggered, you can check by writing Debug.Log("X: "+ movementX + " Y: "+ movementY)
if this display double zeroes it means nothing is coming out of movementValue . Make sure you have it properly set up, roll back to the part of the guide where the Player Input is setup and see if you skipped any steps.
Your answer
Follow this Question
Related Questions
RayCast issues 0 Answers
The roll a ball script isn't working :(((( 2 Answers
is there any way to select gameobject by script in hierarchy ? 0 Answers
how do I rezolve "look rotation viewing vector is zero"? 1 Answer
How to make certain collectibles have to be unlocked before being able to be picked up? 1 Answer