Orbit camera around player while facing player - unity3d

I ACCIDENTALLY programmed this function (it was just 2 lines or so) a few days ago to orbit the camera around the player with the mouse x input value, but now I just can't get it to work again. I saw many solutions, some even used LookAt, but my own function was really very simply.
My player is constructed like this:
PlayerObject
CharacterWithBones (child of PlayerObject)
OverShoulderCamera (child of PlayerObject)
Could somebody tell me again how to orbit the mouse around the player so that the camera always faces the player?
I do swear that it was without LookAt, and it was really simple. But now all solutions that I can think of would be overkills.
Thank you for the help.

Related

Is there a way to have camera follow g-force in Unity 3D (versioon 2019.3.15f1)?

I am making a game where at one point the player flies a plane/spaceship, and was wondering if there is a way for the camera to move slightly up when the player flies down, and vice versa, same for left and right so that it might make it feel better to play, and slightly more realistic then just a static camera movement.
Thanks a lot !
PS: Beginner here, so sorry if it's an obvious answer...
You can use Unity Standard Assets script CameraFollowsPlayer (Not sure of the name but it is something like this) and you drag and drop your character to your new Camera. It should do the trick with the delay movements. Alternatively you could use Lerp and transform Cameras Position in LateUpdate() method.

Coyote time for 2D platformer

I'm a novice game designer and a coder new to the term 'coyote time.'
I've always felt its existence before or after practicing game design as a career ever so naturally playing other games, but now that I have to implement it to my own game I'm kind of confused how to actually attempt to do it.
My game is set up with modified CharacterController in 3D world space as an orthographic 2D platformer. If anyone could give me where to look for head start trying to implement this feature for the first time or a very simple example I'd appreciate it very very much. Google didn't quite cut it this time for me :(.
It's 11 months late but hey, maybe someone else will benefit from the answer.
Have a player variable called coyoteTime. Whenever the player touches the ground, set coyoteTime to a certain number between 0 and half a second. At every game update, reduce that number. If the player touches the ground, set it back to that number.
When the player tries to jump, if (0 < coyoteTime), the player can jump.
This is basically just extra time to jump

How to ensure sprites face the correct direction at all times in a 2D top down game. (logic)

I am making a multiplayer top down 2D game with 3d elements. All my movement, healthbars and basic functionality is working flawlessly even while hosted and playing on a server, node.js socket.io. However In this game it is possible to move the camera like in Realm of the mad god.
in case you are in doubt here is a video: https://youtu.be/4tdcxl3aZ0c?t=31s
This of course means that the players can end up being upside down with regards to each other and I cannot find a solution that works in all regards to make sure the sprites of the other players are always facing the correct direction with regards to their movement.
I have made several solution to this problem which cover most scenarios but while play testing other things we always end up noticing that the sprites sometimes face the wrong directions. So I am wondering if anyone has an answer, the logic, the fixing this problem.
Things I have tried:
Adding a gameobject to the camera to which all sprites asses their change in distance and determine their facing direction based off that information. (this leads to the players sometimes flipping erratically when the camera is moved and they as well are moving as sometimes they may be moving slower and there although moving left the camera approaches from the right and that flips them)
Adding a gameobject to the world which allows all sprites to have a fixed point to which they can measure their change in distance and therefore also know what direction to face (this worked somewhat better as they always know what direction they have to face, however once the player is upside down everything is inverted)
Emitting to the other players wether I am upside down or not in order to try to reinvert the above solution in the case I am upside down. (I could not find a good way to do this, and it got me thinking that this must be a problem people have fixed before many times and perhaps someone know of a good solution that works.)
thank you all for your input.
I seem to have found a solution for this issue that works decently well. Keeping in mind that I do not want to have the server being involved in this and I would rather have each individual sprite know its direction rather that have something heavy trying to determine this logic I came up with the following solution. May not be the best but it works. Still very keen to hear other solutions.
On my main character I have a switch case, which changes depending on the players rotation in the world. I need this switch case anyway for fixing (http://answers.unity3d.com/questions/1348301/trying-to-change-the-cameratransparencysortaxis-to.html?childToView=1348316#answer-1348316) that issue.
As the cases change I simply place the gameobject that I want the sprites to compare their distance to at 1 of 4 positions. YPos, YNeg, XPos, XNeg. Meaning that the sprite now determines its facing direction based on a gameobject that is placed in accordance with the Players position. without having to place it on the camera.
I will update if during further play tests this gives me trouble but thus far it works in the all the cases I need it to.
Still very willing to hear other solutions to this problem.
Thank you.

Unity 2D box collider falls into another and than ports Playercollider upwards

I try to make my first Unity 2D game (it should end up to be a brawler) and i have a little problem with my colliders. My player collider straight falls a little bit into my scene colliders(the player starts ) and than the program realizes that this shouldn`t happen. It ports the player upwards. Now the player falls again and again he ports upwards. After 3 ports the player lands on the ground and can be used until he collides with another edge and than the same problem occures. I can even fly straight into the scene() collider itselfe sometimes i glitch out but sometimes i fall father down...
Can someone say me how to fix this?
Greetings and thanks for all answers
(BTW. I am sorry for my bad English i hope u can understand it)
You can play with Unity's physics 2D settings.
Most relevant to your problem seem to be:
Position Iterations (try to raise it)
Velocity Threshold (try to raise it)
Min Penetration For Penalty (try to lower it)
Baumgarte Scale (try to lower it)
A more accurate physic simulation is more expensive at runtime so try fixing your issue by tweeking just enough or your game will get slow.

How to detect which block is closest to player? (Unity3D)

I am making a game simlar to MotherLoad. I'm trying to figure out how to mine downward. I've tried using OnCollisionStay and mining towards the block that the player is colliding with, but normally the player is on 2 blocks at once, so that isn't working.
Does anyone know a better method to do this?