[Solved] Tween and/or Rotate Issue

How do I…

I need a tween or rotate function that doesn’t have a “hitch.” Essentially when the player uses turn left or turn right it should rotate that direction 90 degrees. As it is right now, what happens is kind of random. If you use the left turn, and just left, it will do it correctly 4 times and then it will rotate to the right 270 degrees on the 5 press.

If you use the right turn, It will do it correctly 3 times and then do the 270 left turn on the fourth try.

That is just for using one or the other, if you try and go back and forth and randomly do left and right turn it will work sometimes and sometimes it will 270 degree in the opposite direction.

What I need is consistent 90 degree left or right turns that take 1 second to tween or rotate. Whichever function works.

You can add or subtract 90° from the current angle value.

1 Like

Hi Davy.

That was actually what I tried first. For turning left it will work once and then just stops completely. I believe right turn it works twice and then stops completely.

This solution posted above does make all the turns, just with the occasional 270 counter rotation glitch.

Hi Davy,

Whoops. So, what I did before was try and use -90 and +90. I didn’t subtract or add from current tank angle. When I did that, surprise, surprise, it totally works!

Thanks!
t

Hey EatPoliticians, if the problem is solved, make sure to add “[SOLVED]” to the beginning of your post title if you still can!

Thanks!
– Snowy

Apologies, I am new. How is that done?

I love playing around with concepts. I also love minimal code.

I started using an object variable named TargetAngle to the tank. The premise is to increase or decrease the variable. Then calculate the tween time based on the difference between the current angle and the target.

I then put the buttons into a group named Buttons . This was a slight improvement.

My favorite version has an object variable for the buttons named Direction. The variable is -90 for left and 90 for right.

Depending on your needs, you could also add a condition to prevent the value from changing if there’s a tween. It’s all preference.

The value of 80 controls the turn speed.

1 Like

Um, this is awesome. This is where I want to end up. I’ve just started a couple of weeks ago but I want to get to where I approach these problems just like this.

I appreciate the code and thoughtfulness of it. Definitely learned something from this.

1 Like


There should be a pencil next to your topic name, you can edit it there. Unfortunately, since you are new to the forums, you might not see the pencil there. All good if it isn’t there, it’s just a way to help other members of the forum know it’s solved.

1 Like

Oh thanks, got it. I don’t have it yet, but hope to get to that level soon…or not, maybe that means I ask too many question :stuck_out_tongue:

1 Like