- Home /
help with vector3
I am trying to simulate bullet drop over time using vector3, I have already got bullet time but I get errors trying the bullet drop. what I am asking is can you or how do you make impactpos(Vector3) the hit point and times the Y axis by -bulletdrop?
function fire () {
//setting the var fwd2 to the foward position
var fwd2 = transform.TransformDirection(Vector3.forward);
//hit variable
var hit2 : RaycastHit;
//ray variable
var ray2 = new Ray (transform.position, transform.forward);
//detecting if there is a collition
if (Physics.Raycast (ray2, hit2, 100000)){
//making smoke from the barrel
Instantiate(smoke,transform.position,transform.rotation);
//setting the bullet time to 0.003 * the distance
bullettime = hit2.distance * bulletinterval;
//pointofhit = hit2.point; - trying other ways to get it to work
//get the bullet drop, drop * 0.003 or something as small
bulletdrop = hit2.distance * bulletdropamount;
//the single line that does not work - just trying to set the variable
//impactpos to hit2.point with extended vector3 so i can subtract the bullet drop
impactpos = hit2.point(Vector3(hit2.point.x, hit2.point.y, hit2.point.z));
// waiting for the time of the bullet to reach the target
yield WaitForSeconds(bullettime);
//creating the inpact for the explotion or other sparks
Instantiate(impact, impactpos, transform.rotation);
} else {
// makeing smoke even though that there is no target in sight to simulate a miss
Instantiate(smoke,transform.position,transform.rotation);
}
}
the error i am getting from unity is "It is not possible to invoke an expression of type 'unityEngine.Vector3'"
"It is not possible to invoke an expression of type 'unityEngine.Vector3'"
Answer by Jessespike · Oct 28, 2012 at 08:28 AM
impactpos = bulletpos(Vector3(hit2.point.x, hit2.point.y - (bulletdrop * bullettime), hit2.point.z));
Not tested, and the vars probably need to be swapped or using different signs. But basically you can calculate how much the bullet has dropped (gravity) by multiplying bulletdrop and bullettime. In this case, DropAmount = HowLongBulletHasBeenInAir * StrengthOfGravity; Then you subtract that from the y position of the impactpos.
I get an error "It is not possible to invoke an expression of type 'unityEngine.Vector3'"
Answer by zr0 · Oct 29, 2012 at 05:47 AM
it is all g i got the answer
impactpos = Vector3(hit2.point.x, hit2.point.y - bulletdrop, hit2.point.z);