Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Undead Pixel

Discussion in 'Works In Progress - Archive' started by TylerPerry, Jul 1, 2012.

?

Which version?

  1. Story

    7 vote(s)
    21.9%
  2. Survival

    5 vote(s)
    15.6%
  3. Survival2

    7 vote(s)
    21.9%
  4. Hybrid

    13 vote(s)
    40.6%
  1. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    I though what I'd do is make a thread for a game I'm working it is a zombie FPS but with some pixely goodness to spice things up :) though it is still very much in development and views of the early builds are a invalid view of the finished product ;)(I am still looking for feedback though) but i am super exited so ill make this thread anyway :p

    Basically i have decided on nothing about the game, except that it is all sprite based (Like old doom etc.) and has zombies, i have some ideas on what the game will be like but they are not set in stone, i think having it free roam around a city with score keeping then it counts how long you last and how many zombies you kill before you die, around the city there would be weapons health etc to aid in your survival, you could ether just avoid zombies but then you would still not get a great score as killing zombies adds to your score, the zombies would spawn at a rate so not killing them would lead to you being over whelmed by zombies.



    Builds
    V0.01
    V0.02

    Other stuff
    Zombie turntable​
     
    Last edited: Oct 17, 2012
  2. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Latest Build
    V0.02
    Build Notes

    In this build you can just walk around, shoot zombies in a small world, but you cant be killed and nor can zombies
     
    Last edited: Jul 25, 2012
  3. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Reserved 2
     
  4. LeakySink

    LeakySink

    Joined:
    Apr 9, 2012
    Posts:
    141
    I know you said it's not representative but I thought I'd provide feedback anyway:

    *I would suggest using the Unity FPS controller rather than one you wrote from scratch.
    *There isn't enough visual feedback when you hit the zombies, there should be blood splatter or whatever.
    *It looks like you're changing the texture based on the number of times the zombie is hit, so if I shoot it in the right side of the head the left side looks blown off, that's a fine idea but you'll need to break the hitboxes up into smaller sizes for it to work consistently.
    *The art style is a good choice, the minecraft thing is big right now.
    *You stop shooting for a while (reloading?) but that isn't indicated to the player at all. If you're reloading there should be "reloading" text or an indicator on screen.

    Good luck!
     
  5. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Thanks, I am still looking for feedback even though it is not a finished project(i am going to modify the OP)

    I actually am :O but i intend to strip it down of the code i don't use.

    I will add this, some zombie flesh flying off ;)

    Hmmm, ill try and work that out :)

    Yer, plus i have always loved pixels and retro FPS :D

    I think this is just a problem with my script(or if it is when the red flash is infront of the gun then that is just because it is shooting)

    Thanks for the feedback :D
     
  6. yuriythebest

    yuriythebest

    Joined:
    Nov 21, 2009
    Posts:
    1,121
    this looks epic! if you can make the gameplay fun and also add a story (characters that say stuff, a general "point" to the what you are doing in the game that drives your actions ) this should be interesting.
     
  7. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Thanks :)

    Hopefully :D
     
  8. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Sorry, I have lots stuff happening so i haven't got much time to work on my game but i did manage to make a building texture.(it is 64x64) Also i am very interested in what frame rate people get in the webplayer version(in OP) soon i should make a far, far... far better performance i will do this by having all the zombies one mesh (and therefore use one material i hope?) as with lots of zombies i get a terrible performance, but with a super low amount of materials this should be no problemo :)

     
  9. ivanzu

    ivanzu

    Joined:
    Nov 25, 2010
    Posts:
    2,065
    Looks awesome!But on some places you could use some more pixels.
     
  10. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Thanks :)

    I have been resting :p so i haven't done much and now school is back on(And the time machine needs some tweaking ;)) so development will be at snail pace probably oh, and i have been doing some vertex color tests so that would have slowed it down, but over the past eons that i have been working i have made the zombie AI much faster and a new shop front:

     
  11. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    This is v0.02:


    LINK

    for a week it is not much to show but it has a kind of area, floor is now made so that is good :D I haven't worked on it that much because i don't know...

    I took away killing zombies, because i think it will be faster to when you shoot the zombie to death it they regenerates its health and moves to a spawn point, instead of the old system were you shot it to death and then it destroyed that one and made a new one at the spawn point.

    frame rate seems to be better, but not having occlusion culling in Unity free is a bit of a bummer.
     
    Last edited: Jul 25, 2012
  12. Khyrid

    Khyrid

    Joined:
    Oct 8, 2010
    Posts:
    1,790
    I like the pixel graphics and the amount of pixels is fine, the problem is not that you need more pixels on the gun and enemies, it's that you need more contrast. The gun kinda disappears into the house texture. The enemies are very desaturated, consider making their outline slightly darker to help them pop more. You might actually need to shrink the gun and add more pixels to give it an outline. Also the brains need an outline.
     
  13. ivanzu

    ivanzu

    Joined:
    Nov 25, 2010
    Posts:
    2,065
    I would replace brains with hearts similar to minecraft ones.Gun needs more pixels right now it looks like a stick.
     
  14. Rush-Rage-Games

    Rush-Rage-Games

    Joined:
    Sep 9, 2010
    Posts:
    1,997
    Great idea, I like the look of it!
     
  15. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Well i though i should post something sense i haven't in like 4 weeks, the reason i haven't posted is because i have been super busy in my school and stuff :( this and the fact i wrecked all my wall prefabs makes for a really annoying few weeks :(

    But sense i haven't posted anything this is a screenshot of it at the moment(The only thing that has changed is the health are not as squished and the prefabs broke :'( wrecking the textures :():

     
  16. the_motionblur

    the_motionblur

    Joined:
    Mar 4, 2008
    Posts:
    1,774
    That is by far the coolest and most original thing I've seen from you. Keep that project up :)
     
  17. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,041
    Looking very cool, it has the kind of quirky look that could get you some notice ... if the gameplay is good ... make it good! :)
     
  18. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Thanks guys :D haven't really touched on game play to much yet.. once i get the basic graphics down that is when i will start.

    I know lots of people say that graphics don't matter so much until the game is done, but i strongly belief that the graphics could make the game play be strange if they are not right, like i don't think this style would fit with a fully serious horror zombie game.
     
  19. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    This post was to long so i just removed all its content :D

    (it was crap anyway :D)
     
    Last edited: Aug 28, 2012
  20. keithsoulasa

    keithsoulasa

    Joined:
    Feb 15, 2012
    Posts:
    2,126
    Looks very cool !, I wouldn't make it into a priority since its very hard to do but look into possible online multiplayer . Photon lets you do 20 players at a time for free , so look into it .


    Very good work though
     
    Last edited: Aug 28, 2012
  21. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Thanks, multiplayer is something i have been thinking of, it would be fun to have in this environment... but it would be hard, so for now it is something that will probably never be implemented :(

    Thank you :D
     
  22. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    I have decided to try and do a post daily for what i have done (mostly not much :p)

    Today i made 64 materials :eek: that is because I have 512x512 texture that holds all the shop/house textures, which are 64x64 each, so 8 of them fit along the X and 8 along the Y so it ends up with 64 textures possible on the one map, to bad it seems prefabs can't be copied and pasted in windows explorer(without breaking them) so it will be much harder making the 64 prefabs :( but that can wait for another day :D:D:D:D
     
  23. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Keep up the good work, always thought you make excellent pixel art : )
     
  24. AndrewGrayGames

    AndrewGrayGames

    Joined:
    Nov 19, 2009
    Posts:
    3,821
    It's possible to have pretty good networking using the built-in Unity. When I was building Onslaught of the Laser Cat, no one who tested/played it reported any issues with connection, really.

    In your place, I would just use the M2H Networking Tutorial to roll your own network system.
     
  25. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Ill look into networking when i have some free time, i'm just not sure about how i could make the zombies all be in sync and not have it running really slow? They walk around randomly so if i was to just have players in each others worlds i'm rather sure the world will implode :O I will still look through what is possible.
     
  26. Shastafication

    Shastafication

    Joined:
    Aug 19, 2012
    Posts:
    51
    I don't know if I like it. The pixel art is cool but I don't know. Its missing something. It all just looks out of place to me.
     
  27. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    As of yet i haven't really done any mapping(The current map is temporary)... perhaps that is why it looks out of place?

    I have a question for every one, if this game what kind of multiplayer would you like to see? co-op were you have to team up and kill zombies?
     
  28. AndrewGrayGames

    AndrewGrayGames

    Joined:
    Nov 19, 2009
    Posts:
    3,821
    I don't think a zombie game is complete without co-op multiplayer. Tell me, have you played Left4Dead? That might have some inspiration, for when you get to that point.

    I do think that you should get your single-player campaign in top-shape though...avoid scope creep, it's killed more than one of my aspiring projects!
     
  29. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    I agree, start with making single player complete, then add multiplayer if you want any chance of completing the game : )
     
  30. Mander

    Mander

    Joined:
    Jul 12, 2012
    Posts:
    68
    it looks and feels great man, good job.

    and yeah there are some great networking tutorials for pc check them out.


    just some ideas: more guns would be awesome too. reload animation, shooting animation, maybe some running faster animation for a couple of seconds, bigger maps, obstacles, different lvl enviroments(destroyed lab map would be cool :p), etc.
     
  31. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    I have decided to

    Thanks :), in the final release there will be a selection of guns and weapons, each including animations(reload shoot/attack) hopefully you will be able to sprint for a short time this along with a open world map that is quite large including many sub areas (maybe a lab :p)

    I will be developing the single player one first but keeping in mind the multiplayer one so that resources can be reused :D

    No I haven't played Left4Dead, i have it though... if i get time ill play it a bit :D one day. Ill be sure to make the single player as good as i possibly can :D
     
  32. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Today I made masive improvements to the zombies, they run much much much faster now, i changed it from an update funtion to an invoke reapeating and it worked wonders :D

    https://dl.dropbox.com/u/52409681/Zombie/FastAI/WebPlayer/WebPlayer.html

    That is the link, I was wondering how many people can spawn before it lags? I can get around 150.

    (Sorry for quick post i'm being pressured to go to bed :()
     
  33. sirenpro

    sirenpro

    Joined:
    Apr 6, 2012
    Posts:
    97
    I like the art style, stay with this project, sometimes you may go weeks with little progress but I'm telling you this has potential! Great work.
     
  34. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Thanks :), Unfortunately my school takes up far to much time :( It doesn't leave much time to do much during the week and recently I have had to much to do on the weekends to have much time.
     
  35. unitrade

    unitrade

    Joined:
    Aug 27, 2012
    Posts:
    20
    hey interesting work you have done there. and you can improve this with so many ways. would like to see more characteristics
     
  36. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Thanks :D,


    Over the past few days I've done a road texture and made the road layout for the world!



    This is a screenshot of the road, and 100zombies in the level :p(runs at 20fps):





    The game is based in a post apocalyptic city infected with zombies, in order to stop them from excaping a wall is built surrounding the city(this makes bounds for were the player can go) this will be located around the outer road.
     
  37. Myhijim

    Myhijim

    Joined:
    Jun 15, 2012
    Posts:
    1,148
    Just asking? Why does it run at only 20fps?

    I thought it would run at 60+
     
  38. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Because, the zombies are quite CPU taxing in there AI, there are over 100 of them which is never easy :O and the world is large. In the actual game there probably wouldn't be that many at a time coming at you.

    Actually, it seems that transform.lookat is very taxing :O so I don't know it only happens when they are chasing the player, if they are just wandering I get around 50-100FPS.
     
  39. Myhijim

    Myhijim

    Joined:
    Jun 15, 2012
    Posts:
    1,148
    Hmm are you caching your GetComponents?

    You could also delay it so it only runs every so often?

    P.S
    Love the pixel style, are you going to make this a fully fledged rpg?
    Friendly AI and such?
     
    Last edited: Sep 3, 2012
  40. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Yer :(

    I already am, it only happens like 10 times a second instead of every frame.

    Thanks :D Yes once the game is finished it will hopefully have friendly characters and a story to play through :D
     
  41. AndrewGrayGames

    AndrewGrayGames

    Joined:
    Nov 19, 2009
    Posts:
    3,821
    Consider refactoring your AI, if that's what's taking the most CPU cycles; you may have some redundant actions that could be refactored into a pre- or post-step, which will give you possibly a millisecond per agent.

    Also, flowchart your AI a bit, see if you can reduce the number of instructions for any state (I'm just assuming your AI is some sort of state-based machine). Possibly you could get another millisecond or two that way as well.

    Tuning an AI is tough, especially in a scenario like yours...
     
  42. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    I can't see anything else that could be made better :(

    This is my AI code maybe someone else can see some ways of speeding it up?(It is triggered by "
    InvokeRepeating("main", 0, 0.1);" in a start function):

    Code (csharp):
    1.  
    2. function main ()
    3. {
    4. fwd = transform.TransformDirection(Vector3.forward);
    5. var hit : RaycastHit;
    6.  
    7.     if (GameController.Chase == true)
    8.      {
    9.       transform.LookAt(player.transform);
    10.      }
    11.  
    12.     else if (Physics.Raycast (transform.position, fwd, hit))
    13.     {
    14.      if (hit.distance < 10.1)
    15.      {
    16.       if (hit.transform.gameObject == player)
    17.        {
    18.          //Debug.Log ("Grrr Brains!");
    19.          //shreak here
    20.          GameController.Chase = true;
    21.        }
    22.       else if (hit.distance < 1.1)
    23.        {
    24.          transform.Rotate (0,transform.rotation.y + Random.Range(0,360),0);
    25.        }
    26.       }
    27.      }
    28.  
    29.   fwd = transform.TransformDirection(Vector3.forward);
    30.   controller.SimpleMove(fwd * speed);
    31. }
    32.  
     
  43. AndrewGrayGames

    AndrewGrayGames

    Joined:
    Nov 19, 2009
    Posts:
    3,821
    First things first - you're using RayCasts. There's a performance hit right there, as those tend to be a bit expensive; I learned this the hard way when building SHMUP: Orbital Combat.

    What I've found effective is to create a trigger around your AI entity, with a script that, when an entity enters this sensory trigger, if the entity is not on the same team as the AI-driven entity, set the detected entity variable.

    Your AI script above, instead of using a nasty-slow raycast, can have a reference to this sensory trigger. If that sensory trigger 'sees'/'hears'/'senses' something, rotate towards it.

    An additional benefit - you can tune detection in the editor, not by some arbitrary number. If you want your entities to have great vision, but crap-poor hearing? Just make a thinner line of sight in front of the entity; if you want something with crappy sight, but great hearing, make a limited sphere centered on the entity.

    When I get home from work, I'll put up a couple of scripts that I'm using in Thora to that very effect - those would probably be very helpful to you.
     
  44. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Smart : )
     
  45. AndrewGrayGames

    AndrewGrayGames

    Joined:
    Nov 19, 2009
    Posts:
    3,821
    As promised; try this on for size:

    SenseEntity:
    Code (csharp):
    1. public class SenseEntities : MonoBehaviour
    2. {
    3.     #region Public Fields
    4.    
    5.     public bool SensedPlayer = false;
    6.     public GameObject LastSeenPlayer;
    7.    
    8.     private List<Collider> observed = new List<Collider>();
    9.    
    10.     #endregion Public Fields
    11.    
    12.     #region Engine Hooks
    13.    
    14.     /// <summary>
    15.     /// When a collider enters the trigger, add it to the list.
    16.     /// If it's a player, set the SensedPlayer flag.
    17.     /// </summary>
    18.     /// <param name='who'>
    19.     /// The collider that entered.
    20.     /// </param>
    21.     public void OnTriggerEnter(Collider who)
    22.     {
    23.         observed.Add(who);
    24.        
    25.         if(who.tag == "Player")
    26.         {
    27.             SensedPlayer = true;
    28.             LastSeenPlayer = who.gameObject;
    29.            
    30.             Debug.Log ("A player entered the sensory trigger.");
    31.         }
    32.     }
    33.    
    34.     /// <summary>
    35.     /// When a collider leaves the trigger, remove from the list.
    36.     /// Then, determine if even one player is still seen.
    37.     /// </summary>
    38.     /// <param name='who'>
    39.     /// The collider that left.
    40.     /// </param>
    41.     public void OnTriggerExit(Collider who)
    42.     {
    43.         observed.Remove(who);
    44.        
    45.         if(who.tag == "Player")
    46.         {
    47.             SensedPlayer = observed.Count(x => x.tag == "Player") > 0;
    48.            
    49.             if(! SensedPlayer)
    50.             {
    51.                 LastSeenPlayer = null;
    52.                 Debug.Log ("The last player entity left the sensory trigger.");
    53.             }
    54.         }
    55.     }
    56.    
    57.     #endregion Engine Hooks
    58. }
    Map AI:
    Code (csharp):
    1. public class EnemyMapAI : MonoBehaviour
    2. {
    3.     #region Enumerations
    4.    
    5.     /// <summary>
    6.     /// Describes how the bot
    7.     /// reacts to knowledge of
    8.     /// the presence of a player.
    9.     /// </summary>
    10.     public enum Attitude
    11.     {
    12.         Ignore,
    13.         Retreat,
    14.         Attack
    15.     }
    16.    
    17.     /// <summary>
    18.     /// Describes how the bot
    19.     /// chooses waypoints.
    20.     /// </summary>
    21.     public enum WaypointHabit
    22.     {
    23.         StandStill,
    24.         FollowNext,
    25.         RandomPoint
    26.     }
    27.    
    28.     #endregion Enumerations
    29.    
    30.     #region Variables
    31.    
    32.     public Attitude ResponseToPlayer;
    33.     public WaypointHabit WaypointDecision;
    34.    
    35.     /// <summary>
    36.     /// The distance at which this entity chooses
    37.     /// a new waypoint.
    38.     /// </summary>
    39.     public float WaypointSwitchDistance = 1.0f;
    40.    
    41.     /// <summary>
    42.     /// The max difference that this entity can be rotated
    43.     /// toward something before this object is considered
    44.     /// to be facing that something.
    45.     /// </summary>
    46.     public float RotationMargin = 0.1f;
    47.    
    48.     /// <summary>
    49.     /// Speed at which this entity turns, in degrees per second.
    50.     /// </summary>
    51.     public float TurnSpeed = 15;
    52.    
    53.     /// <summary>
    54.     /// How quickly this entity moves, in World Units per second.
    55.     /// </summary>
    56.     public float Speed = 15;
    57.    
    58.     private SenseEntities _Sight;
    59.     private Waypoint _CurrentWaypoint;
    60.    
    61.     #endregion Variables
    62.    
    63.     #region Engine Hooks
    64.    
    65.     // Use this for initialization
    66.     void Start()
    67.     {
    68.         _Sight = (SenseEntities) transform.Find("Sight").GetComponent("SenseEntities");
    69.         _CurrentWaypoint = Waypoint.FindClosest(transform.position);
    70.     }
    71.    
    72.     // Update is called once per frame
    73.     void FixedUpdate ()
    74.     {
    75.         if(! OnHeroSpotted())
    76.         {
    77.             OnFollowWaypoint();
    78.         }
    79.     }
    80.    
    81.     #endregion Engine Hooks
    82.    
    83.     #region Methods
    84.    
    85.     /// <summary>
    86.     /// Follows waypoints, based upon the
    87.     /// decision model.
    88.     /// </summary>
    89.     private void OnFollowWaypoint()
    90.     {
    91.         // If we're not close enough, perform the move,
    92.         // but don't make a waypoint switch decision.
    93.         if(Vector3.Distance (transform.position, _CurrentWaypoint.transform.position)
    94.            > WaypointSwitchDistance)
    95.         {
    96.             MoveTowards(_CurrentWaypoint.transform.position);
    97.             return;
    98.         }
    99.        
    100.         switch(WaypointDecision)
    101.         {      
    102.             // TODO: Implement method to find next connected waypoint of least resistance.
    103.             case WaypointHabit.FollowNext:
    104.                 _CurrentWaypoint = ChooseNextWaypoint();
    105.                 break;
    106.            
    107.             case WaypointHabit.RandomPoint:
    108.                 _CurrentWaypoint = _CurrentWaypoint.ChooseRandom();
    109.                 break;
    110.            
    111.             default:
    112.                 return;
    113.         }
    114.     }
    115.    
    116.     /// <summary>
    117.     /// Reacts to players based upon attitude.
    118.     /// </summary>
    119.     private bool OnHeroSpotted()
    120.     {
    121.         if(! _Sight.SensedPlayer
    122.            || _Sight.LastSeenPlayer == null)
    123.         {
    124.             if(_Sight.LastSeenPlayer == null)
    125.             {
    126.                 _Sight.SensedPlayer = false;
    127.             }
    128.            
    129.             return false;
    130.         }
    131.        
    132.         switch(ResponseToPlayer)
    133.         {
    134.             case Attitude.Ignore:
    135.                 return false;
    136.                
    137.             case Attitude.Retreat:
    138.                 MoveAwayFrom(_Sight.LastSeenPlayer.transform.position);
    139.                 break;
    140.                
    141.             case Attitude.Attack:
    142.                 MoveTowards(_Sight.LastSeenPlayer.transform.position);
    143.                 break;
    144.                
    145.             default:
    146.                 Debug.Log("Unexpected aggression state observed: " + ResponseToPlayer);
    147.                 return false;
    148.         }
    149.        
    150.         return true;
    151.     }
    152.    
    153.     /// <summary>
    154.     /// Chooses the next waypoint to follow based
    155.     /// on what waypoint is easiest to follow.
    156.     /// </summary>
    157.     /// <returns>
    158.     /// The next waypoint.
    159.     /// </returns>
    160.     private Waypoint ChooseNextWaypoint()
    161.     {
    162.         Vector3 forward = transform.TransformDirection(Vector3.forward);
    163.        
    164.         Waypoint best = _CurrentWaypoint;
    165.         float bestDot = 0.000001f;
    166.        
    167.         foreach(Waypoint current in _CurrentWaypoint.Connected)
    168.         {
    169.             Vector3 direction = Vector3.Normalize(current.transform.position - transform.position);
    170.             float dot = Vector3.Dot(direction, forward);
    171.            
    172.             //Debug.Log("For Waypoint " + current + ", the DOT is: " + dot);
    173.             if ( dot >= bestDot  current != _CurrentWaypoint )
    174.             {
    175.                 bestDot = dot;
    176.                 best = current;
    177.             }          
    178.         }
    179.        
    180.         return best;
    181.     }
    182.    
    183.     /// <summary>
    184.     /// Rotates towards a given 3D point.
    185.     /// </summary>
    186.     /// <param name='position'>
    187.     /// Position.
    188.     /// </param>
    189.     private void RotateTowards (Vector3 position)
    190.     {
    191.         Vector3 facing = position - transform.position;
    192.         if(facing.magnitude < RotationMargin) { return; }
    193.        
    194.         transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(facing), TurnSpeed * Time.deltaTime);
    195.         transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);
    196.     }
    197.    
    198.     /// <summary>
    199.     /// Rotates away from a given 3D point.
    200.     /// </summary>
    201.     /// <param name='position'>
    202.     /// Position.
    203.     /// </param>
    204.     private void RotateAwayFrom (Vector3 position)
    205.     {
    206.         Vector3 facing = transform.position - position;
    207.         if(facing.magnitude < RotationMargin) { return; }
    208.        
    209.         // Rotate the game object.
    210.         transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(facing), TurnSpeed * Time.deltaTime);
    211.         transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);
    212.     }
    213.    
    214.     /// <summary>
    215.     /// Moves towards a given 3D point.
    216.     /// </summary>
    217.     /// <param name='position'>
    218.     /// Position.
    219.     /// </param>
    220.     private void MoveTowards (Vector3 position)
    221.     {
    222.         RotateTowards(position);
    223.         transform.Translate(Vector3.forward * Speed * Time.deltaTime);
    224.     }
    225.    
    226.     /// <summary>
    227.     /// Moves awya from a given 3D point.
    228.     /// </summary>
    229.     /// <param name='position'>
    230.     /// Position.
    231.     /// </param>
    232.     private void MoveAwayFrom (Vector3 position)
    233.     {
    234.         RotateAwayFrom(position);
    235.         transform.Translate(Vector3.forward * Speed * Time.deltaTime);
    236.     }
    237.    
    238.     #endregion Methods
    239. }
    This is the AI script in question. Sense Entities goes on the trigger, the AI script goes on the actual agent that will be interacting with the player. Hope this helps (yes, I know it's a lot of C#...but it's really not that bad. ;) )
     
  46. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
  47. Myhijim

    Myhijim

    Joined:
    Jun 15, 2012
    Posts:
    1,148
    No seriously. Raycasts will really screw up your system, I know from experience.

    While I was fixing up my destruction system It was getting very laggy, at first I thought it was the amount being rendered, however when I cut off certain aspects of the script I found my raycasts (because there were MANY objects) were seriously, seriously destroying my proformance, so I did the sane thing and cached the data. Not sure if this is applicable in your case, just comment out the raycast part and check with many instances.
     
  48. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Hmmm, it actually seems that it is none of these but instead getting the variable from "GameController.Chase" does anyone know any alternatives to a static variable or how to make it faster?

    Maybe someone would be so kind as to have a look at my source code? :)

    It is located here BUT! before using it, though all my scripts are free to use for what ever, the art that is in this can only be used for non commercial purposes (most likely this will change when the game is released but for now)

    (the unity package is untested but it should work)
     
  49. HJinkle

    HJinkle

    Joined:
    Sep 4, 2012
    Posts:
    8
    We can finally see what our hero looks like in first person!
    But now I wish I hadn't.... O__O
     
  50. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577