How do I rotate the object?

Hi everyone!
I took a helicopter for an obstacle and want it to ‘patrol’ the territory. For that, at the extreme points of its path I want it to:

  1. Stop.
  2. Rotate by 180 degrees (not instantly - i want the rotation speed be a serialize field).
  3. Start moving in the opposite direction.
    My best result was that I made this copter flounce like mad (compared current position to the certain values and if it exceeded them the object just instantly turns 180).
    Can you help me with this please?

Hi Peter,

Since your idea is rather complex, it’s probably the best to use an animation to have the helicopter patrol, stop, rotate and continue to patrol. Animations are covered in this course.

If you want to do that via code, you could start with defining when the helicopter is supposed to stop. Then make it stop. You know if-statements and our extreme values are 0 and 1. Use Debug.Logs to see what’s going on during runtime because it is relatively unlikely that we reach exactly 0 and exactly 1.

I hope this helped. :slight_smile:

1 Like

Thank you Nina,

Yeah, it helped: I understood that it would be overkill for this section :slight_smile:

Well, it’s a bit too complex for an earlier section in a course catering to beginners. However, if you are willing to challenge yourself, you could try to solve this problem via code. The difficult part is to define the conditions. The code itself is rather simple because you know everything you need (if-statements, the relevant methods, etc.).

Animating is fairly easy if you already animated something in Unity. You could watch a little tutorial on Youtube.

Or you could write your idea down, proceed with the course and try to realise your idea at a later juncture. The helicopter definitely a nice and manageable idea. :slight_smile:

1 Like

Exactly, I’m stuck at determining exact angles. Otherwise it leaves the level and flies away somewhere into the eternal void :joy:

Maybe the RotateTowards method could help. You just have to define two points to which the helicopter is supposed to “look at”.

1 Like

Oh, at first glance it looks like what I’ve been looking for, thank you!

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

Privacy & Terms