- Home /
Shoot a bomb to mouse position smooth
I want to make that when I shoot that a sphere which I made goes smooth to my mouse position so like a cannon that is shooting, what I made yet is that it goes to my mouseposition but it's not like shoot it goes directly.
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.AddRelativeForce(Vector3.left * 20000000000f);
cannonTop.transform.LookAt(pos);
}
Please help me and aks question if you didn't understood me.
try lowering the force value at
ball.rigidbody.AddRelativeForce(Vector3.left * 20000000000f);
from 20000000000 to something like 200.
Some questions :
What exactly happens, and from what is spot.position the position?
Answer by helloiam · Mar 23, 2013 at 10:55 PM
http://imageshack.us/photo/my-images/69/bombc.png/ <--- image of my project
What I want to do is shoot forward with the cannnon and hit other objects what is falling down on screen.
It is working if I work with ( ball.rigidbody.MovePosition(Vector3.Lerp(spot.position, pos, fracJourney)); ), but what it does then it creates direct a cannonball on my mouse position.
What I want is that when I click that it goes from a beginning point which is in front of the cannon and then it's shooting from my cannon to my mouse position (of course when I click). And of c oouse the ball is going smooth like it's shooting to my mouse position, my code does a little but it needs more work but hopefully you guys can help me out with this issue, thank you all!
Did you even read my answer/question? Do you have an empty gameObject in front of you cannon where you can spawn the the projectile ?
spot.position is the begin position so where the projectiles must spawn, take a look of this picture: http://imageshack.us/photo/my-images/69/bombc.png/
Your answer
Follow this Question
Related Questions
Smooth platformer Movement (horizontal) 0 Answers
Smooth Move script for my spaceship 0 Answers
smooth motion 1 Answer
How do I spread a movement over several frames instead of one? 1 Answer
moving a ball when touch 0 Answers