Laser defender bomb spinning up into the air

Hi all,

I am so close to completing the Laser Defender section of the course. However, I tried to add a rotation to my ‘big boy’ enemy bomb, and I am seeing something totally different from the tutorial. Instead of falling and spinning, mine have started floating up while rotating around a central point. Here is a video of the behavior I’m seeing:

The code I have to move my bomb is the following:
void Update()
{
MoveDown();
}
private void MoveDown()
{
this.transform.Translate(Vector3.down * _speed * Time.deltaTime);
}

The code I have for the spin function, also attached as a script to my bomb is:
{
[SerializeField] float _speedOfSpin = 1f;
// Update is called once per frame
void Update()
{
transform.Rotate(0, 0, _speedOfSpin * Time.deltaTime);
}
}

I’m really not sure where to start, as I have no idea why Vector3.down would somehow change to an upward motion.

Hi Jackie,

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

If so, does the laser game object get rotated or a parent game object?

Try move down with
transform.position += Vector3.down * speed * deltatime

1 Like

Thanks so much 111100! That solved it. I found a good explanation for why here: https://answers.unity.com/questions/1089817/what-is-the-difference-between-translate-and-posit.html#:~:text=Translate%20will%20do%20a%20local,in%20the%20world%20up%20direction.

Now I know in the future if I’m going to be rotating things, to go ahead and use transform.position.

Nina, I did look at the code in the resources folder, but I have been using these courses as mini-challenges, so my implementation was quite a bit different than Rick’s. In this case, he used the Rigidbody of the laser to set the velocity downwards. My lasers do not have Rigidbodies, so I couldn’t use that method.

Thanks to both of you for your help!

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

Privacy & Terms