I just purchased the A* Pathfinding asset from the Unity store. I have a few questions on getting it set up. My current problem is the AI Destination Setter will only follow the player's "0th" position. It goes to wherever my player starts at and does not update to the current position. (See Image below)
I have a game object prefab called "Essentials Loader" that I drag into every scene. This has things like my Player prefab, Game Manager, UI Overlay, Audio Manager, and other things that will be needed in every scene. I set it up this way for two reasons. 1. It prevents me from forgetting to drag in anything important into a new scene. 2. If I completely re-do the player prefab I only need to swap it out in the Essentials Loader and not in every single scene.
The code in this Essentials Loader checks for accidental duplicates and deletes them to prevent unwanted issues between scenes.
Temporary Solution: I have taken the player prefab out of the Essentials Loader and dragged it into the scene. Now when I assign the "AI Destination Setter" Target transform to the player from the scene and not the project window, it works just fine and follows the player correctly.
My question is: is there a way that I won't have to do it this way? I do plan on completely changing the player prefab a little while down the road and I would hate to have to make that change in every single scene. I would like to still have the player prefab in the Essentials Loader and have the enemy still follow me.
Related
I use navmesh agent for my Isometric game (diablo like)
how then in all diablo-projects did they make it possible to rest against the wall?
how to off pathfind in nav mesh agent ?
I just want to hit the wall (or game object)
Example
ExampleInPoe
I tried everything, I can't figure out how to do it
You have to use NavmeshObstacles like explained here https://learn.unity.com/tutorial/navigation-basics#5c7f8528edbc2a002053b49c in Step 5.
So your navmesh basically ignores the wall - but the object prevents the player from passing. During runtime you can just remove the object and the path will be walkable.
Update:
In order to force the player to run into the wall (I assume when you say 'rest' against the wall you mean that), you could add a script that recognizes the player when they're close and then takes over their movement to let them smash the wall.
But this isn't a specific question anymore. So I'd rather recommend that you check out the Unity Tutorial section: https://learn.unity.com/search?k=%5B%22tag%3A5d351f087fbf7d006af48180%22%5D And try to get a better understanding of navigation and player movement in general.
My 2D game is not lagging, but for some reason the entire game world (except the player) is jittering when the player/camera moves. I tried parenting the camera to the Player and I tried using a script to make the camera move to the player, but it didn't help. It is worse if the framerate is lower, or if there are little frame drops. I use velocity to move the player. Using FixedUpdate (for the player and the camera) didn't help either, it just makes my player not jump every time I press the jump button. I tried searching but I didn't find a solution.
Honestly this is a really difficult and tedious problem to troubleshoot.
I've had issues previously with moving a game object by transform that had a rigidbody.
I've had issues where a rigidbody parent had a child with a rigidbody - also never do this, each hierarchy should have one and only one rigidbody, and that should be at the root level. A rigidbody will "inherit" or consider colliders at all levels at or below the rigidbody in the hierarchy.
I've had issues with a rigidbody that didn't have a collider.
I've had issues where the camera was attached to the rigidbody.
I've had issues where the interpolation settings were not set.
I'd really need to browse through the project and look at the setup to give any kind of specific feedback. Otherwise I'll say that rigidbodies and rigidbody motion is such a pain in the ass that I would recommend NOT using them unless you absolutely have to.
You can do collision checks as triggers without rigidbodies. You can code your own movement and gravity system pretty easily for 2D. The only thing you really need physics for is if you want to solve physics-based collisions, and there I would again say don't use it if you can help it. You can also programmatically add a rigidbody, like for a combat knockout, and add the knockout force and direction, but all the rest of the combat is using scripted motions.
Instantiated objects are stuck at initial position while it was working just normally with no change in code.
I am making a spaceship based game and i was able to making instantiation of prefabs normally until i started adding layers so that the instantiated objects of different kind do not collide. But meanwhile when i ran the game my instantiating objects got stuck at the starting location of their launch.
You probably messed up your Layers a little bit.
To fix this problem go to the Physics 2D Manager (Edit > Project Settings > Physics 2D).
At the bottom you can see the layer collision matrix. (The fancy looking thing with checkboxes)
Because I don't know which layers you have I'm using "Player" as the layer for your player spaceship and "PlayerBullets" as the layer for the bullets your spaceship shoots.
You can now disable collision between the player layer and the player bullet layer.
If your enemies can also shoot, I would create a new Layer called "Bullets". The player layer should be able to collide with enemy bullets, but not with its own bullets.
I'm trying to restart my game when the player loses, I play a coroutine which makes the player ignore collisions and falling off the platforms. Then when the player click a button, the same scene is reloaded.
SceneManager.LoadScene("GameScene")
But when the scene loads again, the player is still ignoring collisions and falls, it's like the scene is loaded but not the same way when the game is played for the first time.
¿How can I reload the scene properly without closing the aplication and opening it again?
Thank you.
The problem is that you are using Physics2D.IgnoreLayerCollision for this.
This property is global, it affect all scenes, and not related to the specific scene. What SceneManager.LoadScene resets is only property related to the specific scene or the objects in the scene.
You have 2 options here:
Don't use IgnoreLayerCollision. An alternative may be, for example, to disable all colliders on the player. You can use GetComponentsInChildren for example to find all the colliders.
Reset IgnoreLayerCollision manually.
I am working on a infinite runner game for android using Unity. The player runs (automatically) and has to avoid the obstacles by touching the screen and changing the gravity. But i sometimes when he hits the corner/side of the platform, the player gets stuck. I already applied a "noFriction" material on the player but it still happens sometimes.
(The small boxcollider under the player just checks if the player is touching the ground)
Here some pictures:
You could add a Physics Material, that has it's Friction and Bounciness set to 0. Resulting in making you slide of platforms if you just hit them from the side.
You should also make sure to set RigidBody2D Collison Detection to Continuous.