- Home /
Bullet mouse control
I basically fire a cannon ball ( sphere ) with some forward speed and some torque to the ball so it makes a nice effect. But I would also like to controll this ball with the mouse while it is in the "air". For example when i drag left the bullet goes slightly to the left, and if drag up then it goes slightly up. How can i achieve this? Thank you in advance
Answer by Chik3r · Dec 27, 2018 at 11:57 PM
 void OnMouseDrag()
 {
            float velocity = 3.0f;
     Vector3 newPos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 1));
     newPos.z = transform.position.z;
     print("Distance: " + (transform.position - newPos));
     transform.position = Vector3.Lerp(transform.position, newPos, velocity * Time.deltaTime);
 }
This is a simple script I created to drag an object using the mouse. It's not the best, but its a starting point. If you want it to be slower, make velocity bigger.

Answer by Serge144 · Jan 04, 2019 at 10:43 PM
Thank you for your answer @chiker, but i've done differently like this:
 float x = Input.GetAxis("Mouse X");
 float y = Input.GetAxis("Mouse Y");
 rb.AddForce(Vector3.right * x * 50f);
 rb.AddForce(Vector3.up * y * 50f);
where rb is the rigidbody component of the cannonball. This was done on the FixedUpdate too.
Your answer
 
 
             Follow this Question
Related Questions
How can I manipulate an object with the mouse? 1 Answer
Dragged object keeping it's original rotation. 0 Answers
OnMouseUp() Click Display Effect. 1 Answer
Click and Drag Camera 3 Answers
Dragging movement Speed 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                