#⚛️┃physics
1 messages · Page 76 of 1
That's what I figured but what's confusing me is how does it obtain magnitude if it is just an arbitrary point
Distance from 0,0
Ahh that's the part I was missing
It's calculated as sqrt((x^2)+(y^2)+(z^2))
okay I see thank you
hi..
i dont know much about unity but i wanted to create a scene so that i could visualise my physics problem(high school student)...
can anyone help?
I guess you're not going to get very realistic results with only angular drag, drag, friction and bounciness. Unity doesn't simulate rolling resistance by default. Angular drag can be used to do sort of same effect but (as far as I'm not mistaken) it's actually not the same thing. If you want somewhat physically correct behaviour, you would need to implement the rolling resistance yourself. In this part I may be completely missing but I guess rolling resistance is just some constant (force applied to opposite side of movement that speed doesn't affect, or maybe It's proportional to speed I have no clue) and angular drag is like air resistance that happens when object rotates (imagine sheet of paper rotating fast) which is either proportional to the angularVelocity or squared to the angularVelocity depening on the speed. Because billiard balls are perfectly round, there should be no angular drag at all. So I'd try to add some constant force (the force should be clamped somehow tho so it doesn't start moving backwards when it's about to stop) in the opposite side of movement of ball, remove angular drag and see whether or not it looks good.
Hi, does anyone know how is add force at position calculated into add force and add torque? I tried looking into physx documentation but it's not there.
Yeah, I basically worked out what you said today lol. I haven't tried it yet since I haven't got my computer, but I'm going to try and add some resistance force to the ball through FixedUpdate, remove the drag and see what happens.
Thank you for the helpful reply.
no problem. good luck with it 👍
I managed to get back and although I haven't tried out the constant resistance yet (though I'm pretty sure that should work as long I deltaTime it on the physic ticks), but with some further study of billiard physics and some trial and error, I've managed to get the ball physics pretty damn close to real cuesports. I've even added the ability to put horizontal and vertical spin on the ball using AddForceAtPosition using a Vector3 multiplied by the radius of the ball. I'm so happy!
Does this look correct? First shot is backspin, second is topspin. Ball is slightly off centre to prevent it from just going straight. Obviously no rolling resistance yet other than the friction that slows down and corrects the spin speed.
Sidespin also seems to work fine, but I know less about that. Cue rebounds off balls and cushions as I personally expect them too, though.
I'm assuming it does it the same way you would calculate the effects of applying a force to a rigid body in real physics. You decompose the force into two components -- a component that points directly toward the center of mass and a component that points perpendicular to the first force. You then apply the force pointing toward the center of mass to the rigid body (as a force) and apply the force pointing perpendicular as a torque.
@jovial wraith thanks
So, im trying to have a system where you control the head of a snake, and the body segments just follow along, right now im trying to do it with configurable joints, but i just want the prior segments to follow, and to not hinder movement of the head
effectively i want the tail to act like a trail-renderer, but with a trigger collider so i can check for intersections, and an actual mesh skin instead of a line
how to add a force to an object in a way that changing the object's mass wont affect the percieved movement from that force
aka apply a force thats not affected by mass
Use ForceMode.Acceleration in your AddForce call
Or, if it's 2D, just use the normal ForceMode2D.Force, but multiply the force by the Rigidbody's mass.
Deceptively complicated issue here. Wonder if anybody has a neat idea for a solution.
My plane has a Rigidbody attached at the top level with a bunch of colliders in the children.
I'm detecting collisions and if collision impact is > a certain threshold we call CrashPlane(). So far so good.
I want that threshold to be higher if you landing on the *wheels * (a bit of give in the suspension) as obviously you can land a plane on wheels much harder than upside down, for instance. But OnCollisionEnter(Collision collision) appears to have no way to know which child Collider called the function 😓
TL;DR how can I detect *which *child collider has called OnCollisionEnter?
collision.GetContact returns the contact point of an index (you can use 0 if it doesn't matter which point) which contains info on the two colliders involved on the collision
https://docs.unity3d.com/ScriptReference/Collision.GetContact.html
you can use that to get the info on whether the wheels where involved
Ah! Thank you! Somehow missed that that function needed to take an int, and then convinced myself it wasn't going to return me what i wanted. Thanks again ʕ•ᴥ•ʔ
It happens when edge of a box collider collide with something. I only found one solution which works for me. I've replaced box colliders with capsule colliders and that's helps me a lot. But also the size of the collider matter. And changing the detection type on rb to continuous dynamic should help.
Another option is to put the OnCollisionEnter script directly on the wheel collider GameObject
How should a cloak or cape be handled? Should I do any rigging in blender, or is this done in unity?
importing rigging from blender to unity is finicky but the blender rigging tools are nicer in my experience
you may have to make the animation in unity but you should be able to rig in blender
https://www.youtube.com/watch?v=M3iI2l0ltbE so i made a infite terrain with the scripts used in this video but i cant seem to get the physics working, all the chunks have a a mesh collider and my player has a capsule collider
In this coding adventure I try to understand marching cubes, and then use it to construct an endless underwater world.
If you'd like to support this channel, please consider becoming a patron here:
https://www.patreon.com/SebastianLague
Project files:
https://github.com/SebLague/Marching-Cubes
Learning resources:
http://paulbourke.net/geometr...
The Dynamic Friction only seems to affect the sliding friction of a ball, not the rolling friction. Basically, it will slow down until it reaches a certain speed (which is different depending on how fast the ball was impulsed at) with constant angular acceleration. Once this speed is hit, the ball will stop slipping and begin rolling, but the friction will no longer do anything.
I tried manually adjusting the angular velocity with Fixed Delta in FixedUpdate, but there were 3 main problems:
-
The angular deceleration was about half or more than what it should have been. If I put in -10rads/s, it only really goes down by about 4-5rads/s, so I have to use -20 to get the effect I want.
-
The ball will eventually reach a linear and angular velocity of 0 just by lowering the angular velocity, but for some reason the ball will start to gain limear velocity in all directions. Despite having something like a speed of 3m/s, the ball stays perfectly still as it should, but stays awake for no appparent reason. I couldn't find a way to force the rigidbody to sleep, doing so through multiple ways gave the ball a 50% chance of not firing.
-
There is no angular deceleration while the ball is slipping, only when rolling. This might be correct behaviour and isn't a big deal in my eyes, just an observation.
I've really been tearing out my hair over this, once I get this bit done, the rest should be easy enough for me. There must be loads of games that have semi-realistic ball physics, I can't believe I'm struggling so much with this.
Nevermind, I found an equation on Wikipedia which might help me, so I'll try that.
Well actually, that just looks like Drag.
But if I use Drag the ball will never seem to stop, just move very slowly for a long time.
Unless I just put in my own minimum speed, I guess.
Actually, maybe it's not the same as Drag. I'll mess around with it.
i have some very annoying issue in my project.
I have a floor which is a plane and has a mesh collider enabled on it.
when i place a rigid body cube with use gravity, the gravity works, but the cube keeps falling down and down
can you show your cube's inspector?
try setting the CollisionDetection to Continuous?
I'm not sure though, I dont use 3d much
that still didnt work 😦
the cube falls through the plane, that's the problem, right?
oh.. ok. In the future, please don't crosspost. delete your message if you're already being helped in another channel
ok sorry
I have a simpel rigidbody movement script. for jumping i use
this.Rb.AddForce(Vector3.up * JumpForce, ForceMode.Impulse);
But my player just "teleports" to the highest point of the jump and than falls down.
Is there a way to do this a little bit smoother?
how much is your JumpForce?
something about 30f i think, but if i lower it, i wont jump at all...
where are you calling this
in fixedupdate
sounds about right.. sorry, no clue
have you fixed it?
are you sure its not the tigidbody
or your pc
try putting your script on a new gameobject
with rigidbody non modified and a collider
i will try
and ping me
Hi, I have a robot and have simulated it with an articulation body. The wheels are attached to the chassis and are revolute joints with sphere colliders. The articulation body for each wheel is locked to the axis I want. Im having trouble though understanding the force limit and how it is applied. Ive set it to a very small number because I was getting loss of traction when applying an instant 100% target velocity but I assumed that force limit would limit the acceleration of the wheel. Any suggestions?
I have the drive configuration set to 0 stiffness, 1 damping, 0.1 force limit, 0 target, and target velocitt is set to 360deg/s when the user presses W
Also another problem im having is when the robot is on a slope it will roll down the hill even though target velocity is set to 0 (no input from user) so my understanding is that the drive motor should apply a force to stop the joint from rotating but that seems to not be the case
@desert wave Tried it with a simple capsule + rigidbody, the same problem 😭
and does it only happen in that scene/and you sure it's not your pc
@desert wave hm i will let it test a buddy 😉
and have you tried restarting unity
i made an extra scene for it, an restarted unity several times 😉
Buddy has the same problem...
Can i cheat a little bit and add an Acceleration over a few milliseconds? maybe it become a little bit smoother ...
Generally a jump would only involve adding a force up one time (not over multiple FixedUpdates). But your issue sounds like just a bad interaction with some other code and/or something wrong about how your Player character is set up. Hard to say without seeing your whole player movement script and how you've set up the GameObject
@timid dove i reduced my movment code a little. still the same problem...
I'm trying to make a cape with the cloth component, but when I click the "edit cloth constraints" button, I'm not seeing any spheres appear on my cape, nor am I getting that little window in the corner of my scene view which can be seen in this tutorial. Does anyone have any idea what might be wrong? I have gizmos enabled. https://www.youtube.com/watch?v=FkEqFvqpyfE
In this video, I talk about Unity's Cloth System and how you can make some sort of Hammock with the Cloth System I also talk about all the variables or parameters that are on the Cloth System. If you enjoyed this video or if it helped you out in any way make sure to hit the LIKE button and if you want to continue to see more videos like this do ...
Hm, after restarting Unity, now I get the window and the spheres but the spheres are very large making it hard to edit them because they're alloverlapping. Is there a way to adjust their scale? Adjusting the 3D gizmo scale doesn't change them at all, and disabling 3D gizmos does nothing as well.
Nevermind I figured it out. For whatever reason the size of the vertex selection spheres is called "constraint size" and adjusting that to 0.01 made them reasonably sized.
I wonder, what in unity physics does make two coliding objects with rigid body always fly off in different directions?
If the starting position of objects, mass, and speed are all the same, I would imagine the result of each collision would always be exactly the same
What does your vehicle movement code look like
just ```using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
// Move the vehicle forward
transform.Translate(Vector3.forward * Time.deltaTime * 20);
}
}```
This is your problem
- transform.Translate mostly bypasses the physics engine
- Doing this in Update means that it's going to be slightly different each time because your framerate is not always the same
So the exact amounts you translate forward will be different
Which means the depenetration by the engine will be different
Because you will overlap colliders differently each time
An immediate fix would be to simply move your code into FixedUpdate
A better fix though would be to learn about actually moving your object via its rigidbody (also in FixedUpdate)
Thanks, that makes sense
Hey,
I made 3 characters.
1: simple animator with ik
2: simple animator with motion matching
3: ragdoll with animator copy motion but here is the problem.
With the case 3, the copy motion, balance is done, but as you can imagine foot hit too mutch floor and did some times moonwalk... It's normal because i didn't do the foot ik gestion.
So what is the best way to get 50/50 rag motion?
Procedural walk and disable foot rag?
Recalculate like ik at x of animation?
Or other thing?
🙃
Hello everybody,
Someone has used the Unity packages for integration with ROS?
For robotic simulation.
<@&502884371011731486> ^
what settings should I add to my RB to make it behave like in 0g and in a vacuum?
Turn off gravity and away you go.
thats all? great
That's basically what 0g is. 0 gravity.
i know, i was wondering maybe some settings were needed for the vacuum part, but i guess unity doesnt count that in anyways?
Well, you can set the drag to zero as well yeah.
I'm making a hand with articulation bodies, but sometimes an articulation bugs out completely, somehow its rotation changes referential
I should point out I'm using an articulation per phalanx
Is it even viable to have such a setup on a realtime physics engine ?
So i have this code.
and it send false when iam on ground (red small line) false = red
and it send true when i jump (small green line)
With is oposite + it wont send tag to footstepsystem :ä
not sure if this is the right channel, but I'm having issues with collisions. Player can move right through walls, and I have tried changing the collision detection mode from discrete to all others. Anyone know?
How are you moving the player
You need to use physics based movement for it to respect colliders
I am using rb.MovePosition
yep
No idea
not entirely sure if this belongs here but would a capsule collider require more resources than a box collider?
Yes but not that much
It won’t make a difference
alright
for the box collider yes, as the collision detection is not re done
not true - box colliders need a second pass just like everything else. AABBs cannot be rotated so the math is much simpler for them vs a box collider. Since box collider can be rotated, it's more complicated
capsule collider overlap checking is surprisingly simple - conceptually it's all points within a certain distance (the radius) from a line segment (the height of the capsule)
forgot about rotations
Hi, I've got a question about particle collisions, should I ask here or in vfx channel?
ig #✨┃vfx-and-particles would be better
Hi , i need some help for this point.
I'm developing a VR Hand, and I'm trying to get the velocity or magnitude of the movement, or speed.. (doesn't matter as long as i get something...)
but the velocity displayed in the debug of the rigid body is still zero.
The only way i can get something is when i activate Gravity, but only for Y
that means you're not moving the hands using physics (like .velocity or .AddForce) right?
the hands are moved following the controllers trackers
I have no idea what that means (I have no exp with vr) but if you don't use physics to move the hands, you can't use .velocity to measure the speed. You can probably keep track of the last frame hand position, measure the distance to that and divide that by Time.deltaTime to get the speed at the moment.
Rigidbody velocity is not going to be set from that
It's probably either just setting the positions directly (teleporting it around), or best case scenario it's using MovePosition
neither of those things sets the RB's velocity
to get the velocity you'll have to record the position each frame and compare it to the previous frame
then account for how long that movement took, and you can easily calculate the velocity
Hey Everyone,
I am working on a project and need to create a unicycle in unity. Should I create the frame and wheel separately in Blender and then add the physics in unity? Then when doing the physics what kind of component would I use to get a physically functioning joint from the wheel to the frame?
WheelCollider
and maybe a hingejoint?
I'd do the wheel and frame as separate meshes (though could be in the same blender file)
so the frame would just hinge on the center of the wheel?
Anyone know what general performance of PhysX articulations are?
I know it’s obviously dependent on a lot of factors, but can’t seem to find anything about performance
Hello. I'm trying to implement a system where the enemy and player colliders can overlap and don't 'interact', but I can still detect OnCollisionEnter or something similar for hit detection. Does anyone have a moderately straight forward solution to this?
I still want the general functionality for my enemy collider though so that it can walk around on surfaces and stuff so I had been using IgnoreLayerCollision, obviously that doesn't work though. I had also tried to child a trigger collider to my enemy object and just have a regular collider and a trigger but they seem to conflict that way
Maybe I just need to screw around with it more
layers, triggers and non-triggers are all you need
I guess I just need to have it configured correctly
its a very common case what you are describing, so if it isnt working for you, there may be an error in your setup
I figured, thank you 🙂
Basically you'll need two separate colliders for either the player or the enemy. One that is a trigger collider for the non-physical interaction, and one normal collider for the physical interaction
Hello I was wondering if someone would know why my player object in my 2D game has collisions with the my tiles top and bottom but not the size. I'm using a Box collider 2D and RigidBody2D for my player, and a TilemapCollider 2D for the tiles. I've looked through Documentation, Tutorials, and tried my best to fix the problem on my own.
Able to stand on top vv
Passes through the sides vv
how are you moving your character
float movement = Input.GetAxis("Horizontal");
transform.position += new Vector3(movement, 0, 0) * Time.deltaTime * MovementSpeed;
This is how I move my character
You're moving by setting transform.position
this method of movement ignores the physics engine entirely
it will gladly teleport you directly into a wall
because it literally just says "set the position to this new position"
there's no checking for whether that position is inside a collider or anything
If you want collisions to work nicely, you need to move via the methods on your Rigidbody2D
Yup that was it haha, that makes sense. Thanks for the help! 🙂
I have an issue where my CapsuleCollider/RigidBody gets stuck on the edge of a BoxCollider when moving slowly. The CapsuleCollider should just fall off the edge, but just gets stuck there, even when using AddForce. The CapsuleCollider does slide along the edge if enough force is applied, but will not fall off,even when going around the corner of the BoxCollider. Has anyone run into this issue?
do you have friction on the capsule and box collider?
I've tried adding a physics material to just the player, just the step and both. I've tried each combination of no friciton on both, no friction on one and friction on both. The problem still persists.
can you show your movement code?
@tender patio see #854851968446365696 for the sites to paste code in
it seems like when not grounded you reduce the speed of movement by 5, which means that isGrounded may be returning true near the edge leading to slow movement and not being able to go off
could you show your isGrounded method
I am dividing the movement by five in order to allow movement while in the air, but at a reduced rate. I added Debug.Log to both of those AddForce calls and it is calling rb.AddForce(move / 5), as is intended. The IsGrounded is doing a raycast downward from the capsule transform. I'll try increasing the air movement and see if it adds enough force to move the object.
is it a single raycast from the middle of the collider?
this could lead to it not being grounded if the collider is half way off the edge
Yeah, and after increasing the amount of force applied when IsGrounded returns false, the capsule falls off the edge as intended. I'll work on a better IsGrounded method. Thank you for the help. 🙂
you can use something like a spherecast instead btw
or a boxcast
if (Math.Sqrt(Math.Pow(rb.velocity.x, 2) + Math.Pow(rb.velocity.z, 2)) > maxVelocity)
{
rb.velocity = rb.velocity.normalized * maxVelocity;
rb.velocity = new Vector3(rb.velocity.x, y, rb.velocity.z);
}
Change this to:
Vector3 horizontal = rb.velocity;
horizontal.y = 0;
if (horizontal.magnitude > maxVelocity) {
horizontal = horizontal.normalized * maxVelocity;
horizontal.y = y;
rb.velocity = horizontal;
}```
right now you're including the old velocity in the normalize calculation
Or that too but now your player is gonna be easier to kill
Hey guys I made my moving platforms rigidbodies so they would handle the player being on them automatically, problem is that it doesn't seem to work all the times, for instance when they start moving (in this example we are referring to an elevator) the player will start falling, then once it touches the platform again it will stick (with an occasional unstick again while moving). Does anyone have a solution in mind?
is the player a character controller? how do you move it?
how do you move the platforms?
are you parenting the player?
Both player and platforms are rigidbodies, im not parenting as I had issues before where the parent transform would override any physics movement
you're probably not moving your stuff in a physics friendly way
e.g. you're setting transform.position directly
or using transform.Translate
^
Are you talking about a vertically moving platform?
Yep
do you need the elevator to be a rigidbody?
https://www.youtube.com/watch?v=UbzAdGiCEes
this tutorial didn't need it
Hi! So in this tutorial i am going to be showing you how to create a one way elevator.
Remember to like if you want to see more and remember to have fun!!!
I was implementing moving platforms for my character and i've read around that simply making the platform a rigidbody too is the simplest way to handle interaction without having to deal with bunch of other issues. Ill watch the video tomorrow as rn its quite late
You need to parent your player to the moving platform. THAT is the easiest way.
You can create a trigger that sits above your platform that tells the game when to parent/unparent the character from the platform
so i am using rigid body on my player to move but I have a custom 3d model and i dont know how I can add a colider for it and mesh collider wont work. I tried capsule colider but the player fell and rolled
you can put constraints in the rigidbody so it doesnt fall
or use more colliders
ok
That did not work when I first tried it as the moving parent would override any physics movement of the player
I feel like there is a way to do this with joints, but i just cant get it to work,
I want to have a line of objects that follow each other, they have a "preferred" distance, .2 units, and will stretch to a max of .25 units, and if the one in front of it slows down too much, they will collide
spring joints just seem to add way too much energy into the system and have it blow up, or dont get pulled fast enough
in 2D the Max Distance Joint seems like what i want, but i dont see a 3D equivalent
so, the end result is i want them to follow eachother perfectly, the way im checking this is by having the leader have a trailer renderer and i want the "children" to follow that trail
Using this code to add knockback to a gun that i've made, but for some reason when the player reaches ~40 y velocity, they keep accelerating upwards infinitely, even though no code is adding any forces. Any idea as to why this might be?
I did find out that if I use my double jump, the player will fall back down (it sets the y velocity of the player's rigidbody)
here's a clip of it happening
use forcemode.impulse, maybe?
I don't know if this is where is should put this but I need help I was making a simple car / bike thing and put the wheels as children of the body and they rotate weirdly how do I fix this
are you using 3d physics?
and is there code and show the inspector of the wheels
How do i check for 3d physics?
Are you using a 2d Rigidbody?
Then you are using 2d physics
3d physics are the ones that doesn’t have 2d on their name
I said to send a video of the wheels when the game runs and see the inspector
Because it can be the scale or rotation
how to i change the collider of the particle?
right now it is the sphere but i want the wood plank collider
i dont see an option
in the renderer it is the wooden plank
ok i found it
under shape
nvm i dont think that was it...
so does anyone know how to change the collision shape of a particle in a particle system?
This happens because the local space of wheel is stretched along some axes. Every parent of the wheel should be scaled uniformily.
I'm trying to modify a chara controller to exclude collision if the hitInfo.collider.name is the same as the player, for a "selective access door" purpose
But this CC uses Physics.CheckCapsule for the last sanity check and this thing has no collider/object callback, so... is there alternative?
I guess i could switch this to OverlapCapsule and check that
i'm doing a car game and i'm using wheel collider for wheels but there is a problem, the collider doesn't work at all, the wheel doesn't collide and just go through the ground, can anyone help?
i solved this
now, why the car is not moving?
You'd have to share some details about what you're doing if you want someone to be able to help.
Im doing custom Physics simulation, soft body with spring mass model, and its working fine, but i have a question
Is it possible to do custom Collision detection ? I have to detect collision of the particles with normal game objects, but the particles are not normal game objects, i have to manually check if a certain position is inside ANY colliders, because i cant use OnCollisionEntry if my particle is not a gameObject
So my question is, is it possible to get all colliders of a scene so i can check all of them for collisions ?
Naively you can just find references to them and iterate over a list of them (i.e. FindObjectsOfType<Collider>())... but without some effort towards optimising that (e.g. search in a BVH or something similar) that collision test will be very inefficient. More efficient would be to use internal physics via Physics.Overlap_() and Physics.Check_() to find colliders in a defined volume.
thx
Didnt fix it :(
I added a velocity cap at 30, and it doesnt continually accelerate anymore, so I think its an issue with unity's physics system?
Show the rest of your code
guys, anyone here got experience with soft body physics im so close to giving up this shit is frustrating asl 😭
guess why it is not a standard feature in realtime-engines 😉
Hi guys! Im trying to let dice fall onto a moving platform. I cant manage to get the dice to stick the the platform once fallen, they just float on the position they landed.
What I tried was to give the platform a physics material with maximum friction, this didnt work. No rigidbody settings on the plattform did the trick as well.
Anybody got another idea? Thanks 🙂
Do your dice have rigidbodies? Do they have a custom physics material?
Yes, I gave them the same physics material to test it as the platform has with maximum friction
This is how I spin the platform. Maybe thats wrong?
Yes this is wrong
modifying the Transform directly bypasses the physics engine entirely
no friction force will be imparted, your platform is essentially "teleporting" into its new position each frame
You can use Rigidbody.MoveRotation, and you should do it in FixedUpdate
Thank you, I will try that!
it should basically be something like:
rb.MoveRotation(rb.rotation * Quaternion.Euler(0, RotationSpeed * Time.fixedDeltaTime, 0));``` inside FixedUpdate
Like a charm! Thank you so much 🙂
I have a bunch of 2d prefab tiles. each has a static rigidbody and a boxcollider set to trigger. I am attempting to do a overlapsphere but am never getting any colliders back. Any ideas as to what may be going wrong? private void CheckColliderMoveTo(Vector3 target) { Vector3 targetPosition = transform.position + target; Collider[] hitColliders = Physics.OverlapSphere(targetPosition, .2f); if (hitColliders.Length > 0 && hitColliders[0].CompareTag("Tile")) { transform.position = hitColliders[0].transform.position; } }
target is a basic vector3 based on move direction. ie new Vector3(1,0,0).
Do your target objects actually have colliders?
3D colliders in particular
and where is the GameObject this script is attached to?
Is it anywhere near the colliders?
I'd guess you're probably just using 2D colliders. Physics.OverlapSphere is for 3D
Hey guys, for some reason my player can pierce and squeeze through walls, even though collisions are somewhat working? I have collision detection on Continuous and I'm using Rigidbody.MovePosition (MoveRotation for rotation) in FixedUpdate for movement. Both the player and walls are just using box colliders. Any help would be appreciated, ty
Hi all, I've been learning unity for quite a while now and now I'm working on a simple car parking project, I'd like to know how you guys typically handle/ would handle the mechanics of checking if the vehicle has been correctly parked, I have tried with bounds.Contains but this doesn't seem to work, does anyone have a script I can use or otherwise a direction I can start following?
i think you can just use a if the car is in the correct position the game ends
I tried something like that but I'm getting some weird things going on, sometimes the position of the car is always the same position as the trigger, I don't know but thanks anyways I just wanted to hear what the best approach would be
do you have interpolation turned on for the rigidbody? if not then moveposition won't detect collisions during movement
Yeah it's on Interpolate
oh wait i don't think it actually detects collisions
you'll need to either have your own collision detection or modify the velocity instead
It seems to be detecting collisions just fine, just not sticking to them
I'll look into changing the velocity though
you can use AddForce
Wouldn't that constantly increase the force and make it go faster?
If you call it constantly, sure
If you add less force when you get up to speed, or add a proportional drag force, then no
How can i make this bike able to move forward by only force made by wheels? Wheels have rotator script which rotates their transform by x amount in time. When wheels are made, the bike keeps jumping because of gravity but doesn't go forward.
Bike
-mesh collider
-rigidbody
Wheels
-mesh collider
The hierarchy is shown on the video. The wheels are Front Wheel Position and Back Wheel Position.
use Wheel colliders.
Rotating transformms isn't going to produce any kind of force
it just teleports them to a new orientation
Will Wheel Collider work even if it has irregular shape? Wheels are made by drawing canvas in left lower corner so user can draw everything.
no
you probably want to attach your wheel to the bike with something like a hinge joint
and then spin it by adding torque to it
"rigidbodies are supposed to act like one big collider" - this is true for collision events but evidently not triggers
i am simply trying to answer your question?
please ignore me then, I'll not answer anything else?
does it only happen when both children are triggers?
hmm what about a raycast shape? @subtle meadow
the first part is wrong, raycasts are not expensive a trigger is more expensive actually
well in my google search no one actually used a raycast shape, just the raycast and well it ended up with try both methods
do you have a source?
Hey do it like this:
keep storing the mousePosition in a variable in update
keep another variable like targetPosition
difference = mousePos - targetPos;
Now move the cube with Rigidbody.AddForce( difference.Normalize * speed)
still using normal raycast and not shapes, might be better to try and tell me
Hello, I'm trying to more or less accurately simulate a Packaging Box used in the industry. It should fold to an almost flat position and extend to a cube shape. I have tried using Hinge Joints but with little success as the physics are very jiggly and don't work at all. I have tried using Inverse Kinematics as well but I'm struggling to make it collide with other objects to make it realistic. I'm quite new to Unity so if anyone has any idea of how this could be done it would be great. Thank you!
Hey guys! I'm trying to make a 3d game that's tiled, similar to minecraft, but I don't really wanna do cubes - I might have to resort to it for ease of programming, but for now, I'm wondering if there are any other regular 3d shapes that tesselate perfectly? they can rotate if they need to, as long as they tesselate with no gaps and with no shapes involved. if there - arent any - then tell me about pairs of shapes that tesselate when put together! i cant see antything about this kinda topic online, so if anyone has any expeirnece, id greatly apprciate the input!
The cube is the only regular 3D shape that tesselates perfectly I believe
There's other, non-regular shapes like this one https://en.wikipedia.org/wiki/Bitruncated_cubic_honeycomb
oh, thank you so much praetor thats the answer i was searching for
I have a question about WheelFriction curve - how do i interpet units of slip - for example if extremum slip is defaulted to 1 and asymptote slip is defaulted to 2 - does that mean it has 1% slip at extremum and 2% slip at the asymptote? I dont know how to interpret the values. I understand the concept of slip (at least i think so) but i dont know how to relate the values to real world.
Very fresh unity user here. I'm trying to do a learning challenge making a ball fall and bounce and stuff. I've downloaded some pipes from the asset store which use mesh colliders. But my sphere does not fall through. The pipe objects have seemingly correct collision meshes
Did you mark the collider on your pipe as "convex"?
if so, there will be no central hole in the collider
If the shape is convex it cannot have any internal gaps or holes
Ooh, that was the issue. And thanks for that image, clears things up a little 🙂
All google-results said to enable "Convex" on the mesh collider, and without really understanding what that was i never tried to turn it off
convex colliders are much more performant in general, but if your pipe is static (non moving) and there's not a million of them you should be fine
Alright good to know, just doing a simple ball-bounce platform challenge as part of a learning pathway and wanted to try with something more than just basic platforms 🙂
my character slipping above the other colliders
i use character controller as a player's collider
how can i keep player on ground when hits colliders?
player movement script
Vector2 move = new Vector2(Input.GetAxis("Horizontal"), 0); characterController.Move(move * Time.deltaTime * speed);
Start by first adjusting the step offset value on the CC component
i tried to change slope limit but nothing changed
i tried 0, 15, 90, 180
oh sorry my bad 😅 i read step offset as slope limit. Now i change step offset value but still same :( when i try up to 1.50 character don't move
Ok i found the problem. Capsule has rigidbody because it is an enemy and follows player. I enabled "is kinematic" option and boom
Is there a way to get a wheel collider that has a contact patch more similar to my actual wheel. I tried doing 2 wheel colliders near the edges of the wheel to get the effect from the rounded tire corners but the wheel does a ghost slide when at a stand still.
This is what it looks like with 1 wheel collider
Uhm, is it really needed?
The only situation I could think of that you 100% need that is if you're doing some type of simulator
Otherwise hardcoding behavior should do just fine
I am doing a simulator 🙂
Its for AI research
Then you probably want to steer off of unity's way of doing things
you can do multiple raycasts
Then get on dynamic friction, static friction, separate side to side friction from front and back
Great
Or just make your own volumetric wheel collider as this guy https://youtu.be/T8MB1Txi2-I (dont really, this guy has to be crazy at coding…)
Hello, I'm trying to more or less accurately simulate a Packaging Box used in the industry. It should fold to an almost flat position and extend to a cube shape. I have tried using Hinge Joints but with little success as the physics are very jiggly and don't work at all. I have tried using Inverse Kinematics as well but I'm struggling to make it collide with other objects to make it realistic. I'm quite new to Unity so if anyone has any idea of how this could be done it would be great. Thank you!
Almost impossible to do realistically. Boxes like that need way more than what performance oriented rigidbody physics with constraints can provide. If you can live with some clipping you can probably do it with some help of a script. Generally, cyclic constraints (ie a closed chain of hinges) that you need here are a tough computational problem.
Hello, I would need help rigging my multi joint robot! What components you would use here to get IK like movement with joint constraints 🤔 I've been stuck on this problem for few days and I'm finally seeking help haha
Is it possible to make an inverse kinematics object work with colliders?
Couldn't find right tutorial for me anywhere
sure, but depends on what exactly you need and how much scripting you want to do. I’m no IK expert though. Someone else will know more.
I don't exactly need the perfect simulation but if it is able to interact with other objects then that's enough for me
That is definitely doable
I'd take a look at some of the setups in this github perhaps https://github.com/TeckUnity/AnimationRiggingPlayground
I think there's a 6 DOF robotic arm constraint that might shed some light on a setup
However I haven't found anything similar online so I'm not sure how to proceed
If anyone has any recommendations I would be glad to hear them
if you describe what you want/need exactly i can try to help. i.e. what should the box' capabilities be?
So, my project involves erecting the box from flat cardboard to its usual cubic shape, and to do so I need to test different mechanisms with Unity and check which is more likely to work once built physically
In practice this equals to simulating a hinge at the top of the flat cardboard holding it in place while a gripper sticks to one side of the box and rotates to erect it
Which means the box should be able to fold and open as well as have a collider so that the hinge can hold it in place
Uhm
You can have two instances of the object, one open and one folded
Just simulate the transition, and when it's done switch the the one you need
Instead of holding it in place which can get buggy after a while
And make sure to increase the physics iterations
Does anyone know if its possible to create a 'skin width' (like the character controller has) for a box or capsule collider?
what would it do?
Skin Width on CC is related to how the Move method behaves
I think there's a "general" skin width setting for the whole physics engine. Project settings -> Physics -> Default Contact Offset
I did manage to figure out that setting the default contact offset to like 0.00001 mostly fixed my issue, is that a 'safe' setting for it?
im making a box-shaped rigidbody character controller and it gets stuck between meshes even if the surfaces are completely flat
I don't fully understand it but I have noted that there's all kinds of issues that a large setting has for it
yep this is a common issue
Unity is the ultimate game development platform. Use Unity to build high-quality 3D and 2D games, deploy them across mobile, desktop, VR/AR, consoles or the Web, and connect with loyal and enthusiastic players and customers.
Look a thread that I participated in back in 2015 about the subject lol
darn built-in physics is up to no good again
reducing the default contact offset seems to be the simplest solution.
ok ill go with that, thankyou!
would using Collider.contactOffset for my character's collider be a better solution? rather than changing the offset for everything?
TBH I didn't know that was a thing
so maybe?
ok yeah that does the trick, while also not messing with every collider in the game as a bonus
oh wait no, now its sticking again, I guess ill just change the global parameter
Suppose two footballs of the same mass are launched starting one meter off the ground, at 64 km/h, but one of them has fins.
When launched horizontally, the finned football would travel further than the normal football before touching the ground.
When launched vertically, they would rise and fall at the same rate.
It is not windy, and they are thrown with perfect accuracy.
How could I mimic the behaviour of the football with fins?
Some people say that the one with fins would definitely fly further, and due to the fins it'll follow a much straighter line. For launching them vertically, the fins won't make a difference.
Other people say it wouldn't really unless you can't throw a spiral, in which case the non finned football loses speed much faster from drag while tumbling. It would also fly higher at a given velocity
Surely whichever is right, there's no difference whether you launch horizontally or vertically?
You think so?
What could cause there to be a difference?
If the finned version flies further because it has less drag, it has less drag when thrown in any direction
Unless you launch them so hard they leave the atmosphere but 64 km/h isn't going to do that
Hi! I have a tricky problem 🙂 I have the following hierarchy: GameObject:Player(RigidBody) { Camera, GameObject:Sphere }
I'd like to always keep the "Sphere" GameObject in front of whatever direction the "Player" GameObject is moving (not necessarily where the camera is facing), facing the "Player" GameObject.
So far I've tried using Player.rigidbody.velocity's x,y,z values to position the "Sphere" GameObject, but that doesn't seem to work well, it's never ahead of the "Player" GameObject. I'm suspecting this is because velocity increases over time.
Any help would be much appreciated!
Figured it out, my main GameObject was rotated so all the values were incorrect 🙂
Alright so I'm gonna try to word this. I have a characterController which rn is just a capsule collider. Using this online tutorial, I made it so the characterController will slide down slopes of a certain angle. However, it goes apeshit when running into completely vertical walls, or when a curved-edge of the capsule collider hits any type of corner or edge. Would anyone be willing to help me find a solution for this?
PS: here is the online tutorial I used https://answers.unity.com/questions/1358491/character-controller-slide-down-slope.html
Unity is the ultimate game development platform. Use Unity to build high-quality 3D and 2D games, deploy them across mobile, desktop, VR/AR, consoles or the Web, and connect with loyal and enthusiastic players and customers.
I can kind of tell WHY it's happening, but I can't necessarily figure out how to fix it
Hi Guys. Looks this is a better place to post this question:
I was wondering if Unity had any built in way to allow a dynamic rigidbody to move up and down slopes without sliding off when stopping, or not bouncing off slope when moving down?
Or is that just a matter of buying an asset or doing some rather complicated code in C# to apply forces along the slope?
Basically is there anything similar Godot's snapping of one rigidbody to another with 'move_and_slide_with_snap?
There is no built-in in way, no, you have to do it yourself (or buy a character controller asset).
Thanks man
Anyone knows where I can get free customizable physics for car?
I used AddForce as impulse for my player jump, but when stationary the force is barely strong enough to lift me off the ground and it looks like a stutter instead of a proper jump, why would that happen?
this is standing still
this is while moving
I feel like im missing an important thing about physics
can we see the code
sure
Ill go grab it but iirc it's just an addforce
fired when the input system fires the spacebar event
yep
I was thinking about implementing a separate force for stationary jumps but i'd rather not have hacky fixes 😭
and how do you move?
Oh
for some reason that question made me figure out the problem
I think it's the custom friction code
Since im not moving it's overriding the velocity
now to think how to fix this i guess
🤔
what if instead of setting the y velocity to zero i just take what i already have in that friction if
that
aye that didnt help
i thought you meant setting velocity instead of using addforce mb
Actually
it did
thank you
np
The lighting looks sick lol
Does it? I've been trying to get something working in a while rn
if i may ask what kind of game is it?
That sounds epic bro
you got a demo to try?
Not yet, theres barely a level
does anyone know why my rigidbody controller is doing this?
the left ramp is a convex mesh, and the right ramp is not set to convex, ideally I want to make the level out of fewer probuilder objects which would require most stuf to not be set to convex
Im removing a mesh collider and adding box colliders to an object. Is it bad for colliders to intersect?
That sounds amazing
its not necessarily bad if it works while playing with no issues, but usually you want to avoid that
@tall sorrel any particular reason to avoid it? I'm assuming it has something to do with not being able to detect which collider is responsible for a collision where the colliders intersersect?
That would be one reason yes, it could mess up physics when using rigid bodies, it also could impact performance if you have a lot of colliders usually there might be a better way to combine the colliders, but its not entirely the worst thing in the world if you have colliders overlapping
Okay thanks. I'm trying to figure out what's less resource intensive; A mesh collider or several box colliders as empty child object with primitive colliders attached? The reason for the child obiect instead of the parent object having colliders on it would he so you can use primitives, but angle them to the contour of the object, thus avoiding mesh colliders
it depends on how complex the mesh collider is
but usually multiple primitives will be faster
Even if they are each their own object?
it definitely depends, i'd advise to do some research and look at the profiler
https://www.youtube.com/watch?v=FxYiFRzp84Q
I compare the speed of different physics collider in Unity. Mainly I created a script that instantiates many rigidbody with different collider types attached to it and see what the CPU consumes.
Twitter: https://twitter.com/DEEntertainme
I watched that video durring some preliminary research. I suppose I just have to run some tests to determine the best performance for my use case
Thanks for your help guys I appreciate the advice and input : )
looks like you should use mesh colliders for static scenery but anything that moves should use a bunch of primitives
and overlapping them is fine
@flat palm If you attach a rigidbody to the gameobject multiple colliders will act as a single composite collider, so unless mistaken it should count as a single collider and wont hurt too much
posting a new video that might make it clearer if anyone can please help me fix concave mesh colliders shoving my player like this that would be awesome!
im new to ragdolls and just started using unitys built in ragdoll system, when i activate the ragdoll, it works but i thought possibly turning it off then back on would reset everything and make it ragdoll again but no, it stays in place from the first time it ragdolled, anybody know how to fix this?
I have an issue with 2D colliders that don't want to interact, someone could help me ?
using UnityEngine;
public class Bullet : MonoBehaviour
{
public float Speed = 730f;
public float Drag = 0.023875f;
private Vector3 gravity = new Vector3(0,-9.81f,0);
private Vector3 position;
private Vector3 velocity;
private float timeElapsed;
private int layerMask;
void Start() {
layerMask = 1 << 8;
position = gameObject.transform.position;
velocity = Speed * transform.forward;
}
void FixedUpdate() {
velocity += gravity*timeElapsed; //apply gravity
velocity += -Drag*velocity; //apply drag
gameObject.transform.position += velocity * Time.deltaTime; //move the bullet in front of the ray
RaycastHit hit;
if (Physics.Linecast(position, position + velocity * Time.deltaTime, out hit, layerMask)) //interpret the result
onLinecastHit(hit);
position += velocity * Time.deltaTime; //move the ray forwards
timeElapsed += Time.deltaTime; //increment time
}
void onLinecastHit(RaycastHit hit) {
print("I hit" + hit.point.ToString("F3"));
Destroy(gameObject);
}
}
How's my bullet script? It casts a ray that's affected by speed, drag, and gravity.
Seems mostly ok. Just a few things:
- the
positionvariable and the Transform position are redundant. You don't need both. - the
timeElapsedvariable is redundant. it can be replaced withTime.fixedDeltaTime - The position + velocity * Time.deltaTime calculation is being duplicated. You should just do it once and reuse the result.
- hardcoding the layermask is a bit inflexible. Consider using a serialized LayerMask variable instead.
Here are the changes I made:
public LayerMask layerMask = -1;
void FixedUpdate() {
velocity += gravity*Time.fixedDeltaTime; //apply gravity
velocity += -Drag*velocity; //apply drag
RaycastHit hit;
Vector3 displacement = gameObject.transform.position + velocity * Time.deltaTime;
if (Physics.Linecast(gameObject.transform.position, displacement, out hit, layerMask.value))
onLinecastHit(hit); //interpret the result
gameObject.transform.position += displacement; //move forward
}
Is there a reason why timeElapsed, the total amount of time that passed by, should be replaced with Time.fixedDeltaTime, a constant value?
The longer the bullet stays in the air, the harder it is being pulled towards the ground.
well yea terminal velocity exists which makes any falling object stop accelerating and fall at a constant speed, but I don't fully understand how it works yet
This doesn't have anything to do with terminal velocity
what am I missing
If you multiply gravity by time elapsed, velocity increases exponentially
Pull of gravity is constant
The velocity of a falling object increases linearly
oh that's true
Because the time elapsed in FixedUpdate is always Time.fixedDeltaTime. This is documented in the Time.deltaTime docs.
for me it always says 0.02
I see
it (effectively) gets called every 0.02 seconds and the logic within should represent what happens every 0.02 seconds
(this number can be changed in project settings)
what I really need is the difference between the time the gameobject was instantiated and the current time
why
i mean, i did before
velocity += gravity*Time.fixedDeltaTime; this calculation seems correct to me
basically for the reasons Nitku said above
how's the behavior look now
if you want to use the full elapsed time since it started then you would be doing velocity = instead of velocity +=
show your current code?
also try with drag = 0 for a minute
your current drag value is pretty aggressive
you're taking 5% of the velocity away 50 times per second
that's going to give you a very low terminal velocity
show code
public float Speed;
public float Drag;
Vector3 velocity;
Vector3 gravity = new Vector3(0,-9.81f,0);
void Start() {
velocity = transform.up * Speed;
}
// Update is called once per frame
void FixedUpdate() {
velocity += gravity * Time.deltaTime;
velocity += -Drag * velocity;
gameObject.transform.position += velocity * Time.deltaTime;
}
yeah looks alright
how to know what amount of drag would be appropriate?
for large projectiles
Well your drag model currently doesn't take the cross sectional size of the projectile into account at all
I could probably plug that in http://www.navweaps.com/index_tech/tech-073.php
Yes
public float Speed = 44f;
public float SurfaceArea = 19f;
public float DragCoefficient = 0.33f;
public float AirDensity = 1.225f;
private Vector3 dragForce;
Vector3 velocity;
Vector3 gravity = new Vector3(0,-9.81f,0);
void Start() {
velocity = transform.up * Speed;
}
// Update is called once per frame
void FixedUpdate() {
velocity += gravity * Time.deltaTime;
dragForce = .5f * AirDensity * velocity * SurfaceArea * DragCoefficient;
velocity += -dragForce;
gameObject.transform.position += velocity * Time.deltaTime;
}
That message means your object is too far away from the origin for Unity to track its position properly
also dragForce should not be directly added to velocity
it should be multiplied by Time.deltaTime and divided by the object's mass
(as you do with any force to get the resulting velocity)
public float Speed = 44f; //m/s
public float SurfaceArea = 0.4185f; //m
public float DragCoefficient = 0.31f;
public float AirDensity = 1.225f; //kg/m
public float Mass = 0.149f; //kg
private Vector3 dragForce;
Vector3 velocity;
Vector3 gravity = new Vector3(0,-9.81f,0);
void Start() {
velocity = transform.up * Speed;
}
// Update is called once per frame
void FixedUpdate() {
velocity += gravity * Time.deltaTime;
dragForce = .5f * AirDensity * velocity * SurfaceArea * DragCoefficient;
velocity -= dragForce*Time.deltaTime/Mass;
gameObject.transform.position += velocity * Time.deltaTime;
}
looks good
this is probably what a baseball would look like if I ever threw one
I don't know if this is the right place to ask, but how would I make something not register collision with the player, but detect collision with everything else as well as gravity?
Hey guys, I'm trying to get a Moving Platform working for my controller. I'm moving the kinematic platform by using MovePosition in FixedUpdate. On the player I'm settings the velocity to the velocity of the platform your standing on. (I get this through OnCollisionStay)
Moving Platform Code
Moving With Platform Player Code
The issue I'm having is that when I increase the speed a bit, the player very slowly slides off, and there is a small difference in velocity's between the player & platform rigid bodies. Any help appreciated 🙂
I'm no expert, but try turning "Angular Drag" down to 0. No idea if it'll work, but it might.
In the Rigidbody
Ill try it one sec
Wait i just realized, its the drag in general
Pretty sure the velocity of your moving platform will always be zero. MovePosition does not set the RB's velocity property.
you should print that out and verify
no the velocity changes ive checked
rigidbody info
that your player is moving at all is probably due to friction
See if that plays out if you debug.log the velocity as well
mhm
Alright so it was the drag on the player
last issue to fix is him walking slow on the platform
@wicked night
thx for the suggestion homie
not exactly, but you reminded me that drag is a thing lmao, which was limiting the players speed
🙂
Is OnTriggerEnter faster to compute than OnCollisionEnter? (2D, I can use either one just as well in my case.)
Intuitively I think so (because physics bouncing doesn't have to be calculated), but my intuition doesn't always work with Unity. 🙂
Afaik oncollisionenter is much faster. Collisions are calculated once every physics update and if hit is detected, unity sends collisionenter message to scripts. Triggers on the other hand are not part of the physics loop. When you use them on script, the trigger collisions gets checked once per OnTriggerEnter function. So if you have 100 gameobject and everyone of those have OnTriggerEnter function on one of their scripts, trigger collisions needs to be calculated 100 times.
Gotcha, thanks. 🙂
I don't know if this is the right place to ask, but how would I make something not register collision with the player, but detect collision with everything else as well as gravity?
Hello everyone. My team are working on a university project where we try to implement a Billiard table/game. We got a lot done so far but we'r having a little problem for a while now and cant figure how to fix it. For some reason, after the billiard balls got hit by the cue, instead of slowing down in a fluently motion, they abruptly slow down. We are using the default unity physics and we'v been struggling with this problem for weeks now. We have found some unity forum messages about this and that it is supposed to be a unity bug, still I'm here and asking if someone found a way to fix this in any way. It would really help us a lot. thanks in advance.
layers?
can you send a video?
my bad. give me a second
Here, the first example is right after the cue hit the ball. The second one occurs a second after the ball hit the wall.
Ignore the unrealistic mass and friction. We'r testing some values but the problem occurs either way. Just about the slow down for now.
might be friction combine
what value should we use in that ?
theres different options
as minimum and maximum
test them
I remember. we already tried all options for the friction but non seem to help with the slow down
We talked about that earlier and the problem seems to be the lack of rolling resistance, you need to implement it yourself (idk what is correct formula for that tho) #⚛️┃physics message
Hey - i wanted to make some kind of ragdoll here - so the arms will wiggle around while moving. Added a Rigidbody to the arm and a character joint but somehow it is messed up. Can somebody help?
Thanks a lot @desert wave @unique cave ! We'll look into it 🙂
Do collision meshes take vertex normals into account?
I'd like to know whether I can skip proper vertex normal generation when generating collision meshes (for terrain).
not 100% sure but id imagine they doesn't matter. could you try it by generating simple mesh and trying physics with it with different normals?
I don't think so. They use the clockwise triangle ordering of vertices to determine which direction the triangle is facing. The normals are just for rendering AFAIK
Yeah, thats how i understand it too
A 2d rigidbody just slides after addforce. Any way to dampen the effect? I want it to slide a tiny bit, but increasing drag or friction makes the physics wonky
The physics engine simulates real life physics. Think about how objects stop moving in real life and apply that
Friction, but that makes the physics wonky
What I'm getting at is newton's first law of motion. Objects in motion stay in motion. If you want to slow something down you must apply a force in the opposite direction of motion
It doesn't have to be friction
You can apply any force you want whenever you want
Are you applying your own friction force or that of Unity's colliders?
I tried both
Maybe I could add force in the opposite direction for a frame after stopping
Using your own friction force correctly is not trivial - you can easily end up where applied friction force is too large and makes the object move in the opposite direction again.
why mu bulllet just slide on the wall
But Unity's collider friction shoulnt exhibit this
instead of destroy
strange
Rigidbody drag is also a decent option. Just be sure to pick a low number (< 0.05 or something)
@open skiff Do you have top-down 2D or platforming 2D?
Platforming
And it slides over platform when you want it to stop after a while?
Or is it gravity-less
I'm making a game like Terraria or Starbound, so sandbox, and it just slides
Like a terribly designed ice level
right
collider friction man
i cant imagine you cant get the desired result with that
Let me try again
Also, there are different friction modes. Something like multiply, average, min, max, right?
think so
Try to stick to the default (multiply or average probably)
reasonable, thanks!
and start with friction like 0.5 and tweak from there
Although I dont think friction > 1.0 is a thing.
yeah
Keep in mind that both the platform collider and the rigidbody collider have their own PhysicsMaterial (although this is kind of obvious when you think about it).
If you disabled rotation on the Rigidbody then you probably need even lower friction (< 0.2)
There is also a project-default PhysicsMaterial in settings somewhere i believe.
Yes
nice, I'll set the player to the appropriate weight in kgs
Always a good idea. Same for lengths as well.
👌
around 80kgs for someone (took average between lowest of both genders)
k, thanks!
why does increasing the number by which I set my WheelCollider's MotorTorque not increase the speed?
the rigidbody drag is set 0
@cobalt pilot You mean its not spinning at all?
it was but it wasn't getting faster as I was increasing the torque
found a sweeetspot at 1000
but not using wheeelcollider anymore now
Hello, I want to make it so that my character doesn't glitch into the wall and I have a feeling that this problem has something to do with physics
I added a rigidbody and a platform effector so far
Hello, We have turned Physics off in our game. Yet I would like to reproduce the "AddForce" algorithm. Does anyone know if there is an implemention anywhere for me to study?
Would this be a good start?
Today's video games offer an incredibly realistic, immersive experience, due in large part to their true-to-life simulations of physical phenomena. By far the most commonly simulated effects are those of Rigid Body Dynamics.
Toptal is pleased to have our very own Nilson Souto present this first installment of our...
it actually is
This too
Physics is a part of games that has always amazed me. I find it funny how impossible it seemed to do correctly when I was younger. While making a custom game engine, it was finally demystified!
The full article: https://blog.winter.dev/2020/designing-a-physics-engine/
The background game demo: https://winter.dev/demo
0:00 Intro
0:26 Dynamics
...
I usually dont question someone else's design choices here but I have to say this is a strange one. What is the reason to partially re-implement physics like this yourself?
That's a great question and, I'm doubting my design choice as well. I want to optimize my code and only kind of need this portion of physics. PhysX is taking up a huge portion of the performance. So, in the concept phase we are doing some tests of running the code with and without PhysX. By doing our own implementation I could also tweak how often I do the calculation; furthering our performance.
But, please, put me to the hot irons and question me
you can slim your physics scene too
- What is the PhysX contribution in terms of, say, milliseconds per update?
- Are you dealing with 100 or perhaps 1000 dynamic rigidbodies and/or colliders?
- Are you dealing with a lot of non-convex MeshColliders on dynamic rigidbodies?
if you only need AddForce, you can remove all extra colliders and don't have your rigidbodies collide with anything
but without knowing further details it's really hard to tell why the physics were heavy to begin with
general assumption is.... you can't make physx equivalent yourself and have it perform better unless you strip out all the expensive to compute parts
(meaning it will be way less functional)
- I don't remember how many milli seconds per update, - 1000 rigidbodies and colliders, - I've just learned that different colliders can produce different performance results and will be adjusting accordingly
Just keep in mind:
- Super fast: SphereCollider, BoxCollider, CapsuleCollider
- Reasonable: CONVEX MeshColliders
- Slow: Non-convex MeshColliders
- Extremely slow: MOVING non-convex MeshColliders
This is an old project that I worked on in 2018 for a few months before my team assembled. My first attempt but, not the end of work on the MVP. God willing, we will get back to working on it. We are going to be updating the designs, mechanics, and code.
www.ButtonDownStudios.com
www.FaceBook.com/ButtonDownStudios
ContactUs@ButtonDownStudios.com
Im not even sure if the last one (moving non-convext MeshColliders) is still allowed in Unity
it is not
this is the proof of concept video
they removed that possibility in Unity 5
we are supposed to have 100s of units per side
Heck I'd use CapsuleColliders for all of those.
What kind of colliders do they have right now?
I believe MeshColliders Don't remember if they are convex or not. We've started with a new code base
I hope not because of the physics performance because I reckon there is a very good change the PhysX implementation/performance is salvageable
IF the performance problems are indeed MeshCollider-related
You ought to just check it out and try it if that was indeed the case
You've proven a great point of doubt I've had and will switch coarse
Thank you!
Ohh, there is one thing though... It's going to run on an Oculus/Meta Quest 2
I dont know much about VR but those devices are just the "screen" right? The actual computer is connected with a cable?
no they run without a PC connected to it. It's basically a Cell Phone level processor
Oh
Took me a couple of days to write this. I had to learn and use ECS and AR foundations. This is just to get familiar with the technology. Since ECS is still in development I will not be taking this project to far. I would love to add "NetCode" to project but, that too is under development by Unity and, is not very stable.
Either way it feels go...
This is what I did with DOTS
Well if you would like to get an idea of what physics performance is like on that thing you could perhaps spawn 1000 basic shape colliders and let them bounce around in a box or something. Just as a quick check to see if that will kill the CPU or not
If you're already comfortable with DOTS - there's always DOTS physics
itll do everything for you
forces, collisions, etc
We'll we have to go into stress testing soon
We dropped DOTS for this version
Only thing it cant do from what ive experienced myself is have 2 colliders that move within the same rigidbody (imagine something like a retractable panel on a vehicle or whatever)
We don't have that issue but, that's great to know
But depending on the fidelity of physics you need, doing it yourself can be a real headache.
If you dont know or care about rotation inertia tensors then perhaps you could get away with writing simple AddForce(...) and AddTorque(...) and such yourself.
AddForceAtPosition() is also not too difficult
Another debate has to occur over "Rigid Bodies" collisions without Physx. To keep the ships from colliding together.
The question is can you turn off Physics and still have rigid bodies so that two gameobjects don't collide?
But as soon as you need something more advanced (joints, proper collision physics, friction) you're probably better off trying to optimize your PhysX usage as much as possible.
So when you say "turn off Physics", what exactly do you mean? Not using any "standard" Rigidbodies?
Actually turn off PhysX. There is a line of code to do that : "Physics.autoSimulation = false;"
If I use "AddForce" yes they don't move
Ok im not sure if im understanding your question but you want to know if rigidbodies can still "maintain separation from another through the collision system" while the actual simulation is frozen?
Yes, I'm not going to test it this week but that's on the docket
Man, I really wouldnt know. This sure is a strange way to use physics in unity
I know, it's squezing performance out for a Meta Quest
My advice remains unchanged lol: really try to see how much performance you can squeeze out of PhysX.
Oh that thing has a modern snapdragon processor
Will do. But testing things in the concept phase is what we are doing
It's not totally weak but, I mean I had a tough time with many units on my own laptop so I can't imagine that the Snapdragon processor would fair better
Phone processors are kind of funny in a way because theyre really unreasonably fast at certain things. E.g. video encoding
If I can get them "maintain separation from another through the collision system while the actual simulation is frozen" and write my own simple "AddForce" then as far as I can see we are set
I'll still going to try it out with PhysX on as well. No need to complicate the code, if it does work out
Also if PhysX works my programmer will go nuts with collision based damage when I've already planned out that our damage will be a math based calculation
We've be going back and forth on that debate of how to handle damage
That would add a bunch more phsics related stuff to an already taxed system
I had AddForce for particles somewhere but I cant find it, so I'll do this from memory:
- For VelocityChange:
velocity += inputVector; - For Acceleration:
velocity += inputVector * deltaTime; - For Impulse:
velocity += inputVector / mass; - For Force:
velocity += inputVector / mass * deltaTime;
Now I'm thinking, we go down the road of leaving PhysX on during our preproduction phase and if it doesn't work out we do it my originally planned way
Maybe you need more than this but this is basically what happens in AddForce.
That's what the webpage basically states as well 😀
The first link I posted
Right. Its just physics basics.
AddTorque is a bit more complex
AddForceAtPoint is more or less a combination of AddForce and AddTorque
I'm not going to need AddTorque. We just need the part you stated
Although if you ignore inertia tensor then it basically simplifies to something idential to AddForce
Hello, I am trying to make a platformer game. But I have a slight problem with the image above happening. I think it has something to do with physics so yea
how are you moving it?
arrow keys
i mean do you modify the transfrom?
yes
that's the problem, you need to use a physics friendly way
ah
so what I am thinking now is that with that platform object I create a wall and check the trigger or smth
move the cube in a physics friendly way, and the overlaping will be over
@echo sluice Thank you for the debate
@icy nexus Instead of modifying transform.position and transform.rotation, try modifying rigidbody.position and rigidbody.rotation. Doing it like this should take collisions into account from what I remember. (Otherwise, you can also try to use actual forces)
No problem. Let me know if you need anything else.
oh ok
@icy nexus Oh I think i made a mistake. It should be rigidbody.MovePosition(...) and rigidbody.MoveRotation(...).
ah I think you are right cuz im getting an error but its fine
So for rigidbody.MovePosition(...), you input the new position it should be
Also your character should have a Rigidbody2D if it doesnt already have one
Yes exactly, physics stuff should happen in FixedUpdate.
Although FixedUpdate does weird things with input
oh
You can store input data in Update() and use them later in FixedUpdate()
But does it collide properly now?
yes it does work
but I think I see what you mean about weird things with input
the up arrow input lags pretty hard
Let me know if you need help with working around the input problem
ok
@echo sluice I am still having problems with the code and I think its because it only reads one input at a time
plus for some reason the downward velocity is very weird
I think I know how to fix that tho
actually im not sure
@icy nexus I have to go now but you can send me a screenshot of your code in a message to me if you want
then its easier for me to find what is going on
ok
how to add jumping to rigidbody??
Does anyone know how to describe the next situation scientifically? How do you call the force that prevents the bottom part of the "pole" from going up? Friction? How would you calculate it? I want the bottom part to remain static on the same spot instead of sliding when the object falls to the side.
yes it's friction
friction force comes from the coefficient of friction between the two surfaces * the area of the contact patch * the force pushing the two objects together
so - bigger contact patch = more friction. Objects being pushed together harder = more friction
Would the force that push it together would be gravity in this case?
And do I need to get a project of it along the object vertical axis?
yes, you need the downward component of it only
any sideways component doesn't contribute to the friction calculation
or more precisely:
- parallel force doesn't contribute
- orthogonal force contributes
So it should be something like frictionCoefficient * Dot(gravity, objectDown) * gravity?🤔
How do you even call a motion of a an object falling on it's side while supported by the ground? Is there a term for that? 😅
"toppling"?
This upward force is called the "normal force".
"Normal" as in, it always points along the surface normal
I was actually referring to the horizontal force that prevents the bottom of the "pole" from sliding.
Oh lol I completely interpreted your explaination the other way around
red cross on arrow pointing up = "this force is missing - i need it!"
Yea nevermind, the other one is friction as you and the other person said
Hi !
I just want to confirm : Does we need to use the fixedDeltaTime when using an AddForce / AddForceAtPosition ? (if used in a FixedUpdate of course)
I'm working on an airplane simulation, and i was struggling with the calculation of aerodynamic forces (and many other things) where i always had to add a x50 multiplier to have a "realistic" result... And i just realised that this should be the reason X)
No. AddForce in the default ForceMode already multiplies by fixedDeltaTime as part of its internal calculations
also as a side note, you shouldn't even use AddForce outside FixedUpdate
well, I now mean if you use force mode, it's fine for impulses regardless where you call it from
Yeah.. just noticed... Now eveything is working as i was expecting.. lift, thrust.. -_-
That's really not intuitive
i'm talking about the AddForce that already does the multiplication with the delta Time, not the physics ^^
It's as intuitive as you can get I think. Forces are applied over time in real life. When you want to know the effect of force you say "n newtons applied over t seconds"
so it is intuitive that forces are meant to be applied over time and that they work in standard units. the unit of force is a newton.
Force by definition includes deltatime, if you somehow take it away for game physics that's actually very counterintuitive
yup i see what you mean. 👍
you can always just use ForceMode.Impulse instead of ForceMode.Force (which is the default) if you want to omit the deltatime part
but then you have to add the DT component to it if you want actual forces so you are just doing what physics engine did for you in the first place 🙂
Yup. 👍
and now everything is working as expected ^^ 💥 https://cdn.discordapp.com/attachments/833953986910224395/913540505206394960/2021-11-25_22-21-49.mp4
Theres something i have a problem with but im not sure how to explain it, its a little complicated, i tried explaining it before but no one could really understand. im trying to make a water slide but the tube won't curve with the slide
basically what i'm doing is i have the tube attached to an invisible sphere
to ensure that the tube doesnt suddenly stop midway and keeps going
but its rotation is also frozen so it doesnt roll with the ball
but that also makes it so it doesnt really look like its properly sliding down
why doesnt the tube rotate?
because i turned off its rotation
so that it doesnt rotate with the sphere
because then it would be rolling and that would look wrong
hey, i have a physics questions about objects with front/back heavy masses
suppose i have an object like a ninja throwing dagger, where the front part is the heavier metal blade and the back part is the lighter grip
in real life when throwing this dagger it would obviously fall blade-first into the ground every time (assuming it has the time to rotate before hitting the ground)
is there any way i can simulate this on game objects? or atleast a clever way to fake this kind of effect?
you can change the center of mass
really? how?
rb.centerOfMass
yes? just change it to whatever you want
dang, and here i was preparing my heart for a whole headache of physics coding
i'll check out the docs, thanks a lot
you can change the center of mass to closer to the blade and it should make the trick
yea im looking into it now
shame i cant do it in editor
you could probably make some sort of editor script to change it
probably, but i dont think i'll get into that this early into development
well, the center of mass is working when the object is balancing like a seesaw, but it doesnt make changes to the rotation when falling down to make the heavier side land first
Oh, I did understand this bit wrong... why would ninja daggers land blade-first? mass of object doesn't affect gravitational acceleration...
air resistance is also very negligible so it doesn't make much sense to go heavier side first. anyways im pretty sure there's no build-in way to do that, you need to code that yourself (maybe you could use either AddForceAtPosition or AddTorque)
id try to add force that's pointing at opposite direction of velocity at the lighter part of the object (using AddForceAtPosition). that would simulate air resistance on the lighter part of the object and would rotate it to go heavier part first. if you move the center of mass closer to the heavier part, even small air resistance should be able to rotate the object without slowing down the object too much
if i were to throw a knife in the air, the heavier blade side would always be the one pointing down when it falls, right?
isnt that because it's heavier compared to the lighter side of the handle?
not right. if you throw your knife in vacuum, the center of mass wont affect the rotation. center of mass affects the rotation only if theres large amount of air resistance but in case of relatively slow, heavy and small knife, heavier part shouldnt go first. ofc you can do that in your game if you want but as far as im not mistaken, thats not physically precise behaviour
in real life you need to be very talented at throwing them if you want them to go blade first. in this video he actually uses knifes where the handle side is heavier, it doesn't matter https://youtu.be/xuSjZ9mWIHU?t=530
hmmm, i'll have to reconsider my approach then
games doesn't need to be physically accurate but that's the reason why it doesn't work like that by default
i think i'll just fake it by setting some other pivot point for rotation
and just do it manually with a gradual pointing down rotation
you could try this if you want it to also work when you throw it sideways or in any direction
ill give a try
Hi. How do I make a mesh collider work? Like, I've exported a hall from blender to Unity, but the mesh collider doesn't seem to work properly, the physics inside the hall just do not work
Is the mesh collider set to convex?
Yes
then how do I make it so it has an "inside"?
don't make it convex
But will it work then?
why wouldn't it?
I don't know. All the times I tried without convex it just didn't work as a collider I don't know why
Well I can't speak to that.
But if you have a cursory understanding of "convex" you would know that it wouldn't work the way you want if it's convex
Well, I'll try disabling "convex"
Nope, it just doesn't collide at all
The capsule just falls through it like nothing
That's why I do not understand what disabling the convex option would do
well first - your hallway has either no rigidbody or a kinematic one, right?
if it has a dynamic body, then concave colliders are not supported
Concave vs convex is this. Convex has no "internal space'. Any two points on it can be connected by a line that never exits the shape
If this is the case it may just be issues with your hallway's geometry. Missing or inverted faces for example
no rigidbody
then your geometry is just messed up
honestly it's better to make colliders for something like a hallway out of primitives anyway. It'll be more performant
well okay
I'll try that thanks
And is there any way to make a box collider but like inverted?
that I can be inside it?
6 box colliders
4 walls, a floor and a ceiling
I guess mesh collider with inverted normals could work
Is there any way to do that in Unity?
You just need to make the mesh in blender or other modelling software
https://www.youtube.com/watch?v=Qjf6_tu_Oq4
Hi guys how would you recommend beginning to do something like this? (Breaking water, Controlling water movement)
Today I'm super excited to be showcasing Breakwaters. In Breakwaters, you explore a procedural world with dangerous ocean depths and massive Titans in an Exploration Survival game that changes the way you interact with water. Displace water with powerful crystals harvested from the world, delve into its depths to collect rare resources, build wa...
hi guys, why IgnoreCollision doesnt working?
Can you maybe explain what we're seeing in the video? Just looks like a guy slowly moving to the left to me. no idea what I should be looking at.
Also there's no need to repeatedly call IgnoreCollision every frame. Doing it once in Start is sufficient.
gear is moving guy to the left
A. Why does the gear even need a collider?
B. WHy not just put the gear in a layer that doesn't collide with the player's colliders from the get go
you don't need any code for that
A.because there will be several of them and they should be separated from each other
B.they are in different layers
So set up the layer collision matrix.
That's all you need to do
no code is needed (make sure you do it in the 2D physics section, not normal 3d physics)
thank you 🙂
Should I be putting "wheel" colliders on the wheels of the mesh (which are children of the root part), or should I add "wheel" colliders to the root part of the mesh and just move them to where the wheels are?
Or does that not affect the wheel physics at all?
ive got an object with a rigidbody whos colliders are in the childrens object, this to make it more modular, however, when i add a force to the parent it also makes the child colliders rotate a bit (in local space), how can i stop this, they need to act like one rigid whole?
also if i add a force to an object in a vacuum that isnt in line with the CoM, will the object still get inertia?
you need to add a joint that fixes the position of the children relative to the parent. I don't remember the name of the correct one off the top of my head, but there's only a few joints. It should be pretty easy to figure out which one is right
When you apply a force that is not in line with an object's center of mass, it has two effects--it has a "force-like" effect that gives the object a linear acceleration, and a "torque-like" effect that gives the object rotational acceleration. If you split the force into part that is pointing toward the CoM and part that is perpendicular to that first part, the part pointing to the CoM acts as a force and the part perpendicular acts as a torque.
Hey, i figured this is the Channel to ask Collider Questions, if not please point me there
I need to find the closest point on the surface of a collider, but using collider.ClosestPoint gives me point inside the collider as well, i need it ONLY on the surface so i can push points outside of the collider
Does unity have a function for that or do i need to figure it out myself ?
You need to figure that out yourself
i don think joints would work for this since the children objects dont have rigidbodies, they are litterally just the renderer of a part of the whole and contain the collider at that spot
they dont have a rigidbody, only the parent object has it
bit random - im working on a hooded cape for my character, using the cloth component. I want to make it so that I can fold the hood back and put it over at will. Any ideas?
This sounds more like a bone control thing than a clothing system, as the animation you expect is very complex.
Yeh I've decided to just stick with a cloak for now, but I was thinking I'd add a hood as a separate object and pivot it to create the illusion of pulling the hood back
I mean, having two bones that just work as like a half circle with bone weights might do the trick too, so you could still use cloth to have like the cloth go a little bit up and down with super low weight paints but still control the position mainly with the bones you are setting.
Yeh that was what I was thinking, thank you
I was just wondering if there was a simpler way
Depends, do you really need physics calculation for cloth on the hood when its on the back, or maybe just for a cape and not the hood/hat thing itself? but thats performance analysis for later maybe
At the moment I'm just focusing on the cape, I may make the hood later, and make the sides of it cloth enabled but mark the main body as immovable and move it with bones
how can I move the player behind the tree? I tried changing the sorting layer and layer order but it just makes it worst
You need to change the sorting axis:
https://www.youtube.com/watch?v=q-r1YJzj28M
don't crosspost
I tried, it didn't work
You need to fix your sorting layers too. If you made them all on various layers to attempt to fix it to begin with.
If I am using a character with rootmotion and using a walk animation blend tree to blend between each cardinal direction with WASD input, should I have the animation controller update mode in animate physics or normal?
It is a non rigidbody character. It's just using a character controller
Im making a soccer game, but instead of pushing the ball, my character just walks on top of it, how do I fix this?
Are you using the character controller?
Play around with the values, such as lowering the step offset.
But also note that the CC doesn't interact with rigidbody physics, if you're expecting your ball to be pushed around by it.
You have to do your own detection (there's a collider detection built into the CC), and apply your own forces to the ball.
The step offset helped it. Thanks!
why Rigidbody2D don't have AddExplosionForce ??
it's really Unfair 😦
What can cause inconsistent physics between a HDRP and a URP version of the same project?
I have a VR game made in HDRP and I also release it in a URP version to ship on Quest standalone. The code base, prefabs, physics (solver iterations...) and time (fixed timestep...) settings are exactly the same and the rigidbodies and joints have the same parameters at runtime. Yet, I can notice that the joints are less stiff in the URP project!
The FPS is approximately the same. This happen in both editor and builds. The main noticeable difference between the two versions is that the HDRP project uses OpenVR, while the URP project uses OpenXR on desktop, and Oculus on Android (the issue is visible in both desktop editor and android build) .
Do you know what can explain the difference of stiffness?
Never mind I found it. It appears that OpenVR, on the HDRP version, is changing the fixed timestep upon start with a much lower value.
using UnityEngine;
public class HorizontalLaunch : MonoBehaviour //zero gravity
{
public float Speed = 10f; //m/s
public float DragCoefficient = 0.4f;
public float SurfaceArea = 0.79f; //m
public float Mass = 2f; //kg
private float airDensity = 1.225f;
private Vector3 velocity;
void Start() {
// initial velocity v0
velocity = Speed * transform.right;
Debug.Log(calculateTimeToReach(3f, velocity));
}
void FixedUpdate() {
//change velocity over time
var dragForce = velocity * 0.5f * airDensity * SurfaceArea * DragCoefficient;
velocity -= dragForce * Time.deltaTime / Mass;
var displacement = velocity * Time.deltaTime
//move object
gameObject.transform.position += displacement;
}
float calculateTimeToReach(float x, Vector3 v0) {
return (float)
System.Math.Sqrt(
(Mass*x + Mass*v0.magnitude) /
(0.5f * v0.magnitude * airDensity * v0.magnitude * SurfaceArea * DragCoefficient)
);
}
}
I am trying to write a method that can calculate the time to reach a given position before the projectile is launched. calculateTimeToReach(float x)
I do this by rewriting the function used to move the object.
https://imgur.com/LqTKivR
var dragForce = velocity * 0.5f * airDensity * SurfaceArea * DragCoefficient;
velocity -= dragForce * Time.deltaTime / Mass;
var displacement = velocity * Time.deltaTime
Fd = v * 0.5 * p * A * Cd
v = v - (Fd) * t / M //insert dF
dx = v * t
v = v - (v * 0.5 * p * A * Cd) * t / M
dx = (v) * t //insert v
//the result
dx = (v - (v * 0.5 * p * A * Cd) * t / M) * t
dx = v - (0.5 * v * p * A * Cd * t^2)/M //simplify
Then I solve for t:
t = ±√((M * dx + M * v0) / (0.5 * p * v0 * A * Cd))
Hey everyone. Simple question here. PhysicMaterial (sic...) has an enum for determining which friction combine method is used when determining the (dynamic or static) friction coefficient for a collision between two objects.
The documentation says that, when these two enum values are not the same, the one with the highest priority is chosen. "The priority order is as follows: Average < Minimum < Multiply < Maximum." (quoting unity documentation)
However, when casting the PhysicMaterialCombine enum to int, the order goes 0 = Average, 1 = Multiply, 2 = Minimum, 3 = Maximum
My suspicion would be that the documentation is wrong here, flipping Multiply and Minimum. That would mean the physics internally just take the highest value.
Or is it actually worse and is the documentation correct, with the physics blithely ignore the enum ordering?
Great question. I haven't played around with friction enough to ever notice. Maybe try some tests and see what you find?
Yeah, well that's sort of the issue. I don't think I have any reliable way of "requesting" the final results, so my best bet would be create a couple of wildly varying PhysicMaterials and try and estimate what combination of values best matches the observed behavior.
Doable, but I was hoping somebody might just have run into this before, before I had to do that work 😉
anyone familiar with wheel colliders? i wanted my car to be able to go up the curb smoothly but it's very sudden
wheel collider is just one ray down from the center
so if you want that kind of case to look smoother, your curb collider has to be more round
@nimble crater
or rather, smoother
To get back to this, I can now confirm the documentation (Maximum>Multiply>Minimum>Average) is correct and the priority is irrespective of the enum's int values (so in fact it goes it 3>1>2>0....)
7th column shows Multiply takes precedence over Minimum.
HingeJoint. I find the documentation for what resting angle is relative to confusing (or non-existant).
I've come to the conclusion the actual direction is the (joint.anchor - transform.position). I kind of expected it to be (joint.anchor - joint.connectedAnchor). Anyone have any insight regarding this?
Is there an alternative for APR Player
Thanks for sharing your results! This is the kind of stuff that needs to get added to the uninomicon: https://uninomicon.com/
Will try and see if I can add it. At work we have quite a few more where this comes from
To make it simple, I'm trying to implement an animation when my character is in the void (that's not the problem): it's gravity that's not acting correctly. I want him to fall faster, if possible:
presumably your script or your animation is moving the character in a way not conducive to physics
and is thus overwritign the Rigidbody's attempts to fall due to gravity
Do you actually need Rigidbody physics for your game? Maybe just do the gravity bit yourself.
yes I need it
My guess is you've got a line something like rb.velocity = moveDir; but what you actually want is
moveDir.y = rb.velocity.y;
rb.velocity = moveDir;
I need to attach a payload at the end of a robotic arm driven by articulation bodies.
Having a classic rigidbody on the payload, with a fixed joint won't do, because the joint must be very stiff.
I tried to parent the payload under the arm end using a fixed articulation body but this causes the whole articulation body architecture to reset in its initial pose.
What' is the best practice?
So I have a basic model of a crate, should I make it into a mesh collider for more accurate particle effects or keep it as a box collider for better preformance?
it all depends on what you want but for me it seems box enough to be box collider
ah
box collider is heck a lot of better in terms of performance
makes sense
I'm going try this
I made this char in vroid and wanted to use it in vrc but the hair keeps doing that, it has no weight it gets just stuck in the air, dont know if i have to do something different in vroid, blender or unity
here is the same problem in vrc with the test before
im using hinge joints on something for vrc but i keep getting clipping issues and when theyre moved they fly away from where theyre connected to
So I have a shipping container object that I want the player to be able to go through, but still collide with the walls. I know mesh colliders are expensive, is there an alternate solution?
Static mesh colliders arent really that expensive, bounds calculations takes care most of collision checks. Second way would be to make compound collider by using multiple box colliders. You can also make simplified mesh for mesh collider only to improve performance still maintaining good visual quality.
Ah
Sorry for the ping, are you sure about that? I've been using primitive colliders for my modular kits because i've always been told mesh is expensive, but what you said actually makes sense, if they're baked whats the problem? 🤔
I mean they are not baked but bounds are something that every collider uses, bounds are always checked before any more complicated collision checks
Yeah my bad, meant to say static
It doesnt need to be static either
By static I meant you dont change the shape of collider runtime which is quite expensive
Oh even better. Thanks for the info
I'm going ask something else in here in the meantime. I have a set of points which make out a path. An object follows this path. I thought
time to move from point to next = distance between the two points / a constant
would be enough to have smooth movement between points but for shorter distances it still goes faster than with longer distances, what am I failing to consider in my calculation?
Lets say you have only 1 active rigidbody in the scene and 1000 objects with mesh colliders on it, only very few of closest of those mesh colliders needs to be checked because bounds doesnt collide. For those 995 colliders, type of collider doesnt matter at all because they are ignored anyways
It does makes sense, wonder why i never thought of it
Is there a way to physically move a car by rotating the tires?
I'm currently trying hinge joints, but if the tires rotate, the temporary car model box slowly approaches the ground
I remember seen some rigidbody + joint tutorial on youtube but ig thats not going to be very good since theres no any good collider shapes to match the tyres
This seems correct. You have probably something wrong in code, you can ask that in #archived-code-general for example (share the code there)
Probably, I still doubt that will be better than unitys wheel collider/custom raycast controller
Wheel Collider has shot my car to the moon when it hits an obstacle a tenth of a unit high before
I don't know what's with it
I've also tried a raycast based car system, but when I turn, the car banks (I think that's the right term) way too much on it's turns
Is PhysX 4.1 the latest PhysX version integrated from Unity 2019.3 on?
anyway to make this physics movement a lot more smoother?
https://www.toptal.com/developers/hastebin/lefidutove.csharp
and the mouse movement
cause i have no idea how to do it
Anyone who could help with Ragdoll Physics? My characters head is going all over the place.
This is how it looks like
Its most likely something to do with the wrong relations between joints ( beginner guess though )
But would really appreciate if someone can explain on what I should check when I get this kind of behavior.
Physics Debug
it looks like you have some overlapping colliders in the hips area. Go through and make sure none of your colliders overlap. That's my guess as to what's causing the jitter. The Brackey's video on setting up ragdolls is pretty good. It shows how to do a lot of the configuration. Following all the steps there will probably help debugging your issue as well.
So the colliders must not touch each other by any means?
They can't be inside each other. If they are, the physics system will try to push them out (this is what dynamic rigidbody/colliders do), while simultaneously trying to keep them in their original position (this is what joints do). It wants them to be in two different places, so it ends up very unstable (causing jitter).
Thanks for the great explanation man! So I can freely use some extra space to separate them from each other and possibly avoid jitter.
Also the ragdoll maker-unity tool didn't make some parts so I had to create them on my own
When Unity says Vertex data for meshes isn't in the Dedicated Server builds, does that mean they expect that collision and physics queries won't work against any non-read/write asset?
It seems difficult to make performant client and server shared assets if the server requires all collision meshes to be read/write
"and not used for internal systems" is probably the key line here, whatever they mean by it
I'd just test it in practice instead of making assumption that everything has to have read/write checked. I mean doesn't Unity bake collision data for physics separately anyway?
having actual mesh data in server side that doesn't have to render anything makes very little sense, which is probably the main reason for that optimization
@north hollow ^
having read/write tagged textures and meshes on server builds is also probably related to just keeping the thing from breaking as you'd typically want to manipulate that data if you have those options checked.
In this scene, there are elongated rectangles that represent lines. The player can drag them to rotate and lengthen them in order to accomplish the winning scenario. I need a way to get - when two of these game objects overlap - get the exact point and notify the player.
I tried to add a Collider2D to each game object, and then a Rigidbody2D with x,y coords fixed. Then using an OnCollisionStay2D method I got the ContactPoint2D and sure enough the first contact point from contacts[0].point. The outcome though was not what I expected, with said point sometimes not being even on the surface of at least one of the colliding game objects.
Any suggestions to how I could fix this, or another way to implement it would be welcome.
Actually, me asking this question is because I just upgraded our game to Unity 2021.2.4 and we started falling through colliders when playing our game against our dedicated server backend. I have created a very simple repro case and sent that in as a bug. In this case I don't think the game objects are tagged as static in our game level since they are only enabled in certain game modes. Some of the colliders do still work on the headless server though.
I should update my bug reproducing project to test for the case where a non read/write mesh is marked as static to see if it gets collision on headless server.
For anyone curious, my tests show that a collider marked as static but not imported as a read/write mesh does not work in the headless server physics
I can't find any configuration that seems to control what is stripped out of the Dedicated Server builds
When I log a normalized WASD movement vector and am holding A and W I see that it outputs (-0.7, 0.7). My understanding is that normalization ensures the value is 1 regardless if the input vector is < 1 or > 1. So if I'm understanding this correctly, the output is correct because it is adding sqrt(0.7^2 + 0.7^2) which would be ~ 0.98 or pretty close to 1
Is there anything equivalent to the interpolate function for rigidbodies that applies to classic Particle Systems?
I am trying to set limbs modularly, where some limbs may have ‘sockets’ where other limbs can set - however i just need to them to freely flop around. I am using Configurable Joint, and everything either balls up or will fly around like crazy. Limbs are being instantiated via script.
it is supposed to be more chain-like, not ball-like.
The green is player, blue is a body-like limb (has sockets that limbs can connect to, setup with sockets as the location that limbs are set to w/ autoconfigure anchor) and the purple is limbs.
probably not setting the anchors correctly, so they're all anchored to one spot in the middle somewhere
dunno if this goes here but i want to try and create a sort of parallelogram collider with an object like this. Is there a way to do so in 2D?
follow up, is it significantly resource intensive?
nvm i sure it's more than box but not enough to turn my Laptop into a nuke
i am trying to make a car but the car isn't moving
as you can see the wheels are rotating but the car isnt moving
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CarController : MonoBehaviour
{
public void GetInput()
{
m_horizontalInput = Input.GetAxis("Horizontal");
m_verticalInput = Input.GetAxis("Vertical");
}
private void Steer()
{
m_steeringAngle = maxSteerAngle * m_horizontalInput;
frontDriverW.steerAngle = m_steeringAngle;
frontPassengerW.steerAngle = m_steeringAngle;
}
private void Accelerate()
{
frontDriverW.motorTorque = m_verticalInput * motorForce;
frontPassengerW.motorTorque = m_verticalInput * motorForce;
}
private void UpdateWheelPoses()
{
UpdateWheelPose(frontDriverW, frontDriverT);
UpdateWheelPose(frontPassengerW, frontPassengerT);
UpdateWheelPose(rearDriverW, rearDriverT);
UpdateWheelPose(rearPassengerW, rearPassengerT);
}
private void UpdateWheelPose(WheelCollider _collider, Transform _transform)
{
Vector3 _pos = _transform.position;
Quaternion _quat = _transform.rotation;
_collider.GetWorldPose(out _pos, out _quat);
_transform.position = _pos;
_transform.rotation = _quat;
}
private void FixedUpdate()
{
GetInput();
Steer();
Accelerate();
UpdateWheelPoses();
}
public float m_horizontalInput;
public float m_verticalInput;
public float m_steeringAngle;
public WheelCollider frontDriverW, frontPassengerW;
public WheelCollider rearDriverW, rearPassengerW;
public Transform frontDriverT, frontPassengerT;
public Transform rearDriverT, rearPassengerT;
public float maxSteerAngle = 30;
public float motorForce = 50;
}