Open sourcing a Unity game with assets

So, I have a goal to make and publish one (small, stupid, simple) game every ~Saturday. (I’ve made two, so far, thanks for asking.) I’ve started in Unity, because it’s convenient. My plan for each game was to have a free version with ads, a paid version without, but also have it open sourced (and if they’re willing to go to the trouble of removing the ads themselves, so be it).

Now, concurrently, I keep wandering into e.g. Humble Bundle, or Unity Asset Store sales, and picking up things I probably don’t need but maybe might use.

It has just occurred to me, though, that if I’m open sourcing these games – I kinda suspect the owners of these assets aren’t going to be happy with me just posting all their files on the internet. Pretty sure I can’t open source assets I’ve purchased.

Now, I could probably just use free assets and make note of where they came from, and everyone would PROBABLY be ok with that. But that significantly restricts the things I can use. (And it would be kindof a waste – you don’t want to know how many ancient untouched game-dev Humble Bundles I’m sitting on, haha.)

Is there some kind of workaround? Like, if I posted the whole project, but included a license stating that only my code was open sourced, and the rest could not be used in anything else, for instance? Anybody know any nice solutions?

Is it possible to work out rotate in degrees per second based on this rotate logic?

I have this code to rotate an object towards another at a given speed.

    /// <summary>     /// Rotate towards the target.     /// </summary>     /// <param name="lookPosition"></param>     private void RotateTowardsTarget(Vector3 lookPosition)     {         // Determine which direction to rotate towards         Vector3 targetDirection = lookPosition - transform.position;          // The step size is equal to speed times frame time.         float singleStep = weaponRotationSpeed * Time.deltaTime;          // Rotate the forward vector towards the target direction by one step         Vector3 newDirection =             Vector3.RotateTowards(turretYRotation.transform.forward, targetDirection, singleStep, 0.0f);          // Draw a ray pointing at our target in         //Debug.DrawRay(turretYRotation.transform.position, newDirection, Color.red, 3);          newDirection.y = 0;         // Calculate a rotation a step closer to the target and applies rotation to this object         turretYRotation.transform.rotation = Quaternion.LookRotation(newDirection);     } 

And I’d like to convert this to a “Degrees per second” to give the user useful feedback on how quickly it rotates. Is there a formulae I can apply to work it out?

Unity toggleable shader property misbehaves when set by code?

I’ve added a toggle to my shader:

[Toggle(ENABLE_COLOR_BLEND)] _EnableColorBlend ("Enable Color Blend", Int) = 0 

In the Subshader:

#pragma shader_feature ENABLE_COLOR_BLEND 

And in the fragment shader:

#ifdef ENABLE_COLOR_BLEND     color = lerp(_DryColor, _WetColor, _ColorBlend); #endif 

And there it is in the inspector, and when I toggle it, color blending is turned on and the material is rendered as it should be. if I turn it off, it’s off.

But if I try to set it like this in code:

Renderer.material.SetInt("_EnableColorBlend", 1); 

The material is rendered like if EnableColorBlend is off.

In the inspector it’s ticked, and as soon as I turn it off, it gets ticked again. (I set it in an Update) But for some reason, it’s still rendered like color blending is off.

And if I remove the SetInt above, and set it by hand, everything works fine.

Why?

Idea: If I set it by hand, there is a smooth transition (don’t know why) instead of an instant change in shade. Maybe by setting it constantly to 1, it always just starts the transition, but can’t finish it?

EDIT: Just checked it with a guard, and it still behaves the same.

if (Renderer.material.GetInt("_EnableColorBlend") == 0) Renderer.material.SetInt("_EnableColorBlend", 1); 

Per-object screen space uv issue

I am currently trying to sample a texture in screen space. This works well :

float4 positionCS = vertexInput.positionCS / vertexInput.positionCS.w; screenPos = ComputeScreenPos(positionCS).xy; float aspect = _ScreenParams.x / _ScreenParams.y; screenPos.x = screenPos.x * aspect; 

But I would like to be able to constrain uv position and scale based on object’s position and distance from camera. I found some example but I also faced some issues and for the moment I don’t see how to fix them. Here’s the code :

float4 positionCS = vertexInput.positionCS / vertexInput.positionCS.w; screenPos = ComputeScreenPos(positionCS).xy; float aspect = _ScreenParams.x / _ScreenParams.y; screenPos.x = screenPos.x * aspect;  float4 originCS = TransformObjectToHClip(float3(0.0, 0.0, 0.0)); originCS = originCS / originCS.w; float2 originSPos = ComputeScreenPos(originCS).xy; originSPos.x = originSPos.x * aspect; screenPos = screenPos - originSPos;  // You can match object's distance like this float3 cameraPosWS = GetCameraPositionWS(); float3 originPosWS = TransformObjectToWorld(float4(0.0, 0.0, 0.0, 1.0)); float d = distance(float4(0.0, 0.0, 0.0, 0.0), cameraPosWS - originPosWS); screenPos *= d; 

And here’s the issue I am facing. You can notice that when the object is near screen edges the texture starts to move. Is there a way to avoid that ?

I am using URP but this doesn’t really matter.

Navmesh awkward path generation with string pulling due to “inner” vertices

I’ve identified a problem and a possible solution related to navmesh-based pathfinding. Before diving in, I’ll preface my post with some questions to keep in mind as you read:

  • Is this a known problem that people have solved before?
  • Is there a term for the problem that could help me search for information related to it?
  • Is the solution I came up with an existing idea? If so is there a name for the algorithm or some other search term I could use to find more information?
  • Is there a better solution? If so, please point me to it.

