Unity Animation Controller and walking diagonally keeps switching between the two diagonals?

Using Unity 2019.4.1f1 Personal.

Unity Animation Controller nodes

I have the above Animation Controller. When only walking in one direction at a time and when you stop you stay facing that direction, this works as planned.

Successfully walking pokemon trainer

All of the transitions do not have an exit time and have a fixed duration of 0. I don’t know what info to give as this is the first time I’ve used animation. Let me know and I’ll add relevant details.

Here’s my update function that updates the variables in the animator:

void Update() {   float h = Input.GetAxisRaw("Horizontal");   float v = Input.GetAxisRaw("Vertical");    animator.SetFloat("Horizontal", h);   animator.SetFloat("Vertical", v);    if (Mathf.Abs(v) < Mathf.Abs(h)) {     // flips the renderer to reuse other handed image     spriteRenderer.flipX = h > 0;   }    // no actual movement until I figure this out } 

What I’m experiencing that I want to fix is when running diagonally:

Broken diagonal movement

It seems that when walking diagonally then the animator variables for Horizontal and Vertical are both either 1 or -1 and this causes the alternating of the sprites. What I’d like to happen is that the state machine would deterministically pick either N/S sprites or E/W sprites when moving diagonally. Turning on "Can Transition To Self" seems to properly pick a direction and stick to it but it fails to animate when only moving in a single direction. It looks like it’s constantly transitioning to itself which starts over the cycle so I’ve left that unchecked on all transitions.

I’m not sure what the best way to fix this is. Most attempts I’ve tried so far complicate the state machine to the point it’s unmaintainable. I also couldn’t find anything about introducing priorities in a way that fixed the jitter.

What’s the idiomatic Unity way to achieve clean diagonal movement in 2D?

Unity 3D platform spawning problems

I’m making an infinite runner game in Unity 3D. I have it so that platforms spawn and move backwards toward the player and they are destroyed once past the player. Over time when the platforms are spawned, the position they’re spawned at gets more and more inaccurate. Sometimes they over lap slightly and sometimes there are small gaps in between them. And as the game is continuously played, it gets worse and worse. You can watch the video below to see what I mean. This is the script I use to spawn the object

 public GameObject[] objectSpawned;   public PlatformKiller myPlatformKiller;   void Start()  {      myPlatformKiller = GameObject.Find("PlatformKiller").GetComponent<PlatformKiller>();  }   private void Update()  {      if (myPlatformKiller.readyForSpawn)      {          int rand = Random.Range(0, objectSpawned.Length);          Instantiate(objectSpawned[rand], transform.position, transform.rotation * Quaternion.Euler (-90f, 0f, 0f));      }  } 

Here is a video so you can see what I’m talking about: https://youtu.be/eASouQlTsqs

Also, I know the exact unit size for each platform is 11.92. I know this because I added a c# script to each one that shows me the vector3 values. There are originally 20 platforms. And to know exactly where to spawn the object I did 11.92*20 = 238.4. And the first platform is at -4.78. So I subtracted that from 238.4 and got 233.62. So a z position of 233.62 is the correct place to spawn the object. I just wanted to include that in there so you know that the spawner gameobject is in the right place. Please let me know if there is any additional information about this that I can give you. Everything should theoretically work I think, so I seriously have no idea what to do. Thanks for your help!

readyForSpawn is set in my PlatformKiller script shown below:

public bool readyForSpawn;  void Update() {     readyForSpawn = false; }  void OnTriggerEnter(Collider target) {     if (target.tag == "Floor")     {         readyForSpawn = true;         Destroy(target.gameObject);     } } 

And that script is attached to PlatformKiller Game Object: PlatformKiller Picture

Rewarded video ad Unity

I’m trying to create a reward system in my game where once the player dies, they have the option of watching a rewarded video ad after which the game restarts and the player score is set to score before the player died. I have been trying to figure this out for the last 2 hours but unable to achieve the desired result. This is my game manager script:

public class GameManager : MonoBehaviour {   public Player player;   public Transform startLocation;    public GameObject startPanel, ingamePanel, gameoverPanel;     private bool gameHasStarted;    public enum GameStates   {     Start,     InGame,     GameOver   }    public float playerScore = 0;   private int savedScore;   private int difficultyLevel = 1;   private int maxDiffLevel = 10;   private int scoreToNextLevel = 10;        private void Start()   {     SetupNewGame();   }    void Update()   {     if(playerScore >= scoreToNextLevel)     {         LevelUp();     }      if (player.dead == false && gameHasStarted)     {         playerScore += Time.deltaTime * difficultyLevel;                }                     if (playerScore > PlayerPrefs.GetInt("HighScore", 0))     {         PlayerPrefs.SetInt("HighScore", (int)playerScore);     }        }   void LevelUp()  {     if (difficultyLevel == maxDiffLevel)         return;     scoreToNextLevel *= 2;     difficultyLevel++;   }  public void SetupNewGame()  {            playerScore = 0;             player.transform.position = startLocation.position;                   UpdateUI(GameStates.Start);  }   public void StartNewGame()  {     player.dead = false;     gameHasStarted = true;     UpdateUI(GameStates.InGame);  }  public void GameOver() {     player.dead = true;     gameHasStarted = false;             UpdateUI(GameStates.GameOver);         }  void UpdateUI(GameStates gameState) {     startPanel.SetActive(false);     ingamePanel.SetActive(false);     gameoverPanel.SetActive(false);      if (gameState == GameStates.Start)     {         startPanel.SetActive(true);     }     if (gameState == GameStates.InGame)     {         ingamePanel.SetActive(true);     }     if (gameState == GameStates.GameOver)     {         gameoverPanel.SetActive(true);     } }    public void ReceiveReward()  {             savedScore = (int)playerScore;             SceneManager.LoadScene(1);             playerScore = savedScore;          } } 

I have created a button for and added the ReceiveReward() in the onClick function. However when I click on this button, the score is reset to 0 and not the score before the player died. Can someone please help?

EDIT

I have added this code to the game manager:

private void Awake() {     if (instance == null)     {         instance = this;     } } 

The score is still reverting to 0.

[ Politics ] Open Question : Why do conservatives accuse people calling for unity of being divisive?

Chanting “Black Lives Matter” is in fact a message of unity. It means that ALL LIVES don’t matter until BLACK LIVES DO! It’s an expendable term that should not even trigger conservative snowflakes. #BlackLivesMatter The riots are irrelevant. The media has been covering the riots more than the peaceful protests (which make up probably more than 90 percent of the BLM protests). Try harder, conservatives! It’s not working. So you conservatives finally decide you trust the media now that this matter is pertaining to BLM???? Yeah, I see you guys!

How to do collision detection in Unity between Character Controller, Rigidbody Collider and a NavmeshAgent?

I would like to know more about how collision detection works in Unity especially when character controllers and NavmeshAgents get involved.

For example, how can I detect collision between NavmeshAgent and a CharacterController? I have added a sphere collider to my NavmeshAgent, but it doesn’t seem to detect a collision unless I set it to “IsTrigger”. I have tried OnCollisionEnter(), OnControllerColliderHit() and OnTriggerEnter(). OnTriggerEnter() seems to be the only one that works and only when I enable “IsTrigger”.

How come the other two don’t work? Shouldn’t they? What if I didn’t want to make the collider a trigger?

In Unity, how can I render borders of provinces from a colored province map in a grand strategy game?

I am kind of a beginner of Unity.

I am trying do work on a grand strategy game. I already have a province map, colored by unique rgba for each province, looks like something below:

s

I know that the province map is kind of a look up map for province id. But when I obverse the paradox strategy games, I notice that they have render borders differently for the provinces and nations. For example, in the CK3, the Baron collars are separated with dotted lines, and the kingdoms are separated with enhanced yellow lines.

enter image description here

I thought they have some other maps or files containing those information, so I went to read their dev diary, and I find that all province shape information are stored in the province map.

enter image description here

So, my question is:

Is there any way in Unity3D to create those different borders with some shader and some province map such those given above?

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?