- Home /
How to speed up?
I made a bow what shot an arrow and i want to the arrow stop when collision with a wall the arrow's script is now:
#pragma strict
function Start () {
}
function Update () {
}
function OnTriggerEnter (other : Collider) {
rigidbody.isKinematic = true;
}
but sometimes its move through the walls and stop in the middle of the room in the air. Help me please Sorry for my bad english :)
And what is the piece of code you've used to actually move the arrow? The code above does not offer much info to go about.
function Fire()
{
animation.Play("PullAnim");
BulletSpeed += 100;
if(BulletSpeed == 5000){
animation.Play("FireAnim");
var Bullet1 : Rigidbody = Instantiate(Bullet, Spawn.position, Spawn.rotation);
Bullet1.AddForce(transform.forward *BulletSpeed);
BulletSpeed = 0;
CanFire = false;
Ammo -= 1;
yield WaitForSeconds(0.1);
CanFire = true;
BulletSpeed = 0;
}
}
So when you shoot, your bullets' speed is 100 but it doesn't do anything. When the speed of the bullet is 5000 you instantiate a bullet rigidbody and add force to it but you set your bulletspeed back to 0, twice. Shouldn't the bullet speed remain constant until colliding? Therefore when it reaches the wall it will stop moving?
Answer by robertbu · Jun 15, 2013 at 02:13 PM
Getting something to stop immediately turns out to be a somewhat hard problem, and I could only come up with a couple hackish solutions. The immediate issue may be solved by reducing the Fixed Timestep. From the edit menu, select Project Settings/Time. Reduce the Fixed Timestep from 0.02 to 0.01. As for other movement see this answer:
http://answers.unity3d.com/questions/462907/how-do-i-stop-a-projectile-cold-when-colliding-wit.html
Good solution!
Although, wouldn't it be easier for him to create a new speed variable which he could set to 0 at any time he would like the object(arrow in this case) to stop?
^_^
@Eugenius - unfortunately setting Velocity to 0 at the time OnCollisionEnter is called does not instantly stop the object. There appears to be a single frame of update.
Answer by PAHeartBeat · Jun 15, 2013 at 12:20 PM
Just use Collider on your wall and don't use isTrigger Property as true. if you translating object by code, it will not stop in some cases, use rigidbody and apply force to your bow
Answer by Soumya · Jun 15, 2013 at 01:47 PM
Go to the arrow prefab and uncheck "Trigger".
Then , change
function OnTriggerEnter (other : Collider) {
rigidbody.isKinematic = true;
}
to
function OnCollisionEnter () {
rigidbody.isKinematic = true;
}
Also, if your arrow moves at a high speed , it will sometimes not detect collisions. Hope I helped :)