Hot answers tagged

45

Animations in which the character translates away from the origin are said to contain "Root Motion" - because the root bone moves. This allows the animator to directly author subtle non-uniformities in the movement speed, in a "what you see is what you get" fashion. Say the character slows down slightly as their foot makes contact with ...


7

Nice idea by the author. From experience... High vertex counts aren't that much of a problem (100Ks, millions even). Dealing with complex UV mapping is far more so. Sometimes it is worth staying closer to the actual description of the surface (i.e. the backing 3D array), than optimising yourself into a place where it's not as easy to change the mesh when you ...


6

Quoting the meshing page you link: It isn’t too difficult to modify the code deal with either multiple block types or different normal directions. What you would do is modify the array called “mask” in the code to store an integer value which encodes the type of each block. You’d need at least 1 bit for orientation, and then you could use the rest to store ...


6

Here's an example of how we can mimic this appearance in a Unity scene: My strategy is: First, compose the image that the POV display is trying to project. Render that image, with a shader filter that adds artifacts that look like a POV display. On the left is step 1. I've positioned some sprites representing my clock face and hands. That way it's easy ...


6

slots = GameObject.FindGameObjectWithTag("Slots Content").transform; FindGameObjectWithTag can return null if it doesn't find such an object, then the transform reference will fail. Just split this into two lines: Transform theTransform; slots = GameObject.FindGameObjectWithTag("Slots Content"); if(slots != null) { theTransform = ...


6

You want a Coroutine. // IEnumerator tells Unity to run this as a coroutine // that can suspend and wait, without stalling the whole game. IEnumerator Start() { // Your loop condition was backwards, // so it would never execute the body. // It looks like you want a < here instead. for (int a = 0; a < 1000; a++) { Debug.Log(&...


5

Happened to me too. Solved it by setting Visual Studio as the default 3rd party tool as scripts editor in Unity's preferences.


5

The MapNode class I would represent each node on the map with an own gameObject which gets a MonoBehaviour I would name MapNode. That class would have four variables representing its neighbors: public MapNode upNeighbor; public MapNode rightNeighbor; public MapNode downNeighbor; public MapNode leftNeighbor; Another option might be to make those a public ...


4

This is a feature of the C# programming language called an explicit cast. When you have a reference of a type of a base class or interface, but you are sure that the object it points to is of a certain more specific sub-class, then you can use it to convert that reference to a reference of the more specific class. In this particular example, a Renderer is a ...


4

By using deltaTime, the timer is independant of the amount of FPS. deltaTime is the time between the current and last frame, meaning on 60 fps the delta time is smaller than on 30 fps. So for people with 60 fps the timer updates 60 times with a small amount, for 30 fps the timer updates 30 times with a bigger amount (in this case double). So for both users, ...


4

I'd attack it something like this... Have one script that represents the digit as a whole, and assign to that script in the Inspector an array of SpriteRenderers representing the seven segments. They don't need their own custom scripts, since the only functionality we need from them is setting the colour, which the built-in SpriteRenderer component has ...


4

You are using the public static int Range(int min, int max); overload, which as per the documentation is inclusive for the lower boundary, and exclusive for the upper boundary. The documentation you see in Visual Studio is for the version accepting floating point parameters. The overload accepting integers is documented below the floating point version on ...


4

We are talking C#, so I'll assume .NET. Thus you would either use System.Random.Next which works with integers, or System.Random.NextDouble which - as the name suggest - works with double. There no method in System.Random that uses float. From System.Random it is preferible to use System.Random.NextDouble. This is how it works: first generate a pseudo ...


4

I found the answer online! I had to go to the editor preferences (Edit -> Preferences) and under External Tools, there's a section with checkboxes under "Generate .csproj files for:." All I had to do was check "Registry Packages," click Regenerate project files, and it worked! Thanks to everyone who tried to help, and to DMGregory ...


4

The regular Text component unfortunately can't do that, at least not on a UI canvas and without some nasty hacks. But TextMeshPro can. I really recommend using TextMeshPro over the classic Text component anyway, because it is superior in basically every way. The only thing which still justifies the existence of the classic Text component is backwards ...


4

