Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Jun 27, 2012 at 09:59 AM by yeoldesnake 1 for the following reason:

Other

avatar image
0
Question by yeoldesnake 1 · Mar 21, 2010 at 11:56 AM · bulletdamage

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); }

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jason_DB · Mar 21, 2010 at 04:33 PM 0
Share

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

avatar image yeoldesnake 1 · Mar 24, 2010 at 04:23 PM 0
Share

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

1 Reply

  • Sort: 
avatar image
2
Best Answer

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image yeoldesnake 1 · Mar 24, 2010 at 04:24 PM 0
Share

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

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges