Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

Advanced search

1285699 Posts in 56962 Topics- by 47902 Members - Latest Member: ninjavivi

March 23, 2017, 06:21:57 am

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsFeedbackDevLogsScraps: Modular Vehicle Combat - Vehicle combat with buildable vehicles
Pages: 1 ... 17 18 [19]
Author Topic: Scraps: Modular Vehicle Combat - Vehicle combat with buildable vehicles  (Read 40619 times)
Level 3

Some random guy

View Profile WWW
« Reply #360 on: August 20, 2016, 07:47:46 pm »

This week I've been mostly placing content in Gauntlet mode levels. I did make an SMG drone as a less deadly version of the the existing MMG drone:

I also made a little Unity editor prefab placer script which I'll share for any Unity devs out there.

In Unity, if you want to add things to a scene you usually drag prefabs from the Project window, which is really just a folder view. It works pretty well but it means that you need to switch around in folders to find things, and you also can't see the object while you're positioning it. Unity provides pretty good tools to customise the editor so I made a little custom window instead:

It lets you spawn arbitrary prefabs with the buttons, and it automatically raycasts to the ground and places things there. You can show a visual indicator for placing invisible prefabs, and there's an option to give things a random starting rotation. You could also rotate the selected object with the keyboard like in the gif above, but for some reason it often ran at like 1fps and was horrible to use, so I've removed that feature.

The code isn't anything special because it's just meant for my personal use in the editor, but I'll share it here as I think it could be useful to other unity devs. If you're using it, read the code comments as there are some changeable things within, but it should work as-is as long as you replace the paths in LoadPrefabList with your own:

using UnityEngine;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;

