how to make an object move in unity
Vector3 input = new Vector3 (Input.GetAxis("Horizontal"), 0 , Input.GetAxis("Vertical");
Vector3 dir = input.normalized;
Vecotr3 vel = dir * speed * Time.deltaTime;
transform.Translate(vel);
how to make an object move in unity
Vector3 input = new Vector3 (Input.GetAxis("Horizontal"), 0 , Input.GetAxis("Vertical");
Vector3 dir = input.normalized;
Vecotr3 vel = dir * speed * Time.deltaTime;
transform.Translate(vel);
unity how to move an object
float x = 10f; //the x value for the object's position
float y = 10f; //the y value for the object's position
float z = 10f; //the z value for the object's position
Vector3 position = new Vector3(x, y, z); // this will create a vector with the values of the x, y, and z values
transform.position = position; //this change the object that this script is attached to position to the position vector that was created
How to move object up & down | Unity
//README!!!
//THIS ONLY MOVES UP AND DOWN IN A LOOP FOR THE Y AXIS.
//Just apply this script to a gameobject adjust it to your needs.
//The x, y, z speed of your object
public Vector3 Movement_Speed;
//When the game starts, will it be moving up or down?
public bool IsMovingDown = true;
//How long will it be moving up and down?
//Ex: 3f = 3 seconds of it moving up, then it will move down for 3 seconds
public float TimeToSwitchFromUpAndDown = 3f;
//A Fixed Update is a Updated that is called every fixed frame
void FixedUpdate()
{
//Just moves the object based on your speed you inputed
gameObject.transform.Translate(Movement_Speed * Time.fixedDeltaTime);
}
void Start()
{
//If you changed the y speed of the object then...
if (Movement_Speed.y > 0)
//start the method UpAndDown() that moves the object on the y axis in a loop
StartCoroutine(UpAndDown());
}
public IEnumerator UpAndDown()
{
//Change this while loop condition that will keep it running for as long as you need it
while (FindObjectOfType<PlayerController>().IsAlive == true)
{
//If it will move down then..
if (IsMovingDown == true)
{
//make it the inputed y value negative
Movement_Speed.y = -Movement_Speed.y;
}
//If it will move up then...
else if (IsMovingDown == false)
{
//make the inputed y value positive
Movement_Speed.y = 3;
}
//Look at TimeToSwitchFromUpAndDown varible at top of script
yield return new WaitForSeconds(TimeToSwitchFromUpAndDown);
//If it was moving down then...
if (Movement_Speed.y < 0)
{
//make MovingDown false so it moves up when the while() loops
IsMovingDown = false;
}
//If it was moving up then...
else if (Movement_Speed.y > 0)
{
//make MovingDown true so it moves up when while() loops
IsMovingDown = true;
}
}
}
//Hopefully there ain't any bugs!
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us