Unity Engine. Rotation calculation issue. Rigidbodies and rotation with an object - unity3d

I´ve got some problems with rotations. So, I´ve got a ship, imagine it as a container, I´m trying to get everything within that container to follow the position and rotation of that container. These internal objects are also rigidbodies that can freely move.
So imagine that within the ship there is a table and a cup, both objects rigidbodies. If you are within the ship you can push over both objects, but while the ship moves, it will "drag" them with it.
So the table and cup have to always stay in the correct position, no matter how much the ship moves and rotates. And to clarify, I won´t be able to parent them either, they have to stay separate in this case. Hope I explained that right!
So, for now, I was able to achieve the detection of objects within the ship and follow correctly the position. But the rotation, using rotateAround three times with each axis (Which in itself might be incredibly wrong already lol) even though it seemingly works, it´s always slightly off. And on bigger rotations just breaks fully.
Which does make sense I guess but I still don´t manage to think of a way to get this to behave right.
Is there any way to achieve this?
Thanks for any help!

Related

Don't animate hands in Unity 3D

There was a problem with the animation of the character's hands. I do animations in Blender, naturally I had a ready-made character, from which I cut out the arms and extra bones. Animated separately hands and exported to fbx. But there is one problem, the animation plays, but the hands do not move. As I understand it, you need to move towards the bones. But they are all right, which is strange. Simply I choose in the panel "Inspector" Rig - Genric. In fact, everything should have worked in the best way, but no matter how I tried, I did not fix this bug. Reworked the model and so on. Maybe I'm doing something wrong?
All I tried was to remake the bones of the arms, remake the arms themselves, I tried to experiment with "Rig", but I did not manage to achieve the desired result. If you turn on "Rig Bone", you can see the bones of the hands. But everything that was done did not help

Why can I see the inside of a room as soon as I cross it, in Unity?

I am currently working on a 3d game in Unity, and I am working on the level design using ProBuilder. I basically created a huge cube which I "flipped normal", and a second one way smaller
which, as the other one, I flipped normal, but as soon as I crossed it while turning backward I could weirdly see through the small cube, which makes it feel unfinished. How could I fix this issue?
Normally in 3d games triangles can only be seen from one side. Usually this is not a problem because walls have some thickness. Since you clearly have paper thin walls made of only one layer of triangles this is exactly the result you should expect.
In short add the other side to your walls. The simples way is to duplicate the existing triangles and flipping them. Walls will still be paper thin of course. Later you should probably make them thicker.

Unity3D Wheel Collider - Friction Curve? Alternatives?

