- Home /
during build object moves different position than editor(vr)
hello, so currently I'm creating a simple drag and drop mechanic and I've come into an issue wherein editor the game mechanic works perfectly but during building the position of the object during drag shoots off consistently further away. I've done some research and people are saying local position vs world position but I have had no luck! if you need more information please let me know happy to provide it!
private void Awake()
{
Physics.IgnoreCollision(GetComponent<Collider>(), ship);
}
public void dragStart()
{
isDragging = true;
distance = Vector3.Distance(testcam.transform.position, transform.position);
previousPos = transform.position;
Debug.Log(meshDist);
if (isDragging)
{
StartCoroutine(Dragging());
}
}
private void Update()
{
Debug.DrawRay(worldOffset, transform.forward, Color.red);
}
public void dragEnd()
{
isDragging = false;
transform.position = previousPos;
}
IEnumerator Dragging()
{
Debug.Log(distance);
while (isDragging)
{
int _layerMask = LayerMask.GetMask("Path");
RaycastHit hit;
worldOffset = transform.position + Vector3.up * offset;
if (Physics.Raycast(worldOffset, transform.TransformDirection(Vector3.forward), out hit, _layerMask))
{
draggedPos = testcam.ScreenToWorldPoint(new Vector3(Screen.width / 2, Screen.height / 2, distance));
transform.position = draggedPos;
LastKnowPos = transform.position;
Debug.Log(hit.transform.name);
}
else
{
}
yield return null;
}
}
Answer by mossbeard1 · Oct 04, 2018 at 05:40 PM
Turns out use
new Vector3(testcam.scaledPixelWidth / 2, testcam.scaledPixelHeight / 2
that way it will dynamically get the screen resolution of your phone
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
GUIButton only executes once 2 Answers
just update X and Z position of gameobject 1 Answer
Setting transform.position not behaving properly 2 Answers
How to rotate an object to face the direction it's going? 1 Answer