Universal joint physics simulation in unity - unity3d

I‘m trying to create real physics simulation of the universal joint in unity. In my case universal joint is in vertical position. The whole mechanism consists of four objects: white ceiling, green shaft, blue universal joint and red shaft. All parts have Rigidbody component, with specific mass (ceiling – 1kg, green shaft – 0,05 kg, blue universal joint - 0,01 kg, red shaft – 0,05 kg). The mass of center of the parts are represented in the pictures. All objects dimensions are NOT scaled and represent the real dimensions of an object in cm. The Box Colliders or Mesh Colliders were not added to the objects.
Green shaft center of mass point, Blue universal joint center of mass point, Red shaft center of mass point
The parameters for all objects are represented in the pictures: Green shaft parameters, Blue universal joint parameters and Red shaft parameters. To the ceiling object only Rigidbody component was added with an “Is Kinematic” option, without the “Use Gravity” option. One Fixed Joint and two Hinge Joints are used for objects. My aim is to create realistic physics behavior of this universal joint in simulation. For example, while playing the scene I want to be able to move the red shaft end, let go it and see how because of gravity and friction red shaft swings back to initial position. I want to do this with object components and project settings, not with a script if possible. If I succeed with universal joint physics I will later plan to add a point on the red shaft object end, which would have Constant Force component and would pull the red shaft end on demand with force to the certain direction. But the force which would pull the red shaft end would be based on real measurements.
The problem that I’m currently facing right now is with the object swinging back to initial position. If I leave Rigidbody and Hinge Joint parameters as it is represented in pictures and try to move red shaft end in scene play mode, the red shaft and blue joint swings back to initial position very very slowly. Like it would have no mass or would have very high friction. But if I turn on red shaft and blue Use Spring parameter in the Hinge Joint and set Spring value for example to 0.2 the shaft as expected goes back to initial position much faster. I also noticed that if I increase object Scale parameters (increase object size) for example from 1 to 100 it swings faster without the spring parameter turned on.
My first question which component or project parameters have the most impact on pulling object down in gravity direction?
Is where more friction friction parameters about which I should know while creating this universal joint model? Because so far I have changed only Drag, Angular Drag to 0, I have created a PhysicMaterial with almost no friction and added it to Default Material field in Project Settings->Physics. I have increased Default Solver Iterations and Default Solver Velocity Iterations almost to the maximum.
My third question would be, is it even possible to create a realistic universal joint shaft swinging without Spring option turned on in the Hinge Joint? Or should I better write the script that would define the red shaft swinging with gravity behavior?

First, Unity physics are not real physics, they are real-looking physics.
Second, Unity units are typically assumed to be in meters. When you set a position to <1, 0, 0> you should assume your object is at 1 meter in x.
Third, Unity physics uses colliders to determine volumes, for the purposes of moments of inertia.
So, when you say that
The mass of center of the parts are represented in the pictures. All objects dimensions are NOT scaled and represent the real dimensions of an object in cm. The Box Colliders or Mesh Colliders were not added to the objects.
It makes me think that (1) you are using the wrong scaling, like 1 = 1 centimeter instead of the assumed 1 = 1 meter, and (2) you're preventing Unity from being able to really run the physics calculations correctly because you're not providing volumetric information to the physics engine (which again is done via the collider volumes).
Also, your masses seem very, very, very small. You've got the universal joint at 10 grams, which is really not much at all.
You're seeing better results when you add a spring because the spring is adding a force, where your weights are small and your missing colliders are failing to do much with physics.
I would suggest adding mesh colliders and increasing the weights to get the behavior you want to see.

Related

cylinder simulation on top of each other in unreal engine 4

I created 2 cylinders and put one on top of the other. Then I clicked to simulate physics and on each cylinder I added the following image blueprint, added a 50-point rotation on the z axis of each cylinder in opposite directions.
It turns out that in the simulation, when I perform, the cylinders rotate in one direction and move on the ground in the other direction. If it turns clockwise it moves left, and vice versa, and should be the other way around.
Can anyone help me solve this? It's for both cylinders to work together and I see how their simulation is accelerating with a constant rotation, but that's not what happens
If you want to simulate physics you should be applying forces to the cylinders using Add Torque in Radians or Add Torque in Degrees rather than modifying the rotation directly.
Alternatively, if you want to precisely control the cylinders, do not simulate physics. Instead, disable Simulate Physics and animate the rotation and position of the cylinders directly as you are.