For reference, I’m using images from http://jceipek.com/Olin-Coding-Tutorials/pathing.html#navigation-meshes and generally following the advice laid out there.

tl;dr of that blog post is

Decompose your walkable area into a navmesh, treating convex polygons as nodes and their borders as edges so that you can perform an A* search to get from point A to point B. To translate from “node ids” back to real points, use string-pulling.

Here’s a copy of the example space: initial example area

And an example generated path after performing string pulling: example area with a completed path from A to B

So far so good.

But I realized this approach generates an awkward path in a situation like this: awkward path

In this situation, a trio of nodes are all adjacent to each other, and so the A* will generally choose a path directly from the starting node to the ending node, despite an intuitive understanding that the agent can move in a straight line from A to B which travels through a different polygon.

I’ve been working on a solution to this problem and so far my best idea is to apply a transformation to the nav mesh. My description of this will be a little hazy as I’m making up terminology to describe the approach…

  • Define a shared edge as a line segment that is shared by two convex polygons in the navmesh. Maybe a.k.a. a “portal” for string-pulling purposes.
  • Define an inner vertex as a vertex in the navmesh for which all attached line segments are “shared edges”. The vertex in the center of the three polygons in the image above is an inner vertex.
  • Identify an inner vertex. Follow its attached shared edges to what I’ll call neighbor vertex. (possible improvement; If the neighbor vertex is also an inner vertex, recurse to its neighbors until all of the neighbors are non-inner.)
  • Remove all shared edges from the navmesh that were traversed in the previous step, forming a new polygon whose border is defined by the neighbor vertices in the previous step. Redefine the edges accordingly (I’ll hand-wave that)
  • Repeat until no inner vertices remain.

The result of this on the example above should result in this:

Transformed navmesh

And with the same A-B path from before, the string-pulling should now result in a straight line:

Transformed navmesh with fixed path planning

I believe that as long as the navmesh has no inner vertices, all paths generated with the approach described in the linked blog post should seem “natural” and not have any surprise corners in what seems like open space.

Per my questions at the beginning of this post, I’m looking for more information, e.g. has anybody else solved this problem before, is there a better way to do it, and is there even a name/term for this problem?

How To Place Object On Ground Within Radius?

I’m using Unity and I’m building an object placement system where you’ll be able to position objects around the player.

I’d like to place objects flush with the ground, parallel to world up, even on slopes, so I’ll use a raycast for that.

How would I limit the distance to maxDistance? I tried using ScreenPointToRay but the max distance on the raycast makes the movement of the object stop if the raycast doesn’t hit.

As an example, If I’m looking down in front of me, the object i’m controlling should be at that position. However, if I’m looking straight forward into Infinity, the object should only ever be maxDistance away. If I rotate, the object should follow smoothly.

Thanks!

Como fazer um Jogo Multiplayer Online com JAVASCRIPT [closed]

Olá, gostaria de saber como criar um jogo multiplayer com Javascript, e apenas ele e uma conexão com banco de dados criado pelo própio, pois não tenho conhecimento em MySQL, nem mesmo a instalação e etc, e não tenho conhecimento em php (i’m am child).

Se for possível, agradeço

ps: aqui esta o jogo que estou a montar o multiplayer: https://PabloJuan255.github.io/Game/FreeWorld.htm. Use [W],[A], [S] e [D] para movimentação e [I],[O] e [P] para colocar objetos em tua posição.

SetActive doesn’t work for GameObject

I’m using Unity 2D for my game and I’m facing a weird problem. I have a GameObject (an image) in my scene with a button attached to it. When the player is out of the screen, the image that works as a GameOver panel appears and in case of enough coins, you can resume the game. Everything works fine but when the image appears and I click on button to resume, the image doesn’t disappear while the function for decreasing number of coins still works.

Here is my script in which di() is for die and but() for button:

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using CodeStage.AntiCheat.ObscuredTypes; using CodeStage.AntiCheat.Detectors;  public class UIManager2 : MonoBehaviour {      public static ObscuredInt coin_score = 0;      public Text coin_text;     public Slider slider;     public Slider slider1;     public Slider slider2;     public GameObject bul;     public bool reverse;     public float timer;     public int delay = 1;     public float speed=0.5f;     public GameObject pause;     public AudioSource[] aud=new AudioSource[3];      void Start () {         coin_score = ObscuredPrefs.GetInt ("Score");         StartCoroutine (elapsed ());         slider1.minValue = 0;         slider1.maxValue = 20;         bul = GameObject.FindGameObjectWithTag ("Player").GetComponent<Plane19> ().bullet;     }      void Update () {         timer += Time.deltaTime;         if (timer >= delay && reverse == false) {             timer = 0f;             slider2.value++;         }          if (timer >= delay && reverse == true) {             timer = 0f;             slider2.value -= speed;       }          coin_text.text = coin_score.ToString ();         ObscuredPrefs.SetInt ("Score", coin_score);          if (slider2.value == 10) {             bul.SetActive (false);             reverse = true;         }       if (slider2.value == 0) {             bul.SetActive (true);             reverse = false;         }      }      public void di(){         pause.SetActive(true);         GetComponent<AudioSource>().Pause();         Time.timeScale = 0;         aud[0].Play();         aud[1].Pause();         aud[2].Pause();  }      public void but(){         pause.SetActive(false);         Time.timeScale=1;         aud[0].Pause();         aud[1].UnPause();         aud[2].UnPause();         GetComponent<AudioSource>().UnPause();         UIManager2.coin_score-=2;      }  IEnumerator elapsed () {         yield return new WaitForSeconds (2f);         slider.value++;         StartCoroutine (elapsed ());     } }