- Home /
I have a Block and I want it to go somewhere when walked into. The block is not going to the quardinets though
I have It going to X 176 Y 16 Z 127 But its going to X 5.681625 Y-328.1724 Z374.8713 There is absoluetley nothing there and its so confusing here is the code :`using System.Collections; using System.Collections.Generic; using UnityEngine;
public class NPCDestination : MonoBehaviour {
void OnTriggerEnter(Collider other)
{
if (other.tag == "NPC")
{
this.gameObject.transform.position = new Vector3(176, 16, 127);
}
}
} `
do have a parent object to that npcdestination object? because the inspector will always show you the local coordinates if there is a parent object.
THANK YOU I JUST RE$$anonymous$$OVED IT FRO$$anonymous$$ THE PARENT OBJECT IT WORKS!!!!
You should learn why it happens that way though.
Setting a position as a child will result in that position plus all other positions up the hierarchy. If you want a child transform to be set to a fixed world position, an easy fix is to temporarily set it's parent to null
var tempParent = transform.parent;
transform.SetParent(null);
transform.position = new Vector3(176, 16, 127);
transform.SetParent(tempParent, true);
Should I place the NPCDest into the NPC, Sorry I am a beginner.
Answer by JesseAtBlue · Aug 19, 2020 at 09:25 AM
I'm not experienced, but I can think of 2 things:
Maybe try using
this.transform.position
without gameObject?maybe the position is relative to another object instead of world space?
I hope this helped!
Your answer
Follow this Question
Related Questions
Objects with same position appear in different places 2 Answers
Offset against Rotated Object,Applying Offset to a Rotated Transform 1 Answer
GameObject won't move to Transform Position 0 Answers
How to make object stay certain distance above ground (relative o ground normal) 1 Answer
How to center prefabs' children to (0, 0, 0) without changing their position relative to each other 1 Answer