I am new in unity. Here is my scenario which I want to implement.
I have a enemy and a tower. Enemy collides with tower and move to the top of tower to escape from it. I am unable to move enemy at exact position of towers top.
here is my code:
void OnTriggerEnter(Collider collider) {
moveY = tf.position.y + 6; //6 is the height of tower
tf.Translate(0, moveY, 0, Space.World);
}
If I use position instead of translate it moves to towers top position, but I want to walk the enemy towards top of tower. Using translate moves enemy more towards bottom. Pls help me with this
You shouldn't be defining moveY in terms of the current position- Translate moves the object by a set amount, so you should just translate it by the amount you want it to move. I don't quite understand your code here- why is it inside an OnTriggerEnter? Basically, you shouldn't have the tf.position.y - you should just translate up by 6.
– syclamoth