so I've been trying to see if I can make use of Wheel Colliders for the past several months now. As much as I've managed to figure out more and more things about how to set them up properly, there's some things I've been noticing that seem impossible to avoid:
Even if your friction sideways stiffness is lower, there's a chance that your car will continue to "spin" or "rotate" in the direction you were steering if you JUST hold down your input long enough to get the car beyond just rotating. I've noticed this will happen, whether for example the "SteerHelper" or "TractionControl" functions are doing their work or not. This will put a dent in ensuring smooth turn movement. Now, I don't know if maybe this is just due to realistic car physics (I mean, I can picture the car skidding in scenarios where they lost grip of the road for sure), but it just feels kinda glitchy. Sometimes, even when I'm not turning, the car will start to turn a little to the left or right and then gradually seem to "lean" that way in terms of applied torque to the rigidbody. I've seen many suggestions for trying to stop the rigidbody from doing this. Here is one way I'm trying to work against this:
rb.AddTorque(-rb.angularVelocity * 2);
However, it seems that the car will still "spin" more than intended. What would be ideal is to be able to MAYBE allow the car to turn a little extra after the left or right steer buttons were released (maybe more or less depending on the vehicle), and no more than that to ensure there is maximum control to give the engaged and maybe arcadey game play I've been going for for a long while.
It's been difficult to adapt an ideal friction curve value that would give the most ideal feel of a drift turn, especially a more arcadey one. I'm not trying to go for wide turns that slow you down, I'm trying to go for tight (yet controllable) turns that allow you to preserve most of your speed. I find that especially at higher values of stiffness, as I know many people have observed in other posts, that again, the car will turn back an extremely high amount sometimes (you drift left enough, a force is turning your vehicle way to the right). It's sad, because I've wanted to be able to say I've "mastered this beast" and used it for my purposes, but I don't know if that's really a good practical expectation for anyone. I even worked my own alternate friction curve values that would be used in the controller:
But I guess as some people say, you can't polish something that's broken? Moving to the third point...
I've read so many posts that show how to adjust a vehicle's center of mass, or to add more colliders in different spots to correct it, using scripting to add an offset to the center of mass, etc. So many tips that say, "lower the center of mass, you'll find it" and I give that a try. When the center of mass is too low, my car can get pretty shaky on the terrain (not that it hasn't in the past, but it's often been things I could correct, like the weird initialization of the attachedRigidBody of the wheel colliders themselves in the beginning, etc). High enough, and of course, (even when it's lower sometimes???) the car will just start spinning in the air on either multiple axes or specifically the forward z, when you drive off a ledge or bump into something with a high enough speed. It just seems inevitable.
I've been trying to give my benefits of a doubt. I like to think there's a correct way to use this thing, and that I'm just not familiar enough with Unity3D physics concepts. However, it just seems more and more that I'm investing too much time in a broken component - or, maybe I just never got the best grip of physics.
I was about ready to try just convex mesh colliders around my tires, and just abandon the idea of gripping physics altogether, but I'd love to hear suggestions to either address anything I've mentioned above, or just a more ideal package to move onto. I've glanced at packages like Vehicle Physics Pro, but I do want to be sure I'm getting something that makes sense.
Full disclosure: I'm in the middle of trying to make a game that feels incredibly similar to F-Zero, but with wheels.
Thanks in advance for any thoughts or suggestions you can provide.
(Maybe not an answer per se, but hopefully helpful.)
Note Unity also suggests to possibly give the car a constant downward force via script. It might be telling that such workarounds are officially given, one would think proper physics would, well, properly work without them.
There's some assets you might want to give a try generally:
One is the Unity Asset Store asset called Arcade Car Physics, and it's free. I've tried it and it works (but not sure if it works for your needs). It's using Unity's native Wheel Collider plus extra scripts.
Another is the Arcade Car Physics github project. It has nice plane stabilization and more, and works well. It's not using the native Wheel Collider.
Then there's this asset called Vehicle Physics. Instead of native Wheel Colliders, they've create a fully custom wheel system so that it would be more physically workable. The asset is not free, but they offer a free demo executable where you can drive around different vehicles, and that works quite well. (I haven't yet bought this asset myself.) As a downside, some reviews mention there's some complexity in setting this up (and I suppose future support for this custom Wheel Collider hinges on the company continuing to exist).
Good luck!

Interactable script allows "Hand follow transform", defaults to transform of the attached object, ignoring offset

We are building a 3D VR billiard, and we are struggling with the Cue-Stick.
We try to use the steamVR Interactable scripts as much as we can.
I attach the Cue stick to the hand with
hand.AttachObject(gameObject, GrabTypes.Grip, Hand.AttachmentFlags.VelocityMovement, Pivot.transform);
The Offset (Pivot.transform is important here because we want to attach to the object at the correct position (which is determined on runtime, depending on where the user puts his hand when grabbing).
Because the Cue stick is moved using velocities and not via parenting, the grab position will not always be on the stick (stick has drag, collision, etc). This is quite immersion breaking.
To compensate for this problem the Intractable script has a boolean for Hand Follow Transform which would be perfect for fixing this.
Sadly the Hand now jumps to the midpoint (origin) of the Cue, even though we grabbed it somewhere completely different. It still behaves like it should, but visually its very confusing.
SteamVR Intractable supports the offset when attaching, but it forgets about that offset when positioning the hand.
Is there something I am missing?
Or is this just not a thing?
I read though the script codes multiple times and it seams like the offset is not available in the scope where the hand is placed. So there seams no way this can work.
How can I solve this problem?
I tried falling back to just parenting to the hand, but this makes physics interactions between Cue and balls funky.
I also read through most of the Interactable and the Hand script to understand whats going on, other that valves naming conventions hurting me a bit I was not successful in finding a way.
I am quite overwhelmed by it though and I can see a good chance that I am missing something.
What probably is possible though, is to set the Hand attachment point to the correct place on the Cue, but this transform is placed in the RightHand (and left) prefab, it seams like a really bad idea to change this transform every frame, or parenting it to the Cue gameobject.
Is there a better way?

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.