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.
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.
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.
I am trying to make an enemy for my game, and I got it to work using Navmesh. The only problem I have is that my character controller for my player is rigidbody based, and I want the player to be able to push the Navmesh agent around. I think this can be achieved by CalculatePath() and steeringTarget, but I am still not sure how the code would work. Thanks in advance
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.
I'm making a game in Unity 3D, and I'm looking for a one-way wall. In Unity 2D, there is a simple one way platform (PlatformEffector2D) that can only allow a player to go one way. I couldn't find something similar for 3D. Is there something simple like the PlatformEffector2D, but for Unity 3D?
Try to have a collider at the start of the way when its trigered disabled the rotation of the player. and then use function
Vector3.RotateTowards
to your desired direction.
Yes. You can check which side of the wall the player is in by finding the position of the player and the wall. If he is on the desired side for passage through the wall, make the wall on a separate collision layer than the player. If it is on the the other side, then make the player and wall on the same collision layer.
Honestly if you are looking for a one way wall. You might want to look into using a raycast. Project a raycast in the direction where the character should be able to walk through the wall. If that raycast hits the object then remove or set the collider to be a trigger.