Unity3D: Letting a BoxCollider2D collide with the floor 'earlier'?

Pre-info:
I'm making a 2D game in Unity which behaves like Castle Crashers, where the player can move around forwards and backwards like in a sidescroller, but also up and down, kind of like a topdown game - but it's still a 'sidescroller'.
In Unity I'm using Rigidbody2Ds and Boxcollider2Ds for physics.
However, when wanting to simulate things like dropping items, creating gibs or any other object that needs to fall to the 'floor', this gets tricky.
The objects that need to fall to the floor don't know where the floor is, so they'll fall forever.
Question
Can Boxcollider2Ds be set to collide with an individual infinite x-axis?
Object A should collide with the red axis and Object B should collide with the blue axis.
Is this possible?
You could use layers. And in project settings -> Physics2DSettings set them not to collide with each other. There is a hard limit of 32 layers and first 8 are used by system (you can still use them for this) this leaves you with 24 discreet layers - change layer of your objects when they change their position on Y axis. The gameplay might feel awful.
Use 3D physics. tilt your camera 45 degrees on X axis, set projection to ortho, and draw 2D sprites on top of invisible 3D physics objects - then you will have real 2D plane to walk and jump on.
Don't use box2d at all: write your own - simple physics library, you need it only for jumping and falling, right ?

New to unity and particles & gravity

I am fairly new to Unity3D and thought I'd give it a go to make physics models.
Here is what I would like to do:
Particles, white small ones, that "stream" outwards from a point, 360 degrees(4/3*πr3) in a shape of a sphere, a growing sphere. The paritcle system should release new bursts of "expanding spheres" quite rapidly and sometimes not as rapid. If I add another primitive to the scene, the particles should bounce in the opposite direction when they hit the surface of that primitive and when they bounce the particle "loses energy" and starts to fade away eventually.
I found the "Particle System" but it does not seem to spawn a ready flow of particles to generate a "exploding effect" that I am after. I hope someone with more experience could help me out :)
You could use the options under the particle system called bounce. and set it from 0 to 1 depending on how much you wanted it to bounce off. everything inside of the collisions tab is what you want, and adding a set amount of burst, would give the impression of a wave, bursts are under emission they need an amount and delay from start of the system.
For the sphere shape you go under the shape category and change shape from cone to sphere.
hope this helps.

Box2d - Giving an object attraction / gravity

I am using Box2d to simulate a top-down space like environment. I have an object that has an impulse applied and will be flying (through space) near to a "planet". The world itself has no gravity but I would like to set up Planets and Stars with individual gravity such that other dynamic objects will fall / be pulled in towards them. How can I achieve this?
If you have small count of bodies/stars you can just apply gravity forces to your bodies each time before calling Step() function.
But I think it will become really slow if the system gets big. If your stars and planets are not moving you are able to precalculate the total gravity force in each point of 2D space. Store this precalculated values of gravity in some 2D array (with some step) and then apply the forces from this lookup table

Buoyancy with Box2D on iPhone

I was wondering if anyone can give me pointers on how to achieve the following using Box2D on the iphone:
1) I have a Box2D world with normal gravity of -9.8
2) The bottom half of the screen is a body of water
So when my sprite hits the body of water, I want him to react with buoyancy (similar to what's going on in this video: http://www.youtube.com/watch?v=0uX-1GXYIss)
Is the best way to achieve this to
1) simply calculate the y position of the main character sprite and then switch the gravity variable accordingly
or 2) is there a specific feature built into Box2D that will allow me to set my "water" sprite to behave as water in my world and "push" my main character sprite up (while still respecting the world gravity of 9.8)
Any info would be appreciated
The buoyant force is equal to the density of the fluid times the volume of the fluid displaced (which gives you the mass of the fluid displaced) times the acceleration due to gravity. The volume of fluid displaced can be costly to compute however. I would suggest making a simple estimate of the volume displaced based on the size of the object and how far it is submerged in the liquid.
Another very important force in fluid is the drag force. This is what makes it more difficult to move objects at high velocity through thick fluids. The drag force can easily be estimated by simply damping the velocity by some constant value: Force_drag = -b * v where b is your damping value and v is the object's velocity.