Question by
unity_7rrrr · Jul 04, 2019 at 09:51 PM ·
quaterniontransform.positionrandom.rangetransform.rotationvector3.movetowards
Random move,Random move and rotation
Hi, i want to do that an object have a random move and rotate, but i don't know why always the object start moving to 0 0 0 and then random
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class random : MonoBehaviour {
public float speed;
public float speedr;
private Vector3 follow;
private Vector3 giro;
public float a;
public float b;
public float c;
public float x;
public float y;
public float z;
void start(){
a = Random.Range(0, 120);
b = Random.Range(0, 120);
c = Random.Range(0, 120);
x = Random.Range(-4.00f, 4.00f);
y = Random.Range(0.70f, 4.50f);
z = Random.Range(-4.00f, 4.00f);
follow = new Vector3(x, y, z);
giro = new Vector3(a, b, c);
}
void Update(){
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(giro), Time.deltaTime * speedr);
transform.position = Vector3.MoveTowards(transform.position, follow, Time.deltaTime * speed);
if (transform.position == follow){
speed = Random.Range(0.25f, 0.50f);
a = Random.Range(-180, 180);
b = Random.Range(-180, 180);
c = Random.Range(-180, 180);
x = Random.Range(-3.00f, 3.00f);
y = Random.Range(1.00f, 3.50f);
z = Random.Range(-3.00f, 3.00f);
follow = new Vector3(x, y, z);
giro = new Vector3(a, b, c);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
transform.rotation spazes out 0 Answers
object referance not set to instance of an object when accessing transform.position 0 Answers
Get camera position back to starting position 0 Answers
Instantiate a GameObject randomly between 2 rotation values 1 Answer
Velocity of parent local to child 1 Answer