Hi there, im trying to apply force to a ball using the angle of a mouse drag, so essentially the ball always travels parallel to the mouse drag.
Like this:
I know i need to store the two vectors of the mouse down and mouse up, but im not sure how to apply force to the ball in the same direction no matter where the mouse drag is done.
void Update()
{
if (Input.GetMouseButtonDown(0)){
mousePosBefore = Input.mousePosition;
}
if (Input.GetMouseButtonUp(0))
{
mousePosAfter = Input.mousePosition;
}
mouseDrag = mousePosAfter - mousePosBefore;
}
You have your vector here.
If you want only the direction you can apply this:
@lstaff, UnityAnswers is bugging out so i cant type a comment. This works… sort of. I forgot to mention this on an Isometric game, so I’d like the click and drag on the screen to translate onto the X and Z movement of the ball. If I click and drag upwards it jumps the balls, I also get some other weird behavior.
For instance if I drag from behind the course, in the direction of the course, the ball shoots off the right side.