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 /
This question was closed Oct 20, 2012 at 06:24 AM by Fattie for the following reason:

Too subjective and argumentative

avatar image
0
Question by RandomDeveloper · Oct 19, 2012 at 10:14 PM · sendmessageenemiescombat

Need A Combat System.

Hello, I have been trying to get a working combat system for my RPG for a while. I am new to unity and I cannot seem to get one working. I have decided to use SendMessage for the combat and I am really stumped. I have found some scripts on the internet that I am editing but I cannot get them to work the way I want them to. I need this script below to send a message to the enemies target that says damage where it says //attack if close enough. The script below is used by enemies.

 // Chasing And Attacking
 var target : Transform; //the enemy's target
 var moveSpeed = 3; //How fast the enemy is
 var rotationSpeed = 3; // How fast enemy turns
 var attackThreshold = 3; // Attacking Range
 var chaseThreshold = 10; // Enemys sight range
 var giveUpThreshold = 20; //  Distance when enemy gets tired
 var attackRepeatTime = 2000; // How fast the enemys attacks come
 var reciever : GameObject;
 
 private var chasing = false;
 private var attackTime = Time.time;
 
 var myTransform : Transform; //current transform data of this enemy
 
 function Awake()
 {
     myTransform = transform; //cache transform data for easy access/preformance
 }
 
 function Start()
 {
      target = GameObject.FindWithTag("Player").transform; //target the player
      reciever = GameObject.FindWithTag("Player").gameObject; //target the player
 }
 
 function Update () {
 
     // check distance to target every frame:
     var distance = (target.position - myTransform.position).magnitude;
 
     if (chasing) {
 
         //rotate to look at the player
         myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
         Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
 
         //move towards the player
         myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
 
         // give up, if too far away from target:
         if (distance > giveUpThreshold) {
             chasing = false;
         }
 
         // attack, if close enough, and if time is OK:
         if (distance < attackThreshold && Time.time > attackTime) {
             // Attack! (call whatever attack function you like here)
             attackTime = Time.time + attackRepeatTime;
                      // Replace 5 with whatever damage that enemy deals here
             reciever.gameObject.SendMessage ("Damage", 5.0);
 
         }

Here is the script that is used by the player. I need it to - the players health by the float that came with the message every time its repeated.

 var health = 100;
 
 function Damage(Damage : float){
 health -(Damage);
              }             
    if(health <- 0){
    print("Game Over");
    health = 0;
    Destroy (gameObject);  
 } 

This game will eventually be in multiplayer. If you can fix this then you are truly awesome.

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 Benproductions1 · Oct 20, 2012 at 04:16 AM 0
Share

If this game will be multiplayer, may I give you a heads up, that porting from local to network is a shit ton of work, if you han't started with networking in $$anonymous$$d... Holing information about the game state in many different objects, is the enemy of networking!! (just a heads up :) )

avatar image Shrandis · Oct 20, 2012 at 05:59 AM 0
Share

So what exactly isn't working the way you want? Simply saying "it doesn't work" won't attract many answers.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Cannot lock onto enemies after they have been killed 1 Answer

I have a problem inflicting damage to my enemies... It works when using it without an array but as soon as I I do put them in it gives me a "MissingMethodExpection"... Here is the code 0 Answers

When I kill one enemy, the rest disapear, but still shoot 1 Answer

A* Pathfinding, multiple enemies, moving target. Efficiency advice 3 Answers

How to respawn enemies after one is destroyed? 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