#how to implement friction on an environment object
1 messages · Page 1 of 1 (latest)
I’m pretty sure @ ronush8 has already done it in circuits think tank workshop
You should be able to find it in the archive
Thanks
I might be wrong tho but iirc he did
I didn't find it unfortunately
You need some way to detect if an object or a player is touching the ground it should get easier from there
You can create friction using the “Velocity Set” chip.
- Whenever the physics object is in contact with a surface, remove velocity from the object that is perpendicular to the surface’s normal. Note that 9.81 m/s velocity is added in the downwards direction every second.
- Perpendicular Velocity = (Get Velocity(Physics Object) - Vector3 Scale(Vector = Surface Normal, Scalar = Vector3 Dot(Get Velocity(Physics Object), Surface Normal))).
- Parallel Velocity = Vector3 Scale(Vector = Surface Normal, Scalar = Vector3 Dot(Get Velocity(Physics Object), Surface Normal))
- Velocity Set(Parallel Velocity + If Value(Condition = Greater Than(Vector3 Get Magnitude(Perpendicular Velocity), Kinetic Friction * Vector3 Dot(Get Velocity(Physics Object), Vector3 Scale(Vector = Surface Normal, Scalar = -1))), Then = Vector3 Scale(Vector = Vector3 Normalize(Perpendicular Velocity), Scalar = Vector3 Get Magnitude(Perpendicular Velocity) - Kinetic Friction * Vector3 Dot(Get Velocity(Physics Object), Vector3 Scale(Vector = Surface Normal, Scalar = -1))), Else = Vector3 Create(0, 0, 0)))
To determine whether or not the Physics Object is in contact with another object or surface, you can use “Overlap Sphere”.
My apologies, I forgot the +9.81 velocity per second.
I will update it later.
velocity set doesnt work on environmental objects
- Create a Vector3 variable “Object Velocity”.
- Using “Update 30Hz”, set the position of the Physics Object to (Get Position(Physics Object) + Vector3 Scale(Vector = Object Velocity, Scalar = Delta Time)).
- Using the same Update 30Hz, detect if the object is in contact with another object or surface. If it is, set the value of the Object Velocity variable to its Parallel Velocity + its Perpendicular Velocity * 0 to allow for friction, or its Parallel Velocity + its Perpendicular Velocity * [number less than 0] for bounce.
- Using the same Update 30Hz, set Object Velocity to Vector3 Create(Vector3 Split(Object Velocity)[X], Vector3 Split(Object Velocity)[Y] - 9.81 * Delta Time, Vector3 Split(Object Velocity)[Z]).
- Continue with the friction calculations.
- Instead of using the “Velocity Set” chip, set the value of the “Object Velocity” variable.
- Instead of using the “Get Velocity” chip, use the value of the “Object Velocity” variable.
Thank you @brazen grotto
Since you are now using a custom object velocity, I have designed it in such a way that you no longer need to add 9.81 m/s to the friction calculations, but I forgot to scale by Delta Time for the Perpendicular Velocity reduction. I will try to update it later. @buoyant brook
yep, all he says is correct
If you want competely 100% realistic friction, you can use the formula F=mu x R where F is the frictional force, mu is the coefficient of friction, and R is the reaction force.
mu is a random arbitararu number for how much friction you want, it is a property of the material, so like carpet will have high mu, and metal will have low mu.
And R is the reaction force which can be calculated as the weight acting on the ground by the object, you can use the formula mass x gravity for this, or if its being pushed down it is mass x (gravity+downward force).
remember the friction will counteract the force of motion,
If it is on a slope you need to multiply by the cos of the angle of the slope and subtract by force of motion.
@buoyant brook
@buoyant brook Note that the method I described to you uses the formula for kinetic frictional force that @rugged thistle described. It also accounts for slopes, walls, etc., so you don’t need to worry about any further trigonometric calculations (cos(slope angle)).
Also, you do not need to have the gravity as (0, -9.81 * Delta Time, 0). Since you are using a custom velocity, you can have gravity that goes in any direction and is any magnitude (positive or negative, lesser or greater). @buoyant brook If you do end up creating this system, please feel free to send photos and/or videos of your results!
Jesus 💀
?
friction isnt allat simple