Hello, when I click the mouse, I want to move an object outwards from point A in the direction of point B at a set velocity. The game is 2D (along the ZX plane) with an over head camera, and I want point B to be wherever the mouse is clicked on the screen, how can that be done.
I have tried this;
var projectile : Rigidbody; var speed = 2; function Update() { if( Input.GetButtonDown( "Fire1" ) ) { var instantiatedProjectile : Rigidbody = Instantiate( projectile, transform.position, transform.rotation ); instantiatedProjectile.velocity = transform.TransformDirection (Event.mousePosition); } }
But using this just makes the object move in a weird direction (sometimes even at the camera) I have also tried to work in "Input.mousePosition" but I cannot get that to work. Thank you.
What I would probably do is throw a transform.LookAt(Camera.ScreenToWorldPoint(Input.mousePosition)); in between instantiate and velocity. Then I'd set velocity = transform.forward * speed;
– anon82646189