Question by
xemega · Aug 08, 2019 at 07:28 AM ·
unity 2draycasthit2d
Cast Ray from GameObject to mouse drag locations,Casting a ray from gameobject to mouse position in 2D
I just started working with Unity and my game idea so to draw specific path for my character to move i
What i'm trying to do is the following ,
i want to click the mouse then drag to draw a path then, i need the output to be vector2[] of positions.
and when mouse is released i need to use those positions to move a game object in that path
I want to do this in 2D project, but i couldn't . i managed to do it in 3D as follows :
Plane plane = new Plane(Camera.main.transform.forward * -1, this.transform.position);
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
float point = 0f;
if (plane.Raycast(ray, out point))
targetPos = ray.GetPoint(point);
pointsArray.Add(targetPos );
and then use points in the array to move the object
My other questions is how to smooth the movement of my character, in 3D it instantly goes to the very last point in the array i dont want that .. i want it to move point by point
Comment