- Home /
Player shoot up in the air HELP
hey i having some problem with my player when he goes in walk animation he shoot strait up in the air but in idle (has hand down it shoots strait)
var bulletPrefab:Transform;
function Update () {
if(Input.GetButtonDown("Jump"))
{
var bullet = Instantiate(bulletPrefab, GameObject.Find("spawnPoint").transform.position, Quaternion.identity);
bullet.rigidbody.AddForce(transform.forward * 2000);
}
}
doesnt make much sense to me, sorry. You'll need to explain and show more if I should understand this.
Answer by seedoubleyou · Nov 17, 2011 at 04:58 AM
Uh, your post is a little confusing... Are you having a problem with the character not shooting in the direction his hand is pointing?
If so, you need to tell your code which way the hand is pointing. Here's how I do it:
var newprefab : GameObject;
newprefab = Instantiate(bulletPrefab, transform.position, transform.rotation);
The instantiated object should now be pointing in the same direction as the object it was spawned in. Then I apply force to the bullet object in a separate script, like so:
rigidbody.AddForce (Vector3.forward * 2000);
(And if that wasn't really the problem you were having, clarify your post a little...)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Why is my enemy stopping before it reaches the player? 1 Answer
How would you make your player freeze for a certain amount of time? 2 Answers
error CS1729: The type `UnityEngine.Rect' does not contain a constructor that takes `5' arguments 1 Answer
Network disconnect player 1 Answer