My code is not working. On line 26, my rb.AddRelativeForce(Vector3.up) is not working. I am on lecture 36 of Complete C# Unity Game Developer 3D
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
Rigidbody rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
ProcessThrust();
ProcessRotation();
}
void ProcessThrust()
{
if(Input.GetKey(KeyCode.Space))
{
rb.AddRelativeForce(Vector3.up);
}
}
void ProcessRotation()
{
if (Input.GetKey(KeyCode.A))
{
Debug.Log("Rotating Left");
}
else if (Input.GetKey(KeyCode.D))
{
Debug.Log("Rotating Right");
}
}
}
yes it should be declaring a component you have confused the question you asked by attaching a code snippet please be clear
if you are asking for a rigid body it shoud be like
rb = GetComponent();
Here in the forum, the <> get interpreted as inline html or something like that. That’s why they disappear. We have to highlight the code and use the </> button to format it as code. Alternatively, we could use an escape character like \, which must get used like this \<Rigidbody\>. @edc237 used ? as a placeholder to visualise what Hammad chould check in his original code. He is right. It should be rb = GetComponent<Ridgidbody>() instead of rb = GetComponent().
@Hammad_Amjad, I edited your initial post, and formatted the code because it caused some confusion.