- Home /
Raycast Snapping Problem.
Hello there im looking for solution for snaping raycast problem so
here is the code
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(BoxCollider))]
[RequireComponent(typeof(MeshRenderer))]
public class MouseDrag : MonoBehaviour
{
Transform gridSize;
void Update() {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
float dist = 100;
RaycastHit Hit;
Vector3 targetPos;
if (Physics.Raycast(ray, out Hit, dist))
{
if (Hit.collider.gameObject.tag == "Floor")
{
targetPos = Hit.point;
targetPos.y += Hit.collider.GetComponent<Renderer>().bounds.size.y;
transform.position = targetPos;
}
}
}
}
so my problem is raycast is not accurate and not working corectly
http://g.recordit.co/8Hj9LT29h5.gif
if any help thx sorry for my bad english
Comment
Your answer
Follow this Question
Related Questions
Interaction with various objects 0 Answers
Add object OnMouseDown 1 Answer
Multiple Cars not working 1 Answer
Raycast instantiating object to grid 0 Answers
Dragging an object smoothly 2 Answers