I’m trying to make a script that when it a object hit the floor it will go up. but it’s currently not working. what are my errors?
public Vector3 currentDirection;
void Update() {
//Move object down
currentDirection = Vector3.down;
transform.Translate(currentDirection * Time.deltaTime);
}
void OnCollisionEnter (Collision col)
{
if(col.gameObject.name == "Floor")
{
currentDirection = Vector3.up;
transform.Translate(currentDirection * Time.deltaTime);
}
}
}
/sigh… try to give more information rather than here’s my script, whats wrong with it.
what behavior are you seeing?
by the look of it, it will always move down, never up.
dont set currentDirection = vector3.down in Update. It just overrides the change to up.
put it in start…
ie
void Start()
{
currentDirection = Vector3.down;
}
void Update()
{
transform.Translate(currentDirection *Time.deltaTime);
}
//insert the collsion code here
I appreciate the the help. sorry to inconvenience you with lack of info?
you seemed to have managed regardless, so thanks.
no inconvenience… more of a ‘in the future’ thing. 