- Home /
transform shooting forward
i have on my FPS transform.forward * 10000(the speed) but when i fire its always firing forward not up if im aiming up it just goes forward not up were im pointing.... please help :O
Answer by Proclyon · Dec 05, 2010 at 12:16 PM
To actually get a location of where to shoot you don't just give it the "forward" Vector.
Forward is always the same value. Increment along the x axis I believe, up being the Y axes and so on.
What you need is to extract the current location of what you "target" , assuming mouse by registering a position in 3D space (I assume) with for example Raycasting.
When you fire you register the input, that event triggers a script based measurement of the location. The location information is store in a Vector3 object. That information is now ready for use in determining the position between source and destination.
Source being point A and destination being point B you could do a Linear Interpolation (LERP) , or use Trigonometry to determine the forces required to get the correct angle. I am sure Unity has 89267892 functions for this of which I know zero. I usually just work with math, being all new to Unity and so. So please do look before doing that part yourself. The LERP function is part of the Mathf library I do know for a fact.
Well hope this gets the theory part covered for you. Sorry for not supplying a readily availabe answer but I don't have the time investement available for it now.
Good luck :)
Good to know you solved :) Don't forget to flag something as an answer if you think it is , and the opposite aswell. If something is totally not helpfull for anyone just vote down
Answer by FLASHDENMARK · Dec 05, 2010 at 12:06 PM
Hmm... dont know if it helpes but try:
bullet.rigidbody.AddForce(transform.forward * 10000);
At bullet type what ever your "bulletPrefab" is called, and your bullet needs a rigidbody.
Hope that helped:)
this is already in my script, i realized what i did wrong, it was firing the direction of the component the script was attached to not were the camera pointed, but thank you :D
Your answer
Follow this Question
Related Questions
Move an object forward and not up? 1 Answer
Rayshoot Reload Problem (Can still shoot) 2 Answers
Turn and Move Foward 1 Unit relative to Objects local direction 1 Answer
Findinga GameObject Transform 1 Answer
fps shooting enemy 1 Answer