- Home /
Other
Bullet scripting , i need help
I have created physical bullets and on collision i need them to acquire someones health then modify it How to aquire it and modify it in networked state?
function OnCollisionEnter (collision : Collision) {
var contact : ContactPoint = collision.contacts[0];
// Check that bullit is colliding with playa if (collision.collider.CompareTag ("Player")) {
//insert awesome HP reduction script here
// And destroy ze bullit
Kill ();
} }
function Kill () { // Stop emitting particles in any children var emitter : ParticleEmitter= GetComponentInChildren(ParticleEmitter); if (emitter) emitter.emit = false;
// Detach children - We do this to detach the trail rendererer which should be set up to auto destruct transform.DetachChildren();
// Destroy the projectile Destroy(gameObject); }
The answer really depends on how you do player health and what you actually want to modify, so you need to be more specific.
the question is how will i receive a value from something that my bullet collides to , i want to modify its health being a variable
Answer by qJake · Mar 22, 2010 at 05:39 AM
I realize this may not be an "answer", but how, specifically are you doing your bullets? Are they objects with rigidbodies that actually travel through the world at really fast speeds? If so, I've got some bad news... your bullets won't be very accurate. Let me explain.
When each frame is computed and drawn by the system, the physics subsystem calculates the new positions of all the objects that were "acted upon" by some force, and then it checks for collisions. But if your bullets are really really tiny, and they're moving really really fast, here's what's going to happen:
FRAME 1 ----------------------------
+--+
| |
. |PL|
| |
| |
+--+
FRAME 2
+--+
| |
|PL| .
| |
| |
+--+
The dot is the bullet, and the box is your player (or whatever bullets get shot by). It's going so fast, that it literally skips over the player and never collides with it, because the physics calculations put it before, and then immediately after the player. There is no "in between", this happens in a few milliseconds, and the engine doesn't check to see if it might have collided with anything between those two points in space.
The solution? Use Raycasts. They are instantaneous lines that "hit" things at a specific point in space. Think of it like an instantaneous laser beam that collides with colliders in the world. There are various functions to drawing raycast lines in the world, and getting the data from whatever you hit, and so on. Look up "Physics.Raycast" in the Script Reference, it should tell you all you need to know about them.
actually i have found a script in the wiki that prevents that , now on to the solution
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How to add a bullet tracer effect to a raycast gun 1 Answer
Shooting Script Bullet Doesnt Fire 2 Answers
coliders are not working 1 Answer
Please, I need a damage script 2 Answers