Cylindrical billboarding around an arbitrary axis in geometry shader

I found an answer on this site relating to this question already, but it doesn’t seem applicable in the context of my project.

Basically I’d like to create a method which fits this signature:

float3x3 AxisBillboard(float3 source, float3 target, float3 axis) 

That is to say, when given a source point (i.e an object’s position in world space), a target (camera position in world space), and an axis (the object’s up vector, which is not necessarily the global y axis), it produces a 3×3 rotation matrix by which I can multiply the vertices of my point so that it’s properly rotated.

I’ve found many solutions and tutorials online which work nicely assuming I only want to rotate around the y axis.

For example, here’s a solution which billboards around the global y axis:

float3 dir = normalize(target - source);      float angleY = atan2(dir.x, dir.z); c = cos(angleY); s = sin(angleY);      float3x3 rotYMatrix; rotYMatrix[0].xyz = float3(c, 0, s); rotYMatrix[1].xyz = float3(0, 1, 0); rotYMatrix[2].xyz = float3(-s, 0, c); 

For context, I’m working on a grass shader, and each individual blade of grass should be billboarded to face the camera while remaining aligned with the normal of the terrain.

Letting the player create a combination of any 4 items that the game will then give the player on a set timer

Okay, so I’ve researched scriptable objects and I’ve realized that it’s something that might be very useful for the kind of game I’m making. I’ve managed to create my own scriptable object for weapons that is able to hold weapon upgrades, range, damage, and other special stuff. I was told scriptable objects are much better for larger scales than enums so that I can hold data for each weapon. I do know how to implement them into

 [CreateAssetMenu(fileName = "New Weapon", menuName = "Weapon")]  public class Weapon : ScriptableObject  {      public new string name;      public string _discription;        public Sprite _artwork;            public int _range;      public int _damage;      public int _upgrades;      public int _element;        public void Print()      {          Debug.Log(name + ": " + _discription + " The weapon does:  " + _damage + "damage.");      }      } 

I’ve researched how to show these on the UI, but is there any hint you could give me on getting scriptable objects working with an inventory system, and point me in a direction on how I can give the player control of the order of weapon in the inventory that the game will use to give said weapons in the same order the player set for themselves.

For Example, I want the player to be able to take any of the four weapons: Katana, Spear, Axe, Chakram, and be able to set them in any order. Even using multiple of itself. Eg. (Chakram, Spear, Spear, Axe) and then the game will then give the player the items list they created on a set timer. (Weapons are one-time use, and the player can only hold one weapon at a time, and the timer won’t start until the player has used up their current weapon)

 public class Weapon  {      public WeaponType type { get; set; }  }    public enum WeaponType  {      Katana,      Axe,      Spear,      Chakram  }  public class WeaponCycle: MonoBehaviour  {      [SerializeField] private Weapon[] _weapon;        public Weapon[] weapons = new Weapon[4];        List<Weapon> InventoryWeapons = new List<Weapon>();        // Start is called before the first frame update      void Start()      {          for (int i = 0; i < weapons.Length; i++)          {              weapons[i].type = (WeaponType)Random.Range(0, 3);          }            StartCoroutine(GiveWeapons(1));      }        IEnumerator GiveWeapons(float delay)      {          for (int i = 0; i < weapons.Length; i++)          {              yield return new WaitForSeconds(delay);              InventoryWeapons.Add(weapons[i]);          }      }  } 

Sorry if it feels like I’m asking for too much, but I’m a beginner when it comes to C# and I’m trying to learn as efficiently as I can.

Window handle is invalid

I’m trying to implement an input listener for FNA (modern version of XNA). Since FNA does not supply any sort of way to listen to native input this has to be done through the windows API and native calls. This is how I set this up:

public KeyboardListener(GameWindow window) {     var procedurePointer = Marshal.GetFunctionPointerForDelegate<WindowProcedure>(Procedure);     procedure = new IntPtr(SetWindowLongPtr(window.Handle, GWL_WNDPROC, procedurePointer.ToInt64()));     if (procedure == IntPtr.Zero)     {         var error = GetLastError();         throw error switch         {             ERROR_INVALID_WINDOW_HANDLE => new InvalidOperationException("Invalid window handle"),             _ => new InvalidOperationException($  "Unknown error message '0x{error:X4}'")         };     } }  // private const int GWL_WNDPROC = -4;  // [DllImport("user32.dll", CharSet = CharSet.Unicode)] private static extern int SetWindowLongPtr(IntPtr hWnd, int nIndex, long dwNewLong);  [DllImport("Kernel32.dll", CharSet = CharSet.Unicode)] private static extern uint GetLastError(); 

I construct the keyboard listener during the Initialize method of Game:

class MyGame : Game {     protected override void Initialize() {         new KeyboardListener(Window);     } } 

This is the method call that reports the error: SetWindowLongPtr(window.Handle, GWL_WNDPROC, procedurePointer.ToInt64()) and it throws "Invalid window handle". It’s worth noting that the example code I saw converted the pointers to Int32 instead of Int64, but I am on a 64 bit machine so the pointers can not fit in 32 bits.

What I’ve tried & figured out so far…

  • Debugging tells me that both window.Handle and procedurePointer are non-null and at least point to something.
  • I have tried to initialize it earlier or later, but that doesn’t seem to make a difference.
  • Other native methods such as SDL2.SDL.SDL_MinimizeWindow(Window.Handle) work perfectly fine and don’t complain about the window handle.

Difference in light between Unity 5.5.2f1 and Unity 2019

The lighting is different between Unity 5.5.2f1 and Unity 2019. Please see the attached image.enter image description here

I dislike the way the lighting is done in the 2019 version. Both verions are installed out of the box, without any additions.

What do I need to change / set up inside Unity 2019, in order to have the exact lighting as in 5.5.2f1 version?

My output is washed out when in windowed

I have the following setup:

RGBA8_Unorm_srgb swapchain buffer
RGBA16Float render targets
RGBA8_Unorm_srgb color textures
RGBA8_Unorm tangent normals textures

I use the render targets for actual rendering. In the very last step in my pipeline, I use the render target as a shader resource and do a fullscreen post processing via shader onto the swapchain buffer as render target

However, I noticed that when I am in fullscreen, I have darker (desired) output compared to when I am in windowed. In Windowed, everything looks washed out and brighter.



What is the cause of this?

What is the standard practice for animating motion — move character or not move character?

I’ve downloaded a bunch of (free) 3d warriors with animations. I’ve noticed for about 25% of them, the ‘run’ animation physically moves the character forward in the z direction. For the other 75%, the animation just loops with the characters feet moving etc., but does so in place, without changing the character’s physical location.

I could fix this by:
1.) Manually updating the transform in code for this 75%, to physically move the character
2.) Alter the animation by re-recording it, with a positive z value at the end (when I did this it caused the character to shift really far away the rest of the units, probably something to do with local space vs world space I haven’t figured out yet).

