Question by
weedmastersr · Dec 28, 2015 at 02:11 AM ·
shootingprojectile
How to instantiate projectile at the right height?
My problem is quite simple I believe, but I'm a complete noob. I'm doing a third person shooter and I needed a very simple shooting script which lets my character shoot a prefab projectile out of its body. Well, it does that but the projectile instantiates at the foot of the character. I need it to be higher, at the level of the arms. If anyone could help me out with that, I would greatly appreciate it. Here's my script:
var projectile : Rigidbody;
var speed = 10;
var fireRate = 0.11;
var damage = 40;
private var lastShot = -10.0;
function Update () {
if(Input.GetButtonDown("Fire1")){
if(Time.time > fireRate+lastShot){
clone = Instantiate(projectile, transform.position, transform.rotation);
projectile.tag = "Bullet";
clone.velocity = transform.TransformDirection( Vector3 (0, 0, speed));
lastShot = Time.time;
}
Destroy(clone.gameObject, 3);
}
}
Comment
Best Answer
Answer by mikelortega · Dec 28, 2015 at 09:40 AM
Something easy would be tweaking the 10th row. Check this:
clone = Instantiate(projectile, transform.position + new Vector3(0.0f, 1.5f, 0.0f), transform.rotation);
Answer by weedmastersr · Dec 28, 2015 at 10:14 PM
Thank you so much! You are a life savior! It worked beautifully!