x


[Closed] 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);
} 
more ▼

asked Mar 21 '10 at 11:56 AM

yeoldesnake 1 gravatar image

yeoldesnake 1
549 15 18 22

The answer really depends on how you do player health and what you actually want to modify, so you need to be more specific.

Mar 21 '10 at 04:33 PM Jason_DB

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

Mar 24 '10 at 04:23 PM yeoldesnake 1
(comments are locked)
10|3000 characters needed characters left

The question has been closed Jun 27 '12 at 09:59 AM by yeoldesnake 1 for the following reason:

Other


1 answer: sort voted first

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.

more ▼

answered Mar 22 '10 at 05:39 AM

qJake gravatar image

qJake
11.6k 43 78 161

actually i have found a script in the wiki that prevents that , now on to the solution

Mar 24 '10 at 04:24 PM yeoldesnake 1
(comments are locked)
10|3000 characters needed characters left

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5096
x308
x248

asked: Mar 21 '10 at 11:56 AM

Seen: 2124 times

Last Updated: Apr 05 '10 at 07:01 AM