// GUI editor interface for easily placing a set of hard-coded prefabs on a map
public class SimpleThingPlacer : EditorWindow {
// Set in inspector. Have this enabled to give prefabs a random starting rotation
bool randomYRotation = true;

// Got prefabs that don't have a visual model? Put their GameObject names here to see a visual indicator when holding them
readonly string[] prefabsThatNeedVisualIcons = {"VehicleSpawner"};

// Your prefabs can be assigned to categories you define here, and will show up in these groups in the editor window
enum Categories { NonEnemy, Enemy, Group }

Dictionary prefabs;
GameObject curHeldPrefab;


protected void OnGUI() {
if (Application.isPlaying) return;
if (prefabs.IsNullOrEmpty()) LoadPrefabList();

randomYRotation = EditorGUILayout.Toggle("Random Y rotation: ", randomYRotation);

// This is pretty basic - could be modified to auto-set NUM_PER_ROW based on window width
const int NUM_PER_ROW = 3;
const int ENTRY_HEIGHT = 64;
const int ENTRY_WIDTH = 80;
foreach (KeyValuePair category in prefabs) {
bool isInRow = false;
EditorGUILayout.LabelField(category.Key.ToString(), EditorStyles.boldLabel);
List p = category.Value;
for (int i = 0; i ();

// Replace these with the paths to the assets you want to show up
// Or these hard-coded paths could be replaced by automatically loading all assets in a folder etc
// Or maybe create an interface in the editor window itself to add/remove prefabs
AddPrefab(prefabs, Categories.NonEnemy,  "Assets/Prefabs/Environment/SinglePlayerPhysicsDamageable/Walls/WoodenWall.prefab");
AddPrefab(prefabs, Categories.NonEnemy, "Assets/Prefabs/Environment/SinglePlayerPhysicsDamageable/Walls/ConcreteBarrier.prefab");
AddPrefab(prefabs, Categories.Enemy, "Assets/Prefabs/EnemyNonVehicles/Drones/MMGDrone.prefab");
AddPrefab(prefabs, Categories.Enemy, "Assets/Prefabs/EnemyNonVehicles/Drones/SMGDrone.prefab");
AddPrefab(prefabs, Categories.Group, "Assets/Prefabs/GauntletSets/GauntletEarthRoadblock1.prefab");

// Path should start with the Assets forlder, e.g. "Assets/Textures/texture.jpg"
void AddPrefab(Dictionary prefabDict, Categories category, string path) {
GameObject prefab = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)) as GameObject;
if (prefab != null) {
ISpawnedThing ist = prefab.GetComponent(typeof(ISpawnedThing)) as ISpawnedThing;
if (ist != null) {
if (!prefabDict.ContainsKey(category)) prefabDict[category] = new List(1);
else {
Debug.LogWarning("Couldn't find prefab at: " + path);

void CreatePrefab(GameObject prefab) {
curHeldPrefab = (GameObject)Instantiate(prefab);
// Remove any automatic "(clone)" designation
curHeldPrefab.name = prefab.name;
if (randomYRotation) {
Vector3 eulerRot = curHeldPrefab.transform.eulerAngles;
eulerRot.y = Random.Range(0, 359);
curHeldPrefab.transform.eulerAngles = eulerRot;
Selection.activeGameObject = curHeldPrefab;

void ReleaseHeldPrefab() {
curHeldPrefab = null;

// Returns true if the input transform or any of its parents, grandparents etc have the specified tag.
static bool HasTransformInAncestors(Transform trans, Transform match) {
if (trans == match) return true;

trans = trans.parent;
while (trans != null) {
if (trans == match) return true;
trans = trans.parent;
return false;

Level 3

Some random guy

View Profile WWW
« Reply #361 on: August 29, 2016, 12:04:37 am »

Last week I got a nice job offer that I've accepted, but it had to be a full-time position, so it's not going to leave much remaining time for Scraps unfortunately. It's an offer that I would be silly to ignore in favour of my obscure little game that I've already been working on for years without much success (income-wise anyway). Of course Scraps could take off in success after Gauntlet mode is added, or after it leaves Early Access, but historically that's very rare: Almost always if a game's sales are slow at first during Early Access, they remain a small-time thing at full release.

So I'm going to stop the current weekly news updates since development is gonna get real slow. I'll post whenever I have interesting new stuff to share instead.

Here's what I did in my last week of freedom:

I made some more level content. Yeah, I'm still on world 1, because I keep making things like tools for level building or things to put in the levels rather than actually putting things in levels. Subsequent maps should be way faster to populate, like how the terrains for worlds 2 and 3 were done much much faster than the terrain for world 1.

A thing I did this week in that vein was make a new type of vehicle spawner. I already had vehicle spawners that I could place on the map with a list of vehicles they could spawn. Looked like this in the editor:

When playing, they'd randomly select a vehicle to spawn from the list, and that worked OK. Gauntlet mode is sort of half procedural, half hand-placed, and it's important to be careful with how procedural it is. Fully hand placed would make it exactly the same every time, which would get boring fast. But fully procedural almost always ends up boring as well - a million variations on the same thing. No Man's Sky is the procedural game du jour to complain about, but there are many.

However, in this particular case I realised that there were many scenarios where I really just wanted a vehicle spawner that would spawn any vehicle I had that was appropriate for the current level. Same potential set for every spawner. On top of that, really the vehicles should get harder as you progressed to another level within the same world, but to do that currently I'd have to place multiple spawners and limit them to just the level they were intended for.

So I made a vehicle library that loads up all the vehicles I've put in a folder, and lets me select them with filters. For instance if I wanted a vehicle in a certain price range with only cheap weapons on it I could do:

vehicleLibrary.GetVehicle(VehicleFilters.TotalCost(minValue, maxValue),

Or for a vehicle in a certain price range with a small chassis:

vehicleLibrary.GetVehicle(VehicleFilters.TotalCost(minValue, maxValue),

"But writing code every time? That sounds like even more work than placing two spawners." Well yeah, it would be, but I made a new vehicle spawner that automatically detects which Gauntlet level the player is on and sets the appropriate filters. So there's no vehicle info to set in the interface at all:

And I can still use the old spawner type if I want specific vehicle options.

In other news, at one point I also accidentally broke everything in a fun way:


Level 3

Some random guy

View Profile WWW
« Reply #362 on: September 25, 2016, 12:41:29 pm »

The Unity engine has a built-in terrain system that's been around for ages. It's honestly pretty great actually, but it has a few quirks. The tree system is maybe the quirkiest part.

There's a special system for trees, separate from the one for placing glass and other detail stuff. Your trees must use two specific built-in shaders. Your trees must reside in a folder with the text "Ambient-Occlusion" in the name. They may have colliders, but other components on them will be ignored.

I tried the tree system out, I haven't used it before. It's got some nice features - for instance it'll automatically turn your trees into billboards at long distances to save rendering work (much like Jurassic Park: Tresspasser did way back in 1998). Although even that has its quirk - the billboards have a slightly different perspective to the meshes so they do some weird bending as they switch over.

I had it all working actually quite well, but the killer was the lack of support for custom components. The trees would have to be permanent; immovable. Scraps with indestructible trees? It wouldn't do.

Look at that realistic tree-smashing action (pls don't destroy trees IRL).

So anyway I added some trees.

(not to SandyBridge - I was just testing them there)

They're not using the special tree system. They're just meshes with a couple of LODs. LODs being levels of detail - showing the lower LOD at far distances. Works fine.

The trees I have actually came with two LODs already, but I wasn't exactly impressed. Does this look like a seamless transition to you?

The branches are fine. The leaves not so much. So I made my own low LOD versions that aren't particularly great either but everything looks OK.

I'm still adding level content. Each "world" in Gauntlet mode is big - but at least it does get reused for three levels. My new job is taking up a lot of time as I knew it would, but I'm still managing to get a little Scraps work done. See you next time.

Pages: 1 ... 17 18 [19]
Jump to:  

Theme orange-lt created by panic