Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
1
Question by jirdano · Apr 06, 2012 at 05:58 PM · collisionnetworkingplayerfireball

How to make network player lose health after being hit by rigidbody?

Hi, im trying to solve this for three days by now, so i ask here:

I have a multiplayer game with working authoritative moving players. Whats also working well is network instantiating fireballs done by server on players request. When a fireball collides something, it succesfully Network.destroys itself by function OnCollisionEnter and spawns my explosion prefab.

But what i need it to do is that when the fireball hits "something" tagged as Player, he has to lose 1 health. I have tried around a hundred ways to make this happen, but not a single on was working.

Can anybody help me with this problem?

This is my working code attached to fireball that destroys the fireball itself:

 function OnCollisionEnter(collision : Collision) {
 // Rotate the object so that the y-axis faces along the normal of the surface
 var contact : ContactPoint = collision.contacts[0];
 rot = Quaternion.FromToRotation(Vector3.up, contact.normal);
 pos = contact.point;
 
 if(Network.isServer){
 Network.Instantiate(explosionPrefab, pos, rot, 0);
 Network.Destroy (gameObject);
 }
 

}

I have tried, for example to put into this code

 if(collision.gameObject.tag == "Player"){
     collision.gameObject.SendMessage("ApplyDamage");
 }

but it worked in one from five shots, or to put into Playerscript the OnCollisionEnter and if the tag is "Fireballshot", gave me pretty much the same result.

I also tried to try a trigger attached on the fireball and function OnTriggerEnter in the Playerscript and many other ways and im just desperate.

HELP!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jirdano · Apr 06, 2012 at 09:54 PM

ok, so i moved to this:

i have separate healthscript on player:

var maxHealth:int=5; static var curHealth:int=5;

function Awake(){ // We are probably not the server -> only server can control this script if(Network.isClient){ enabled=false; // disable this script
}else if(Network.isServer){ enabled=true; // enable this script } }

function OnCollisionEnter(collision:Collision){ if(collision.gameObject.tag == "FireballShot"){ if(Network.isServer){ collision.gameObject.SendMessage("DestroyYourself"); curHealth -=1; if(curHealth<1){ //Network.Destroy(gameObject); transform.position = GameObject.Find("SpawnRedTeam").transform.position; transform.rotation = GameObject.Find("SpawnRedTeam").transform.rotation; curHealth=maxHealth; } } } } would work well, only problem is that when one player hits another, the the health is lost on both players and i dunno why

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 jirdano · Apr 06, 2012 at 10:01 PM 0
Share

hey its just me again spam$$anonymous$$g my own thred :) i figured it on my own again, it was just about changing static variable to public, hope it helps somebody

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Help with getting script of another player 0 Answers

Network two players collision 2 Answers

How do I stop an immediate collision with all objects from ocuring at the entry of game mode? 0 Answers

Player Dies when Collide with enemy 2 Answers

UNET moving the players via the server. 1 Answer


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