- Home /
Duplicate Question
Last time cannonball fire physics.
Hi guys I want to create a game that when I click on the screen a ball goes smoothly to my mouse position, I did a little scripting and it works but what this script of mine does is when I click on the screen it is going immediately to my mouse position, what I really want is that you have a begin position like in the middle of the screen and then whe I click it goes to my mouse position, so my mouse position is the end.
See this video to understand my problem: http://www.youtube.com/watch?v=gzdI4HmsF0Q
NOTE:
spot.position is the position is the begin position and pos is the end position. I did tried Vector3.lerp and .MovePosition and I tried AddForce but with Vector3.Lerp and MovePosition it works but as i wrote before it goes immediately to the end point which is my mouse position I want that it goes like this video:
http://www.youtube.com/watch?v=c27BK927-TE
Please take a look and help me out, this is really important for me.
Thanks in advance guys!
A little script of mine:
void shootInput()
{
cannonShot.Play();
journeyLength = Vector3.Distance(spot.position, pos);
float distCovered = (Time.time - startTime) * 20f;
float fracJourney = distCovered / journeyLength;
depth = 15f;
pos = Camera.main.ScreenPointToRay(Input.mousePosition).GetPoint(depth);
Rigidbody ball = Instantiate(cannonBall, spot.position, Quaternion.identity) as Rigidbody;
ball.rigidbody.MovePosition(Vector3.Lerp(spot.position, pos, fracJourney));
// ball.rigidbody.AddForce(transform.forward * 200);
// ball.rigidbody.AddForce(transform.up * 500);
cannonTop.transform.LookAt(pos);
}