public float speed = 1f; public float wanderDegrees = 45f; Vector2 _velocity; void Start() { // Don't check the game object's name here. Just put this component // on ONLY the enemy that's supposed to use it, and not on the others. // if (gameObject.name == "Enemy_R") // Don't look up your coroutine by its name - that's ...


4

The issue was coming from TargetFramework! If the option .net5.0 is not supported by Godot, there is another option to have full System.Runtime feature of C# v8 netstandard2.1: <Project Sdk="Godot.NET.Sdk/3.3.0"> <PropertyGroup> <TargetFramework>netstandard2.1</TargetFramework> <LangVersion>8.0</...


3

It actually has a tricky way to do it. You need to grab the PostProcessValue and then grab the effect that you want to change, in your case the Vignette. After that, you will need to "Override" the values, that is the key. Here is an example I did based on the Unity documentation: public PostProcessVolume volume; //Assigned with the editor Vignette ...


3

As with every problem, there are many ways to come to a solution. But one solution I usually find the easiest to implement is: Add an EventSystem to your scene. Which happens automatically when you add a Canvas for your UI. Add a Physics Raycaster component to your camera (Physics Raycaster 2D if you want to use 2d colliders) Add an appropriately shaped ...


3

After getting help from @DMGregory I was able to solve this by : Getting the center of the toppingsA and toppingsB Finding 6 most far toppings from the centers generate 2 polygons based on these 6 vertices for each topping check if polygons have the minumum area needed to cover most of the half and that they don't collide This gives accurate half-half ...


3

In contrast to Evorlor's answer, here are some good reasons to use Coroutines: They've been the standard solution in Unity for many years and anyone else you bring onto the team should already be comfortable with them. They are in step with the engine. WaitForFixedUpdate() ensures that the next step in the Coroutine will be run during the Fixed Update cycle....


3

Renderer is a subclass of Component. So (Renderer)b casts current Component to Renderer. GetComponentsInChildren(Type type) (that returns Component[]) was used before its generic counterpart GetComponentsInChildren<T>() (that returns T[]) was added to Unity. In today's Unity this code can be simplified to: void SetTargetInvisible(GameObject Target) { ...


3

You can control the spawn rate by changing the value of secondsBetweenSpawn to a value between 1. One way to do that would be via script. For example, you can reduce the time at a rate of 10% every 5 seconds with this line in your Update function: secondsBetweenSpawn = Mathf.Pow(0.9f, Time.timeSinceLevelLoad / 5f); But another solution I find far more ...


3

This property provides the time between the current and previous frame. That definition is correct. We can argue that it could be clearer. In layman’s terms, delta time is the amount of time your last frame took to complete. That is an over-simplification. After looking for the article in question… I can see the break it down very well afterwards. First ...


3

What I am specifically asking for is a way to store that data in any file format without needing to massively rework my game. It should be noted I am a novice level programmer and in way over my head, so detail would be appreciated. No offense, but the clumsy way you're storing your data is just making things worse for you. You should seriously consider ...


3

In Jetbrains Rider there is one option on folder properties named "Namespace provider" when we use a right-click mouse on the folder. Just uncheck that check box and the namespaces work as expected. You can use this for the Project and Scripts folders. I'm not sure if VS Code has this option. Two good videos for namespaces in Unity: Should You Use ...


3

A ScriptableObject's Awake and OnEnable methods are called (in that order) as soon as the object is loaded. This occurs when... Loading a scene that contains a reference to the object (including in the editor) Reloading recently referenced ScriptableObjects after a code change Clicking on the object in the Project window or reference selector widget That ...


3

Since you wrote in a comment it is for an offline game, the short answer is: you can't. If the player is the owner of the whole game (since it offline), any kind of mechnism can be prevented if he is dedicated enough to figure out how you obscured your data. You can only make it harder for him. You need to prevent memory manipulation, else the player could ...


3

For HP, I'd recommend creating a Health component, something like this... public class Health : MonoBehaviour { public float maxHP = 100; public UnityEvent OnDeath; float _currentHP; void Start() { _currentHP = maxHP; } public void TakeDamage(float damage) { if (_currentHP <= 0f) return; _currentHP -= ...


3

To answer the original question, as @DMGregory pointed out, typically the best/fastest way to find a child during runtime is using the GetComponentInChildren() or GetComponentsInChildren(). This isn't exactly the fastest solution in the world, but it works much better than searching by GameObject name, although honestly in most cases it probably wont be much ...


Only top voted, non community-wiki answers of a minimum length are eligible