But before I go too far down this rabbit hole, I wonder if there is any kind of standard? In the general case, are ‘run’ / ‘walk’ animations supposed to move the character themselves, or is it up to the coder to manually update the transform while the legs move and arms swing in place? Is one approach objectively better than the other, or maybe it depends on the use case? If so, what are the drawbacks of each? I know nothing about animation, so I don’t want to break convention (if there is one).

How to Make GameObject move in Circular Motion

I’ve been trying to work an enemy that moves in a circular motion for my RPG game, but for some reason, whenever I press play the GameObject instantly goes hundreds of units in the X and Y coordinates. It also move back to -1 on the Z axis. Here’s the script to my enemy’s movement:

using System.Collections; using System.Collections.Generic; using UnityEngine;  public class EnemyScript : MonoBehaviour {      private Rigidbody2D rb;      [SerializeField]     float rotationRadius = 2f, angularSpeed = 2f;     float posX, posY, angle = 0f;      // Start is called before the first frame update     void Start()     {         // Gets the RigidBody2D component         rb = GetComponent<Rigidbody2D>();     }      // Update is called once per frame     void Update()     {         Movement_1();     }      void Movement_1()     {         posX = rb.position.x + Mathf.Cos(angle) + rotationRadius;         posY = rb.position.y + Mathf.Sin(angle) + rotationRadius;         transform.position = new Vector2(posX, posY);         angle = angle + Time.deltaTime * angularSpeed;          if (angle >= 360f)         {             angle = 0f;         }     } } 

Unity 3D – Why does my button need to be clicked twice to work?

My goal is to go back and forth between a series of animations by clicking left and right arrow UI buttons. I wrote this C# script and the "next" button (which executes AddInt() on click) works as intended, however the "previous" button (which calls ReduceInt() on click), needs to be clicked twice to work. Is this a glitch or is something wrong with my code?

public class update_animator_parameter_int : MonoBehaviour {     Animator gameobject_animator;     public string int_parameter;     public int max_int;     public int current_int=0;      void Start(){         gameobject_animator = GetComponent<Animator>();}      public void AddInt(){           current_int++;           if (current_int > max_int){current_int = 0;}           gameobject_animator.SetInteger(int_parameter, current_int);}       public void ReduceInt(){           current_int--;           if (current_int < 0){current_int = max_int;}           gameobject_animator.SetInteger(int_parameter, current_int);} } 

Persisting Player Prefs On Build in Android

Can I ask for help/guide where I can build 2d game on android device includes the players prefs that I defined already, for example I have an "int" PlayerPrefs (PlayerPrefs.Getint ("mysavenumber")),

the data "mysavenumber" has already a saved integer value in it. How ever upon building my game and installing it on my android device it seems does not hold any value.

How can I build my game with the Playerprefs data that I have defined upon building and installing it on an android device?