Monster shadow

VIDEO

Rotate an object in Unity [2021 Tutorial for beginners]

Description:
A simple way to rotate an object in Unity. I show you a variety of ways including rotation via player input. ❤️ Become a Tarobro on Patreon: https://www.patreon.com/tarodev ========= 🔔 SUBSCRIBE: https://bit.ly/3eqG1Z6 🗨️ DISCORD: https://discord.gg/GqeHHnhHpz ✅ MORE TUTORIALS: https://www.youtube.com/tarodev About Tarodev: Develop video games like a pro! Whether you're a beginner or a seasoned game developer, you'll find lots of useful tips and tricks to boost your development career. Visit the channel: https://www.youtube.com/channel/UCAg2py6olXgod71Ix06HnUQ
ADD A COMMENT

Ultimate Bluegrass Playlist Corporation
Zing! Like a laser beam.
joshua ocampo
handsome!
Xboxhaslag _69
Instructions unclear, granted bean the power of flight
Tarodev
I can only imagine 😜
Ashwin V
Thank you so much <3
Chunhui Ma
Here is the code: using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerMovement : MonoBehaviour { private Vector3 _rotation; [SerializeField] private float _speed; //public Rigidbody rb; void Update() { if (Input.GetKey(KeyCode.A)) _rotation = Vector3.up; else if (Input.GetKey(KeyCode.D)) _rotation = Vector3.down; else _rotation = Vector3.zero; transform.Rotate(_rotation * _speed *Time.deltaTime); } }
SpiceyBanna
it works when i hit play but when i load the world into test it doesnt
SpiceyBanna
@Tarodev when I hit build and test on my vr chat sdk before uploading to vr chat it doesn't work and it didn't work when I uploaded it either
Tarodev
What do you mean load the world into test? I'd love to try help you out
Michele Guardabasso
Can you please help me for unity3D I have an script that can rotate left, right, up, down game object when in the game I click with the right mouse button the selected object moves but also the other objects I would like to move one at a time
Michele Guardabasso
@Tarodev ca you please giv me you link for profile discord
Tarodev
@Michele Guardabasso No, but you can pop into my discord and ask somebody :)
Michele Guardabasso
@Tarodev I don't now as i can doing Have you facebook? so i can send my script if you can edit the script and write comments so I learn please
Tarodev
Okay so in the object script you would need to add a "selected" field, which turns true when clicked. Now in your rotate logic you need to check if its selected, if not - don't rotate. Hope that helps.
Astricle_Sky
how do can you make camera tilt when moving left or right in the z axis?
Walney moreira klein
hi, speak moviment tank and ship, gamers world of tank and world of warship ?
Biticalifi
I had been struggling with this for about 40 minutes, then after finally deciding on going to search it up, I watch some tutorials for about 30 minutes but they don’t help me then I find this! A 2 minute video, with extremely simple code that does what I want! Thank you so much man, this is a great video!
Tarodev
I'm here for you baby
Hasan KARAKOÇ
You are really amazing. You are really doing a good job! Please keep it!
İlyas Köse
Your content is so good.
Kevin Basel
This guy is amazing!! Clear and straight to the point. We needed a guy like him for some news Unity tutorial. Sub from me, GG!
Matthew Spencer
Thank you my guy :)
DurVids
You're knocking it out of the park with these tutorials. Short and to the point. Great stuff, thank yoU!!
noobcraft
Good opstical for 3d platform. I am also making a 3d platform so will help me :)
noobcraft
Thank you
Tarodev
A 3D platformer, aye? Good luck with it!
SEE ALL COMMENTS


Transcript:

all right let me show you how to rotate a shape in unity
all right let's create a new c script and call it rotator
open it up let's remove the start function as i
won't be using it let's serialize a new vector3
call it rotation now in the update function
access your transform and call the rotate function
pass in your rotation let's times it by time
dot delta time just to keep it consistent across all frame rates
and that's actually all you need for a simple rotate
script so let's just put the rotator on our shape
let's rotate it by 10 on the x 10 on the y per frame
and there you go and at runtime you can speed it up
you go really fast that but we can improve on this so go back to
your script let's serialize a float or
speed and now what we'll do is we'll multiply rotation
by speed by time dot delta time and
basically we'll keep this as a normalized
vector three so instead of instead of putting our speed in the
actual vector we'll put it in our speed um variable
here so now you can just speed it up from the
speed variable like that um
another thing you can do is actually rotate it by
input so you could say if input get k and we'll say a
what we'll do is we'll change our rotation equals to
vector 3 up else if we press d
down otherwise let's just set our rotation
to be zero and then we don't actually need the
serialized field here because we're not exposing it in the editor
back to unity speed up our rotation a little bit and there you go
left and right so if you learned something
leave a like subscribe and i'll see you next time