|
So I'm working on my rocket launcher in my 3rd person shooter. I'm trying to get it so the rocket launcher fires the rocket and it flies at my target gameobject (which is a GameObject that is constantly moving, to a position based off a raycast from the center of my 3rd person camera). Here's how I currently have my rocket launcher script:
My problem is, the initialSpeed variable doesn't actually effect the speed of the rocket at all. As far as I can tell, it doesn't do anything. If I take away the .normalized on the direction variable, the behavior of the rocket is really strange: It will fly slower or faster depending on how far away the target is (so if i'm aiming at a far away wall the rocket will go impossibly fast, but if I aim at the ground in front of me it goes as slow as molasses). What am I doing wrong? How could I get my rocket to travel to my target GameObject at a set speed that I have control over?
(comments are locked)
|

How does the code that actually steers the rocket towards the moving target look? This code is executed only once when it's fired, so it affects the movement only on the first frame.
Sorry, I should had clarified. It is not a "moving target" in the sense that I want the rocket to home on the target, I just meant the target is not stationary (it moves when the player changes where he is looking).
The code looks basically OK, and if you don't normalise the direction you will indeed get a different speed depending on how close the target is. Try declaring initialSpeed explicitly as float and set its value in the inspector.