Author Topic: Micah's Dev Snippet: Unity 5 and Crew On Ships!  (Read 2780 times)

Micah

  • BR Developer
  • 3D Artist
  • *****
  • Posts: 141
Micah's Dev Snippet: Unity 5 and Crew On Ships!
« on: March 04, 2015, 09:55:30 pm »
Unity 5 is out! I've also finished roughing-in crews on ships for the upcoming unity release!



It took a little bit to get Unity 5 downloaded and installed due to some issues on Unity's website, but I finally got into it yesterday afternoon and I'm really impressed with it so far. The two things that I am loving the most is the 64bit editor and pro features in the free version! I tried out the pro version of Unity a few months ago during the Angular Destruction Unity Release, which allowed me to do things like SSAO and see how atrocious my code was for CPU usage. Having those features again is very nice.

Angular Destruction


On to crews!

In this unity test, decks represent the different levels on the ships, with lifts in between. Just like the components, the decks, the lifts, and which decks are connected to the lifts, are assigned based on the name of their object. "deck_01" is a deck, and "deck_01t02" is a transition between deck_01 and deck_02.



Crew members can only move along the deck level in 2-dimensions. When assigned a new task on a different level, crew members check each available lift connected to the current deck, then that lift checks the deck it is connected to and then the lifts that are connected to that, and so on, until it finds the deck the the crew member's target component is on. After searching every possible route to the component, the script will pick the route with the shortest distance and use that to reach its target.



It should be understood that my method for pathfinding in Unity is going to be very different from how we'll do crew movement in BR. For instance, in my version of the pathfinding, the actual "deck" object is just a visual thing. There are no rooms, or walls, and there's nothing stopping your crew from going off the deck object, or through the ship.

Gabe is currently working on the way we're actually going to do pathfinding in BR, but for this Unity release, an approximation will have to do.



Now, as it turns out, having each crew member search through every possible route after every new task is given requires some CPU power. I didn't realize just how much until I tried out Unity 5's profiler.



I knew there would be some hitching due to this code but I didn't think it would be *that* bad. This spike was caused by ten crew members calculating their paths at once, but even a few at a time caused a noticeable hiccup. I thought of a couple ways to do it that might work better and faster, however, for now, I've added a parser that will add requests to calculate a crew member's path to a queue so that only one calculation happens per frame.



Spoiler

It's not the greatest solution, but it works for now and lets me get the feeling of crew without having to optimize it all that much.

Anyway, peoples on ships! I'm really liking how it feels to see crew scramble to repair components or man stations. What do you guys think?
"Could any man alive resist a fresh banana?"

Czorio

  • Founder
  • Residential nutbag
  • *
  • Posts: 685
    • Youtube Channel
Re: Micah's Dev Snippet: Unity 5 and Crew On Ships!
« Reply #1 on: March 05, 2015, 08:09:25 am »
Isn't this one of those things you can use Dijkstra's Algorithm for? I don't know how CPU intensive implementations of that particular algorithm are though.
"If you're in an equal fight, your tactics suck."

http://www.youtube.com/user/czorio4

Micah

  • BR Developer
  • 3D Artist
  • *****
  • Posts: 141
Re: Micah's Dev Snippet: Unity 5 and Crew On Ships!
« Reply #2 on: March 05, 2015, 07:57:20 pm »
Quote
Isn't this one of those things you can use Dijkstra's Algorithm for?
.. Yes. Yes you would. But that would work a lot better than what I've done.

Spoiler

It was important to me to work through the logic and to do the pathfinding myself, but this does make a lot of sense. It would definitely use less CPU than what I'm doing now and I'll probably redo my code in the future using this. Thanks Czorio!
"Could any man alive resist a fresh banana?"

Bladecatcher

  • Founder
  • *
  • Posts: 459
Re: Micah's Dev Snippet: Unity 5 and Crew On Ships!
« Reply #3 on: March 05, 2015, 09:09:52 pm »
Oh cool, I didn't realize crew members where going to be in this standalone. I'm looking forward to it even more now! Damn you.

Aaron

  • BR Developer
  • Creative Director, ZanMgt
  • *****
  • Posts: 2019
  • Available on the IRC from 9:00am to 5:00pm (EST)
    • http://www.zanmgt.com
Re: Micah's Dev Snippet: Unity 5 and Crew On Ships!
« Reply #4 on: March 06, 2015, 12:53:38 pm »
@Bladecatcher

Crews were meant for a future standalone, but it kind of ended up getting pushed into this test as it became apparent how critical the crew were to our combat flow.  We need to feel the targeting and manipulation of enemy crews and how it influences your combat strategies, and how it feels when you lose your own crew.  ::)
Stop by the IRC and say Hi! -- Online Dev Chat

Cy83r

  • Founder
  • *
  • Posts: 1254
  • It's Shooowtime!
Re: Micah's Dev Snippet: Unity 5 and Crew On Ships!
« Reply #5 on: March 08, 2015, 01:06:00 pm »
This standalone is shaping up to be a doozy, I'm impressed.  Keep up the excellent plugging.
Jibreel: Yeah but [Hufer] that's like [Axis] complaining that his Toyota Camry is stuck in the mud and you responding "Well my M1 Abrams doesn't seem to be having much trouble."

Aaron

  • BR Developer
  • Creative Director, ZanMgt
  • *****
  • Posts: 2019
  • Available on the IRC from 9:00am to 5:00pm (EST)
    • http://www.zanmgt.com
Re: Micah's Dev Snippet: Unity 5 and Crew On Ships!
« Reply #6 on: March 12, 2015, 01:51:58 pm »
@Cy83r Yes, quite the doozy!  Fills in a lot of the blanks for us though, and makes Zack Gabe and Nathan more confident in what they're hard-coding in for optimizations. =]
Stop by the IRC and say Hi! -- Online Dev Chat