irrationalistic

Members
  • Content count

    9
  • Joined

  • Last visited

Community Reputation

274 Neutral

About irrationalistic

  • Rank
    Newbie
  1. In most isometric-esque RTS-style game views, sometimes pesky walls can pop into view, hindering the player's connection with the protagonist. This isn't good but is easily solvable with many different solutions. One, highlight the player's outline when it is behind objects. Two, hide the interfering objects. Three, masking shaders to overlay over the screen. There are, of course, many other solutions, but I'll only explore these in this post through the use of Unity. Highlight The Player This method already has several existing code examples. Found on the UnifyCommunity wiki, the shader will draw an outline for the player or fill when part of the player is hidden: Silhouette-Outlined Diffuse This method is effective since it requires very little calculation and handles all possible situations. The con to this system is that you don't get a very good viewpoint of anything else on the other side of the wall including obstacles or enemies. Hide The Interfering Objects Another very simple execution with the right use of C# and/or shaders, this method will create a shader that adds transparency to overlapping objects and maintains visual understanding of the scene. First your script needs to detect all blocking objects. Just attach this to your camera and tell it to watch for the player, using walls and other hideable objects as the layermask. This will disable rendering the walls in the way, but you'll still collide with them. using UnityEngine; using System.Collections; using System.Collections.Generic; public class HideObjects : MonoBehaviour { public Transform WatchTarget; public LayerMask OccluderMask; private List _LastTransforms; void Start () { _LastTransforms = new List(); } void Update () { //reset and clear all the previous objects if(_LastTransforms.Count > 0){ foreach(Transform t in _LastTransforms) t.GetComponent().enabled = true; _LastTransforms.Clear(); } //Cast a ray from this object's transform the the watch target's transform. RaycastHit[] hits = Physics.RaycastAll( transform.position, WatchTarget.transform.position - transform.position, Vector3.Distance(WatchTarget.transform.position, transform.position), OccluderMask ); //Loop through all overlapping objects and disable their mesh renderer if(hits.Length > 0){ foreach(RaycastHit hit in hits){ if(hit.collider.gameObject.transform != WatchTarget && hit.collider.transform.root != WatchTarget){ hit.collider.gameObject.GetComponent().enabled = false; _LastTransforms.Add(hit.collider.gameObject.transform); } } } } } Use Shaders Finally, a nicer-looking option that retains shadows is to use shaders to de-occlude your walls. The shader is essentially adding transparency to the render while the object continues to cast shadows. The shader, which works wonders, was supplied by user ScroodgeM on UnityAnswers: Shader "Transparent/Diffuse with Shadow" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {} } SubShader { Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } LOD 200 Blend SrcAlpha OneMinusSrcAlpha CGPROGRAM #pragma surface surf Lambert addshadow sampler2D _MainTex; fixed4 _Color; struct Input { float2 uv_MainTex; }; void surf (Input IN, inout SurfaceOutput o) { fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; o.Albedo = c.rgb; o.Alpha = c.a; } ENDCG } Fallback "Transparent/VertexLit" } And the code that will toggle the shader in its basic entirety: using UnityEngine; using System.Collections; using System.Collections.Generic; public class HideObjects : MonoBehaviour { public Transform WatchTarget; public LayerMask OccluderMask; //This is the material with the Transparent/Diffuse With Shadow shader public Material HiderMaterial; private Dictionary _LastTransforms; void Start () { _LastTransforms = new Dictionary(); } void Update () { //reset and clear all the previous objects if(_LastTransforms.Count > 0){ foreach(Transform t in _LastTransforms.Keys){ t.renderer.material = _LastTransforms[t]; } _LastTransforms.Clear(); } //Cast a ray from this object's transform the the watch target's transform. RaycastHit[] hits = Physics.RaycastAll( transform.position, WatchTarget.transform.position - transform.position, Vector3.Distance(WatchTarget.transform.position, transform.position), OccluderMask ); //Loop through all overlapping objects and disable their mesh renderer if(hits.Length > 0){ foreach(RaycastHit hit in hits){ if(hit.collider.gameObject.transform != WatchTarget && hit.collider.transform.root != WatchTarget){ _LastTransforms.Add(hit.collider.gameObject.transform, hit.collider.gameObject.renderer.material); hit.collider.gameObject.renderer.material = HiderMaterial; } } } } } Just attach the script to your main camera, telling it to watch the player, use the walls and other occluding objects as the layermask, and pass it a material with the hiding shader attached. It will hotswap the materials on the fly. The result is a very clear indication of where walls are and how they are hiding the player. Don't forget to set the opacity down on your material! Conclusion I prefer the shader version since I want to be able to animate the fade and maintain visuals of obstacles. Either way, there are many more options to choose from such as forcing the viewpoint or changing the visuals with a blended shader. As always, check out the options and pick the one that best fits your project and timeline. 12 Jun 2013: Initial release
  2. Strategy game math

    Great ideas! I think the "percentage block" makes the most sense, since it is a more direct relationship that ends up adjusting if the statistics increase or decrease. On the basic level, this type of algorithm is the driver. Then bringing in the armor types and weapon types (like Tiblanc mentioned) as well as other modifiers such as breakable armor or critical hits will give your equations a higher meaning. I was noticing how this compares to Pokemon, at least in the Blue version, where each creature has a series of values including ATK and DEF, that power it through each battle. These are obviously modified by the type of creature and the weakness/strength of the enemy, but the idea rings true.
  3. Strategy game math

    I've been searching around to try to find good articles that discuss the math behind a strategy game. I'm not talking about visual math, but more about how do stats like ATK and DEF react to each other? While it seems like this tends to be more difficult to make generic due to the massive amount of differences in each strategy game, I get the sense that there are some common elements between these games that can create some base algorithms for calculations. The core example I'm trying to figure out is, given an Attack Strength for an attacker and a Defense Strength for a defender, what would be the actual damage caused by the attacker? I'm hoping to find a solution that will prevent a certain DEF from overpowering an ATK, but should be more appropriately based on their differences, and ideally won't be based on random chance (though it could be included for a CRITICAL type of modifer). This wouldn't take into account the actual attack speed, since that would determine the rate at which this algorithm runs. Some articles I have found thus far: [url="http://na.leagueoflegends.com/board/showthread.php?t=725201&highlight="]http://na.leagueofle...5201&highlight=[/url] [url="http://serenesforest.net/fe10/calc.html"]http://serenesforest.../fe10/calc.html[/url] [url="http://en.wikipedia.org/wiki/Gaming_mathematics"]http://en.wikipedia....ing_mathematics[/url] [b]TL;DR[/b] - Does anyone have any thoughts as to some simple algorithms that can take statistics of Attack and Defense and calculate the damage that would be done by an attacker? Any suggested reading is welcomed as well!
  4. I'm at Boston Logan International Airport (BOS) (1 Harborside Dr, off I-90, Boston) w/ 62 others http://t.co/0w0vrdM0
  5. Educational game

    One thought is to consider the core pieces you want to teach over the course of the game. Which equations? Which concepts? One of the key ideas of "fun" in a game is based on the idea of learning something and then being able to use it later in the game, making it a repetitive skill. Repetition is also good for education. The simpler an idea, the easier it is to understand, and the easier it is for you to design a mechanic around it. Instead of expecting the player to know how projectile motion works, for example, perhaps following the idea that games like Angry Birds show. You learn about projectile motion by actually experimenting with the visual of a path. Educational games are tough in this sense because as soon as you introduce any educational element such as an equation, players immediately know they have to learn something. Learning == work != fun. Abstractions certainly help to give you a level of fun by hiding the actual educational content behind a cool simulation. I would suggest picking a set of, say, five educational concepts (equations, for example), and build puzzles around them. If the equation is a[sup]2 [/sup]+ b[sup]2[/sup] = c[sup]2[/sup], that is a bit hard to initially understand. Why does that equation work? What are the parts? Turn the knowledge of that equation into something visual that the player can experiment with. The story will help drive the theme, but it won't automatically create fun.
  6. First major frame-limiting bug due to by-reference copy vs. by-value copy. Le sigh. #programming
  7. About to attempt writing my first A* pathfinding algorithm. I think I get it, but that usually is a wrong assumption.
  8. Based on road and parking congestion, I would guess everyone took the day off. #stupidholidays
  9. Anybody have a good suggestion for a free personal SVN system? With at least a couple gigs of space?
  10. RT @iA: MIT's new 1 trillion frames per second camera captures light in motion http://t.co/812jlBvW
  11. Every time I write a to-do list, I am constantly thinking of clever ways to procrastinate it.
  12. Waiting for @caraschacher so we can talk nerdy #science (@ Atlas Purveyors w/ 2 others) http://t.co/RbFY4Y55
  13. Games that force you to buy items via in-game mechanics make me sad.