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
0
Question by Living_Dead · Mar 05, 2011 at 08:09 PM · fpsaizombiewaypoints

Spawner + AI control

Hello guys,

I'm busy with a Zombie game, And I bump into a few obstacles:

. . . . . . . . . . . . . . . . (FIXED) . . . . . . . . . . . . . . . . .

My weaponless zombies won't attack me, the'll just look at me. I don't know a way to make them hit me. (Close-combat, melee)

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Also, the waypoints in my map won't really work, they do not form square when I want them to, and the zombies are plainly walking over them, I'd like them to have a bit of a fully walkable track, like 3(meters?) wide, with as few waypoints as possible. I tried to put very much waypoints down, but it didn't work as suspected. they didn't make a nice line, but walked from waypoint to waypoint in a strange way (only x/z directions), which make it look very .. strange. I'd like them to move in a normal way.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

And last but (probably) not the least problem, I need to have a 'Pick-up' system, that when I walk over a gun, I can use the gun. (so propably something that hides the gun until I walk over a copy, then makes the gun visible for switching (like in the FPS tutorials, when you can switch between the various guns)..)

Anyone that can help me with one of the problems?

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

BTW, When you make a script or so, please do it in Java? Because I'm pretty much In my learning fase, and I'd like to know some more about it, Also I don't understand C sharp much, It wouldn't teach me much :)

(unless you are not able to, of course ;))

Comment
Add comment · Show 3
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 B · Mar 05, 2011 at 10:28 PM 0
Share

Not to contribute to any ongoing Javascript vs. C# wars that may be going on, but I would recommend keeping an open $$anonymous$$d about C#. $$anonymous$$any of the "elder" users on UnityAnswers seem to prefer C#, which is not me saying it is superior, I'm only saying that the majority of good answers that you get have a high chance of being written in C#. In any event, even if you don't want to learn C#, converting the languages is fairly simple. Just look up any functions from the code inside the manual, and switch between C# and Javascript until you understand how to translate them. They often operate similarly.

avatar image Living_Dead · Mar 06, 2011 at 04:45 PM 0
Share

@Jason_B,

I know, but I'm still busy exploring JS, Don't want to force myself into a hurry of learning both.

@unitydev0008, thanks for the code,

I merged it into my game and it works just fine ;)

again, Thank you for your time and help.

avatar image unitydev0008 · Mar 06, 2011 at 06:48 PM 0
Share

Glad to help out Living Dead, still workin on the weapon pickup stuff so ill post it when i can if its still unanswered, may be a few days tho as im rather busy =P

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by unitydev0008 · Mar 05, 2011 at 08:31 PM

One way you can handle the melee combat is to use Vector3.Distance to check the distance between the zombie and its target, if its below the melee range then attack.

Now you would also want some sort of a swing timer so the zombie doesn't attack every frame.

Note this is in C# but shouldnt be too hard to convert over to JS, im not familiar with JS sorry but it should also give you some knowledge having to convert it.

C# Example: // These would be assigned from within the editor public GameObject target; public float meleeRange; public float attackSpeed; public float damage;

private float attackTimer;

void Update() { // If within melee range attack the player if not move towards the player if (Vector3.Distance(target.transform.position, transform.position) < meleeRange) Attack(); else transform.Translate(Vector3.forward * moveSpeed* Time.deltaTime); // Or however you move your zombie here ^

}

void Attack() { // If attack timer is not on cooldown attack the target if (Time.time > attackTimer) { // Or place your code to handle the damage dealing here target.SendMessage("ApplyDamage", damage);

     // Resets the attackTimer so the zombie has to wait til next attack
     attackTimer = Time.time + attackSpeed;
 }

}

Asfar as the other two questions i am unsure of how you are handling the waypoints, and the weapon pickups is a little more involved. I am currently working on a project that should be in Asset store soon on making a top down zombie shooter which has weapon pickups like you are asking about, i may post the code for it here when i get it done if noone else has answered that part. (Just the weapon pickup code that is)

Hope this helps and it may not be the best way so if anyone else has a more effiecent way im all ears =P

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 Jason B · Mar 05, 2011 at 10:25 PM 0
Share

I'll "endorse" this answer. :P This is pretty much the way I would do it. If you want to get even more technical, you could ensure that the zombie is facing the player before initiating a melee attack, but this may work itself out naturally since zombies are fairly single-$$anonymous$$ded and probably not turned away from you... a simple way to do a distance and directional check in one is to fire a ray, but rays are precise to a fault in some instances, so this might not be desired.

avatar image
0

Answer by Living_Dead · Mar 07, 2011 at 06:57 AM

- Progress:
   - Attacking: **( FINISHED )**
   - Waypoints: **( FINISHED )**
   - Pickup:    **(   BUZY   )**


  • Attacking:

FINALLY GOT IT TO WORK!

Yay, now I'm happy :P problem appeared a time ago, It was actually a VERY simple and minor change. I had to change

var Target = GameObject;

into

var Target = transform;

Stupid I did not get that earlier... Actually a pretty stupid mistake :)

But GameObject is the same as transform right? only you need a Gameobject to put it in gameobject.

//******** .Js Scripts coming ********//


  • Waypoints:

I got happy with the actual result of doing nearly nothing. I haven't done anything strange to the Waypoints, just was joking around with the walking script of my zombie, then I made it make a small U-turn when I came to see it (16 rays * shaped). just lowering the turning speed and made it move while it turns.

//******** .Js Scripts coming ********//

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 unitydev0008 · Mar 07, 2011 at 09:24 PM 0
Share

Transform is a component of a GameObject, Reason I used target as a GameObject in my script is because i used a Send$$anonymous$$essage which requires the GameObject to send it to, cant be sent to a transform(that i know of) But yes using target as a transform works well too, just wasnt sure how you handled your damage. When you drag a gameobject over the variable Target which is a transform it is storing a reference to that GameObjects Transform component. Glad your making progress though =D

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

No one has followed this question yet.

Related Questions

zombie ai script 1 Answer

Follow Player Via Waypoints 1 Answer

Enemy AI Range Detection 3 Answers

FPS RIGIDBODY PROBLEM 1 Answer

Complete AI Tutorial? 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