- Home /
FPS micrograme transform position of player
I am using the fps microgame template which provides a player entity to move around the level.
Goal
Right now I am trying to move the player to a different position via a collider object event. But when the event fires off nothing happens.
Debugging
I tried debugging it by just using a keydown function to manually force the position teleport but nothing happens. When I use a different GameObject like a cube it works. Also when using the keydown event I have to click random amount of times and it would finally teleport the player.
So right now puzzled what I am doing wrong
Here is the code I am using
public class LevelColliderNorth : MonoBehaviour
{
public GameObject player; // here I link the player entity from the scene
private void OnTriggerEnter(Collider other)
{
player.transform.position = new Vector3(22, 0, 28); // here the player should teleport back to this coordinates
}
}
Answer by curiousgamedev · Aug 09, 2020 at 09:05 PM
Solved it enabling auto sync transforms in project settings. Now the player is teleporting to the position properly.
Source: https://scholarslab.lib.virginia.edu/blog/teleporting-in-Unity3D/
Answer by HugoCortell_VFS · Aug 09, 2020 at 07:08 PM
That's a trigger, not a collider.
Try https://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html
EDIT: What do you have as the player, is it the root object, its controller? It matters whether or not it is a child or a root parent.
I assume it is the root. Here is a screen shoot. Regarding your comment you are right should actually use a collider and not a trigger. https://imgur.com/rX2GgAJ
Your answer
Follow this Question
Related Questions
Positioning gameobjects by a corner, not by center 0 Answers
How to align the bottom of a GameObject with the ground? 1 Answer
C# Script is affecting multiple GameObjects but I would like it to only affect one of them... 1 Answer
"Player" tag collider from other GameObject? 1 Answer
How do you make a game object into a controllable player? 2 Answers