- Home /
Look at object when entering a trigger
Hi, I am trying to get my player to rotate and look at the trigger (box) when entering the trigger.
Setup 1. Player 2. trigger
What happens 1. Player approaches trigger (just a box) and is e.g. 90 degrees forward from the player position. 2. Player smooth rotates and positions itself to look at the trigger (rotates 90 degrees).
Problem I have tried getting the triggers velocity and applying a smooth look at but it always looks at the triggers Z axis. This causes problems when re-entering the same trigger from another angle e.g. opposite side, as this causes the player to flip around e.g. 180 degrees?
Anyway im pretty much lost on what to do now. Hope this makes sense.
Example diagram
Any advice would be appreciated
Nick
Hi, Ill try and explain a little further as im not an expert in Unity so here it goes.
Ive attached another diagram to show you what i mean, i want the player to be able to enter (at any angle) into the 'trigger' and the player doesnt look in the same direction (Z) of the trigger, but just X. So the player finds 'Up Vector'. This would allow the player only to align on X. But its a 3D game so i realise this will make it alot more complex.
Any ideas? sorry if your answer is the way but i just wanted to be clear before trying.
Thanks for your time
Nick
One of the two player at the top can't exist. The X axis as to be on the other side of the ZY axis on one of the two.
$$anonymous$$y answer is wrong then. I thought the player would always look at the trigger's direction. But if it will turn based on the side he entered through it's way more complicated :)
I'll update my answer to something maybe more suited for you.
Answer by ABerlemont · Nov 25, 2013 at 02:38 PM
If you are trying to make your player look at the same direction as the trigger you should use in an Update()
Quaternion.RotateTowards(player.transform.rotation, trigger.transform.rotation, Time.deltaTime * lookAtSpeed);
It should take the shorter path in every situation.
Hope that helps
EDIT
You should cut your trigger in different little triggers. Each trigger will give a direction to the player when the player collide with it.
When the player will colide with A it will take the orientation of A (blue arrow) When the player will colide with B it will take the orientation of B ...
Would that work ?
EDIT typos