Hi, another error, don't know what it means

Again, another error. Every time I do this, it doesn’t work. I even tried changing -UnityEngine.Vector3.forward to UnityEngine.Vector3.back, but it doesn’t work. Please help.


Rigidbody rb;

[SerializeField] float Thrust = 1f;

[SerializeField] float rotationThrust = 1f;

// 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(UnityEngine.Vector3.up * Thrust * Time.deltaTime);

   }

}

void ProcessRotation()

{

     if (Input.GetKey(KeyCode.A))

   {

       transform.Rotate(UnityEngine.Vector3.forward * rotationThrust * Time.deltaTime);

   }

    else if (Input.GetKey(KeyCode.D))

   {

       transform.Rotate(UnityEngine.Vector3.back * rotationThrust * Time.deltaTime);

   }

}

Hi ThePhoenixBoi,

Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture?


See also:

Yes, i cant find the script on the project changes tho

Click on “Browse Files”, then Assets > Scripts.

I don’t understand this code because I am not all the way through the lecture yet.

Should I carry on with the lecture without testing to see if it works then? Or is this a newer version of this code?

The compiler complains about “Dataflow” in the error message. Check your code whether there is “Dataflow”. If you find it, remove it.

Thanks!

Now it’s not rotating
Here’s the new code:
using System.Threading.Tasks;

using System.Threading;

using System.Collections.Specialized;

using System.Numerics;

using System.Data.Common;

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class Movement : MonoBehaviour

{

Rigidbody rb;

[SerializeField] float Thrust = 1f;

[SerializeField] float rotationThrust = 1f;

// 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(UnityEngine.Vector3.up * Thrust * Time.deltaTime);

   }

}

void ProcessRotation()

{

     if (Input.GetKey(KeyCode.A))

   {

       transform.Rotate(UnityEngine.Vector3.forward * rotationThrust * Time.deltaTime);

   }

    else if (Input.GetKey(KeyCode.D))

   {

       transform.Rotate(-UnityEngine.Vector3.forward * rotationThrust * Time.deltaTime);

   }

}

}

1 Like

Hi there!

I don’t see any issues with your code. Have you tried changing the value of rotationThrust in the Inspector? If it is set to 1, as indicated by your code, the thrust will be almost imperceptible.

The inspector thing was correct.

1 Like

I would suggest to spend a couple of minutes to debug this yourself. If necessary, rewatch the video. This will help you develop the skills you need for your future games after this course.

Also, if a problem is fixed, it would be great if you could briefly mention that the problem is fixed before intoducing the next problem. Otherwise, one might think that you suddenly have two problems. In programming, it is very important to do things step by step and to keep things organised because everything else makes debugging difficult.

1 Like

Is there a reason these lines are in your code?

idk, really. they were put there by the script maker i dont know what they really do

Remove them, save the script. That should fix the problem. Use only the namespaces Rick uses in his script.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms