#⚛️┃physics
1 messages · Page 82 of 1
Fast moving objects is kind of a misnomer
It's just about your frame rate
I don't know why continuous doesn't prevent tunnelling in this case, it should
well I'm not sure what you're doing but what I did was to have the first loop fixed in space and others can swing freely. not even continous collision detection can guarantee objects not going thru each other when stretched from both sides with large forces.
I think it might be an angular momentum issue, if it was simply two links being pulled with great force then CCD would never allow it to tunnel
Since of course the links in a long chain will rotate that might be what's causing the issue
Maybe one day we'll have quantum computers and collisions can be done a lot more efficiently
Then we can use more sophisticated algorithms
yep, it has nothing to do with rotations
afaik two objects should never go thru each other (with ccd) but if there's third object and the object in the middle is pulled in both direction, you're in troubles. lemme show you
Yeah I had also considered it may be an issue with resolving collisions between more than 2 objects
But I'm almost certain if you only have 2 links and they aren't rotating you can pull them with whatever force you like and they won't tunnel
that should be the case, but I'm not sure if that's still guaranteed. there may still be some edge cases when using compound colliders
For performance reasons it doesn't really make sense not to use joints anyway
Like this. Plane is using mesh collider and doesn't have Rigidbody. Both balls have sphere collider. Both balls have Rigidbody with Continuous Dynamic Collision Detection mode. Smaller ball have mass of 1 and the larger have 200
That's very weird tbh
I guess if the small sphere is fixed and the plane is removed the issue isn't still there
If it is I just think the CCD algorithm sucks XD
it is but on the other hand, you very rarely need that type of collision on real game application. game engine can't have "perfect" physics engine because it has to be very optimized
yes. it works perfectly if smaller sphere is set to kinematic or Rigidbody removed
I don't think you want to use collision based chain physics anyways so not really a big problem. If I set the mass of bigger ball to be 50, the problem is gone. That's just rare edge case that isn't a problem on 99.99% of games so who cares
Nice !
Just for the little bit of extra realism it might be nice
I believe that's not going to give any more realism on regular games with reasonable amount of forces applied from multiple directions. With more computation power you could obviously use some Two Minute Papers level physics on games but that's whole another story
ok so if u freeze the y pos and have it bounce it doesnt bounce
why is that?
like a sprite moving across the grid
How i can fix this in Unity 2022? https://www.youtube.com/watch?v=xjoW_UAywVo
what's the problem?
Rigidbody Interpolate in Unity 2022
didn't watch the video in detail but it seems like there's a part where it's working as intended?
201* < 2019, 2020, 2021 - Correct
2022.* - Incorrect
if u freeze the ypos a sprite with bounciness enabled wont bounce
When it hits something
Have you tried interpolation
there is something that i discordverederd
is that interpolation can have with calculations involving the coordinates of a moving rigid body
it seems that without interpolation, the calculations are based on the coordinates of the body in the last physics timestep
however with interpolation the calculations are based on an estimation if the rigidbidy within its current and next step
At the time between the current and next timestep that the calculation takes place
so its more accurate
No. Interpolation only affects visuals, not physics. Physics are exactly same with and without interpolation but interpolation just smooths the look of movement so it’s not that jittery
Then explain why calculations involving the rotation of a rigidbody are correct only when the rigidbody has interpolation
i rly need an explanation sorry i didnt mean to tie that up to your question
this rly confuses me
Now this confused me too 😂. I may be wrong too but that’s how I have been understanding it
What you mean by this exactly?
You do that in update?
its the same result when the calculation is done in fixedupdate
It seems to rely on the interpolation of the rigidbidy
which seems stupid, i understand why you thought fixedupdate should do that and i thought that aswell, but it doesnt
I didn’t mean to say it only affects ”visuals” but I wanted to say it doesn’t affect physics. Actual position and rotation of transform/rigidbody (not sure which or both) gets interpolated but collisions are still calculated with the same fixed rate
When interpolation is turned on “rigibody.position” and “transform.position” will give different values
“rigidbody.position” will be the true position of the physics body while “transform.position” will be the position of the “fake visual”
im pretty sure my program uses the transform of the visual and not the rigidbody, is that the issue?
of course
it maks sense now thank yoy
if you're making gameplay/physical/logic decisions based on it, then yes
I think you might be dealing with a large physics timestep, and you are trying to solve inaccuracies there using interpolation instead of a smaller time step
Can you tell us what you mean by “the calculations lag in fixedupdate”?
Im getting the rotation of an object with a rigid body
the rigid body is rotating constantly with the angular velocity set to a constant value by code
it seems to give the rotation of the rigid body before it updates its rotation
so it has 2 rotations at t=0 and t=1
It gives the rotation at t=0 which is outdated because the rigidbody is already at t=1
It’s not outdated in terms of the physics engine tho
no
It’s outdated in terms of visual frames
ye
There’s a key distinction there
Is the vector your trying to calculate going to be used for visuals, or other physics stuff?
yes its the velocity of a child object
Then what you are seeing isn’t outdated and it’s the value you want to be using tbh
If you are using transform.position or rotation for a physics calculation with interpolation turned on, you’re gonna run into problems
Try switching to rigibody.position and I bet you’ll see that the calculation is laggy or behind again, even in Update()
@stuck bay what’s your physics timestep set to?
default
i havent checked because i dont want to change the timestep bc im having issues with one calculation, kinda feels like im giving up
Are you running at 60fps or 144fps?
Because at default timestep, that means at 144fps you’ll be running physics 1 time for every 3 frames
Physics vs frame mismatches are more noticeable at higher FPS
if the default for 2020.3 LTS is 60fps then yes
I mean what’s your monitor support?
60hz or 144hz
idk
get the normal of the slope by passing a raycast on it then project onto the plane with the normal
https://youtu.be/cTIAhwlvW9M this video has a ni xplanaion if it
The third part of my Rigidbody FPS Controller series. In this video, I covered slope handling, fixing the weird jitter, and improving the ground detection. In the next one, we will start working on the wallrunning *yay. Make sure to subscribe so you don't miss it :)
Discord Server Invite: https://discord.gg/6ASySnPVXB
GitHub Repository: https:/...
I have an oddly specific question.
I'm doing bullet trajectories manually, as to avoid having to do massive amount of calculations per frame with the Rigidbody component.
However, the bullets only inconsistently detect collision.
Is there a way to use the Rigidbody continuous dynamic or speculative without just using Rigidbody physics?
Because I'm going to have enough bullets that Rigidbody physics calculations won't be viable.
The relevant part of my physics sim code is as follows:
{
if(!isInitialized)
{
return;
}
if(startTime < 0)
{
startTime = Time.time;
}
RaycastHit hit;
float currentTime = Time.time - startTime;
float nextTime = currentTime + Time.fixedDeltaTime;
Vector3 currentPoint = FindPointOnParabola(currentTime);
Vector3 nextPoint = FindPointOnParabola(nextTime);
if(CastRayBetweenPoints(currentPoint, nextPoint, out hit))
{
Destroy(gameObject);
Debug.Log("Hit object: " + hit.transform.name);
}
}
private void Update()
{
if(!isInitialized || startTime < 0)
{
return;
}
float currentTime = Time.time - startTime;
Vector3 currentPoint = FindPointOnParabola(currentTime);
transform.position = currentPoint;
}```
collision in this case is your raycast?
or are you racasting on top of relying on OnCollisionEnter?
or OnTriggerEnter
In this case, I generate points according to a physics formula, and move the bullet from point to point, creating a nice, good-enough looking arc trajectory
And the bullet has a box collider on it
idk why i can't type a code block with tildes anymore
And the collision is assisted by casting a ray from current point to last point
to see if it hit anything
yeah so if you're raycasting, isn't that skipping any sort of collision detection completely?
I.E raycasting can't be discrete or continuous, it's just raycasting.
The weird part is how inconsistently my collision works
Sometimes it will properly detect floors and walls
in theory what you have should work pretty consistently
but
I'd like to see the rest of the code
alright gimme a sec
{
return Physics.Raycast(startPoint, endPoint, out hit, (endPoint - startPoint).magnitude);
}```
and also there's a caveat with raycasting - it doesn't detect objects that the ray starts in
if you're bullet is already inside of the object
oh this is straight up wrong too
You're using it like LineCast
you should just use LineCast if you want to do it this way
Wow didn't even know about that one cool
return Physics.Linecast(startPoint, endPoint, out hit);```
Linecast takes two positions (like you have)
Raycast needs a position, a direction, and a distance
you are improperly providing a position as the direction parameter
that probably explains most of your issue
CastRayBetweenPoints is his own function though so we're not sure if he's already accounting for that
?
He just showed the code here
is it not?
it's doing a Raycast, improperly
lmfao whoops
well he was on the right track
direction should just be (endPoint - startPoint)
welp apparently that was the issue
got bad advice for that a while back
did about 50 attempts, with perfect collision detection
@split wedge basically you were raycasting in random directions lol
Still got a lot to learn with proper raycasting still lol
seriously this problem has plagued this project for a long time thanks
hey you fixed your code and learned how to replace some of it with a cool built in function!
always nice to not have to reinvent the wheel
idk if you can see this but the script does in fact reference the visual frames as you guessed correctly (Transform gridTransform - a declaration of the visual transformation of the object with the rigidbody component and not the rigidbody itself)
i just thought it would be more efficient because i only wanted to reference the transform attributes of the rigidbody
But for that they would need to have equal transforms
which is possible for an rigidbody of course only if it is synchronized with the object’s visual frames, which is what Interpolation or increasing the physics steps does
anyone know how to make the physics of this game better?
Download the source code by clicking on the link below:
https://code-projects.org/piggy-zombie-shooting-game-in-unity-engine-with-source-code/
[For educational purposes only]
Become our member:
https://www.youtube.com/channel/UCTcaqNZBMBrrtEXHxPne2bQ/join
📱Download our app from Play Store📲:
http://bit.ly/scpapps
Subscribe To "Source code Pr...
can anyone tell me why the friction's not working
you are trying to make your character move using the friction of their feet?
sounds like a very bad idea
how are you moving the character
animation
so why would friction do anything?
yeah i need it to make the realistic collisions afterwards
well the feet have colliders, so friction should work
Animations don't really work with physics
they just kinda teleport the stuff around
at best you use this https://docs.unity3d.com/ScriptReference/Animation-animatePhysics.html
and in that case - well read the caveats in the documentatioin
it's not gonna move the guy around the way you want
i see
so i guess friction will only work with force like things?
what if i apply force to the legs, should work?
and there needs to be actual physical rigidbody motion for it to do anything
if you apply a force to a non-kinematic rigidbody, it will accelerate, sure
um okay, i'll try smthn tnx
Physics and animations don’t mix well
I work on a lot of physics focused games and normally I have to start with physics and then lay animations on top of that
Instead of starting with animations and relying on root motion
Im having an issue with mesh colliders not colliding but box and capsule colliders are. I'm not sure how to fix this (all the colliders are set to convex btw)
Might someone be able to help
i compared it to a working example and here is what i found
this is what the working example uses to access the rigidbody transform component
gridTransform = other.transform;
and this is how the not workng example references it
shipTransform = other.GetComponent<Transform>();
i changed it to shipTransform = other.transform; however im still experiencing the same problem
what i dont understand is why this method works for one script but not another
its a rotation offset
visible at higher speeds
its because its parenting after the parent gets a non-zero rotation offset
which is a script execution order issue
the other setup doesnt have that issue bc its ordered in-script
ig the issue just wasnt visible with less extreme angular velocity
So I've made an active ragdoll balance and play walking animations and stuff (with AddForces and a bit of maths). My method of moving the character around and to balance it is to have an invisible sphere underneath it that rolls around and stuff but the issue is whenever I move, since my player's hips are attached to the ball by a spring joint he kinda just rolls with the ball. Is there a way I can make the hips stay connected but not rotate with the ball?
I'm rotating the ball with AddTorque
hi, should i update an object's velocity in fixedupdate or update?
im currently running this code in fixedupdate, would this object accelerate at the same speed on 144hz vs 60hz?
Your monitor refresh rate doesn’t affect anything unless vsync is enabled. The acceleration in fixedupdate should be independent of your monitor hz and fps (because fixedupdate happens at fixed rate). Changing the physics timestep can change it tho
The default of 1/50 is usually pretty good. Interpolation takes care of the little jittering
is there a velocity equivalent of transform.forward?
i'm trying to apply velocity along forward vector
… just set transform.forward to velocity?
I feel like 60/120hz physics are way more common in games than 50hz
greetings. I have some small dice. 0.004 mass, and 15 mm in unity. When I throw them, when they land and stop, they like to continue to slowly rotate around the y-axis even though they should be all rights not be moving anymore. I have dynamic friction set to 1.
why do they keep rotating?
I don't know if this is the problem here but large and small colliders together may cause some very weird jittering. what type of collider is the one the dice is landing to?
large table with a box collider
you could try to use mesh collider for the table instead
hmm. these dice are using mesh colliders. i wonder if switching to box colliders would help
oh weird. i would think primitives would get better results than mesh
in this case I have heard mesh collider is better than primitives. especially two primitive colliders with large size difference produces some jittering problems
id probably try box for the dice and mesh for the table
tried changing them both around. mesh, box, vice versa. same issue. i may just get y delta pos, and when its not moving in y, set all velocity to 0
Might someone be able to tell me why my mesh colliders arent colliding but every other collider is?
nvm fixed it
Trying to create some ragdolls on this model. These ranges mean the arm should be able to swing forward and side to side, right?
Not sure if this is the right channel, but does anyone know why this happens, I just added ragdolls and they just kinda float away, Use Gravity is checked on the rigid body
I would recommend 1/60, because of dividends and mapping. So at 60hz you have a 1:1 map, 1:2 at 120... results in higher perceived smoothness due there being no “phasing” essentially between frames. Interpolation can of course do either, but it just tends to be a bit more accurate this way since you have more regular input data.
does Rigidbody have a method to move an object over one frame only, while also checking for collisions?
my issue is that Rigidbody.velocity and .movePosition rely on the object's drag coefficient, so the object's movement is spread across multiple frames.
i'd rather have it move on one frame only. So far, I only know of Transform.Translate, but that causes collision jitter
hello, does anyone have knowledge about wheel colliders not colliding. cant rotate as have realised. but once aligning the wheels with the colliders, not long after. they rotate another direction... does anyone know how to fix this issue? or any advice
@timber pelican maybe you can do boxcasting or spherecasting to solve your problems
you'd box/sphere cast and move the shape afterwards
question: if i have a 2d scene with a bunch of objects forming a "wall" like the tree sprites do here, is having every one of them have their own collider and rigidbody (like the single selected tree sprite where the bird is sitting would have) hell for the performance or does it not matter
furthermore how much more intensive are polygon colliders compared to the given 2d collider shapes (rectangle, circle, capsule etc)
you can probably approximate the bird tree with a rect
Nope not really
MovePosition
it does not care about drag at all
Maybe, but I still noticed the movement on the object was still spread over multiple frames. That's an issue for me because I need to sync position of the object to other players, but any position data I send to others is already old data because the object continues to move on the next frame on the server.
Don't confuse game frames with physics frames
MovePosition abides by interpolation settings on the Rigidbody
but the movement happens over exactly one physics frame
Ok, I'll try it again. My rigidbody had no interp on, so I'll see what happens if I change it.
you may also be seeing some interpolation from your networking framework. Depending on how things are configured
there's a lot of factors at play
I debug.logged the position data sent on the server and received by the client, and both were the same. Changing movement to transform.translate did not have movement discrepancies, so I don't think it's that. Both are on local computer for now, so shouold be very very little delay
Oh wow it's a Unity function, I'll have to take a look!
are you reading Rigidbody position or Transform position
i read Transform.position
should generally be reading the RB position, as that won't be subject to any interpolation from any sources.
Hey I have a problem, my object stops to bounce if the velocity is low, how can I fix it?
i don't get how angular velocity works. it says it's radians/s, yet a value of ~157.104 results in 1 revolution/second !?
am i missing something obvious?
increase bounce in the physic material
oh no
the opposite
reduce friction
yes yes someone helped me already. thank you
that could be an aliasing problem. 157 radians/sec is ~25 rotations per second, which happens to line up quite closely with 0.5 rotation per fixed update. So it might be doing almost a full rotation every 2 fixed updates and you only see the small deviations.
Same issue as this video shows: https://www.youtube.com/watch?v=uENITui5_jU
Music: Monolith - https://open.spotify.com/track/2Dujp1sL96EJo2HNAlZoIq
TikTok DMCA verification - Fed 26 2021
Link to TikTok video / account that reuploaded this video without permission
https://www.tiktok.com/@m0tivationspeech/video/6929951454979558662?sender_device=pc&sender_web_id=6933447920746890758&is_from_webapp=v1&is_copy_url=0
Add me...
i figured it out. i was mistakenly doing an angular velocity conversion with Rigidbody.transform.InverseTransformVector instead of Rigidbody.transform.InverseTransformDirection
once i fixed that, the values started to appear sensibly
damn, I was excited for aliasing to show up as a real issue in physics rather than just rendering
hehe, well i did have to divide by fixed delta time to get an almost perfect velocity on each update 😉
hey uh weird question
is it normal for objects with rigidbodies to fall even with no gravity?
no, but you probably have gravity and you just don't know it
apparently restarting unity fixed the physics weirdly enough
I have weird shit like that happen to me all the time
where physics material all of a sudden lose all friction lol
until I restart the editor.
Compiled builds are always fine though
I assume this is a beginner question. I'm getting familiar with Rigidbody Physics and am having a challenge that I'm having trouble researching. I assume the right person will just know that answer 🙂
I have two player controlled characters. When one is hit I apply force to their RigidBody (dynamic body type). When a player moves I call MovePosition in order for there to not be a feeling of velocity when moving.
At this point in time I'm not preventing movement during a push and what ends up happening is the movement removes all of the velocity from the push. For example if I'm pushed to the right while the player is running up I'd like the character to continue progressing up but be pushed right simultaneously, allowing the pushed player to fight against their velocity of the push if they so choose.
Any help would be appreciated
As soon as you use MovePosition to move an object, you're basically removing that object from interacting properly with physics forces.
Is there anyway I could get my Rigidbody to constantly stay up with a torque? What I have now is a character standing on its legs with target rotation but I don't think there's a way for me to keep my character upright with target rotation without having it always point in one direction. Correct me if I'm wrong
If you aren't moving an object purely with forces (velocity), you won't be able to achieve true physics responses
MovePosition is a function that in essence teleports the object, and any collisions that happens in between will not be treated with actual collision responses you expect.
Hm... Okay. Sounds like I need to design around it then. Either prevent movement during push or use velocity for movement.
Thank you for your insight
Ok so scrap what I said
Is there any way to only control the X and Z angular drives?
I am trying to set up collisions between the player (has a box collider + a kinematic rigidbody) and a tree (has a box collider), but I just cannot work it out. I want the player to simply stop moving when reaching a tree 🌲
I am using 2d sprites in a 3d world, so I cannot add gravity to them, but I can freeze their position*. Is there a way to fix this? Tried so many things but got nowhere so far
I don't understand how the fact that they're sprites or not is relevant
The Renderer is not relevant to how it moves
Is there a reason you want to use a kinematic body?
If you're using a kinematic body you'll need to do all the collision detection yourself with e.g. BoxCasts
yes, the movement script the player uses does movement through the rigidbody component, and I've been reading if I want something to move I need a kinematic body for that
and if gravity is involved the object will either fall to the ground, or flies away if I disable it (since all the sprites are 60 degrees rotated on the X axis)
What does the rotation of the object have to do with "flying away"? And yes gravity makes things fall that's what it's there for.
Where are you getting the idea that only kinematic bodies can move?
Here's what a kinematic body won't do:
-collide with anything or be stopped by any obstacles.
why does my wheel collider not collide
and no, it isn't rotated
and it is in a seperate child object under my car
I have a projectile that moves 350 meters per second, and i need to know if it collides with anything by Physics.OverlapSphereNonAlloc or Physics.OverlapSphere, my projectile is supposed to penetrate through some objects, and that's why i use overlap sphere to gather information about what it hit, and if it is penetrable, but OverlapSphereNonAlloc and OverlapSphere doesn't work, and i think its because of the speed the projectile is going, can anyone help me fix it, or have any better idea to implement penetration?
@mortal venture there probably isn't good reason to keep that physics simulated rigidbody in the first place, just sweep it
if u mean why i don't use rigidbody, it's becuase i need penetration, rigid bodies didn't work for me
oh I thought you were using RB already and that was causing your issues
but yeah, you could just sweep test the hits
oh maybe it will work, thx!
Is there a way to set the linear limit of a configurable joint in script?
its giving me this error
"Cannot modify the return value"
I want to set it to my blade's stab depth but the IDE is telling me that I can't because even though it has the whole {get; set} thing, it just isn't doing it
my current workaround is creating a new SoftJointLimit, assigning stabDepth to that and then assigning the new SJL to the joint
which seems to do it
I've got a solution now
just store the current SoftJointLimit in a variable, then modify that, then set the joint's SoftJointLimit to the stored variable
I'm making a car racing game with the wheel collider and it was working but once I added the mesh when it touches the ground is starts shaking violently how can I fix that
same but my collider does not collide at all
with a floating object, I am applying a force of X to the rigidbody. If I double the mass, will I have to apply a force of 2X to get the same movement
that is how forces work, yes
assuming you are using ForceMode.Force or ForceMode.Impulse
There are mass-independent force modes too - Acceleration and VelocityChange
ok thanks
Iamma explain the prob
The player is hovering at height of 0.25
And the player Is an overlapped box with penetration vector and velocity projection vector that minimise the velocity if your touching wall so u dont clip into it the offset I mentioned above messes up the projection on the y axis so idk how to fix that
How can I lock my player to a chain(using hinge joints)?
is there a way to check if two object's colliders are intersecting, externally from objects?
so imagine 3 hierarchy objects: observer, box1,box2.
can I as Observer detect if box1 and box2 intersect?
hello unity folks, i made a car controller, followed this tutorial https://www.youtube.com/watch?v=Z4HA8zJhGEk
but why don't my car move?
[UPDATE] If you are looking for the breaking bugfix check the description after expanding it!
Let’s learn how to create a car controller in Unity. We will get to know Unity’s wheel collider component and use it to move a car. We will also create a simple camera script that will follow the car.
[BREAKING BUGFIX!!]
There is a bug in the HandleMo...
oh apparently inputs
are the issue
same to what
Wheel collider
oh I just added a collider then it slowed down the shaking so now I'm going to leave it as car engine
if my 2d character falls a long ways it kinda pancakes, it seems its rotating on a 3d plane but it dosent show any signs of doing so, please help
@stuck bay does your cube have a collider too?
yeah
huh
this is from the second picture
are they on layers that don't collide with each other?
I think it's the correct one
is your cube spawning inside the mesh collider?
im honestly not sure what's going on here
I dont think so but i dont really know about mesh generation. Could it be that you need to bake the mesh on the collider?
How would I do that?
maybe not then, Mesh and meshfilter dont appear to have a bake method
damb
im honestly not sure
I tried asking in beginner code and someone told me it's not a code question and to ask in #⚛️┃physics
burh
Thanks for trying to help me though
Mr goose
I appreciate it
I’ve never created a shape with code before, but is there any chance your normals are backwards?
I didn't make the normals
Unity does it for me
And if you use a mesh collider without creating the shape manually it works?
IE assigning through editor?
That would narrow it down to code
It does in fact work
Hmm
That is very weird
I mean
the mesh looks fine
But it just clips through
wtf
@stuck bay is there a reason you want to do it via code?
yes
Because I want to learn about it
That’s fair just curious if there was a technical reason
does anyone know about car physics?
if the camera is the cause, check your culling settings
I'm having an issue where collisions are occurring even though the physics layers are set to never interact in the project settings. Does anyone know what could be causing this?
The first image shows my layer collision matrix, and the second shows the character hierarchy and the problematic collider.
show the inspector for the Player object?
It has a box collider, but it's disabled when I'm testing the collisions between the "AirbornCollider" game object.
double check that that collider is actually disabled at runtime
also it's possible your movement script itself is doing the collision checks
When I manually go into the inspector for the "airborn collider object" and disable the collider, the player can move through the object just fine. That leads me to believe that it has to be the airborn collider that's preventing the movement.
\
Yeah, during runtime the collider is still disabled.
I don't know, I feel like it's probably something obvious that I'm completely missing, but I just can't figure it out. 
are you sure you used 2D physics settings for your layer settings?
Or did you disable the collisions in the 3D settings?
I think that's the 3d one, as cloth settings aren't a thing in 2D 😛
Yeah, that was it. Thank you1
Hey everyone, I was wondering what caused this weird issue with hinge joints, why are they shaking like that when I enter in collision with it?
Neither. The two objects should not have an actual parent child relationship
It simulates that relationship without them actually being parent/child, and allows you to freeze certain axes etc.
i already know now
but the car seems to be jittery
when i use the parent constraint to the chase cam transform now
I am working on a multiplayer project where the server needs to substep each player's simulation separately, so my plan was to achieve this with multiple scenes and additive loading. The idea is that the main scene should contain the map geometry and each player scene should operate and do its substepping within that.
So far, however, I can't get it to work unless I duplicate the map geometry as a prefab in each subscene, which can't be right.
Here's my scene generation code:
playerObject = NetworkManager.Instantiate(playerControllerPrefab,
Vector3.zero, Quaternion.identity);
playerController = playerObject.GetComponent<PlayerController>();
if (IsServer)
{
scene = SceneManager.LoadScene(SCENE_NAME, new LoadSceneParameters(
LoadSceneMode.Additive,
LocalPhysicsMode.Physics3D
));
physicsScene = scene.GetPhysicsScene();
playerController.SetPhysicsScene(physicsScene);
SceneManager.MoveGameObjectToScene(playerObject, scene);
}
If I don't duplicate the map prefab, the player object just drops through the floor plane and falls forever. Otherwise it works fine, so the substepping is working, but the multi scene collisions are just not happening. Any advice?
If you use multi scene physics, you get what you paid for. Completely separate physics simulatons per scene
Objects need to be in that scene in order to be interacted with by other objects in the scene. This naturally includes your "floor plane"
Is there a better way of substepping multiple player objects concurrently in one scene? Or is duplicating the map a pretty normal practice for Unity physics?
Multi scene physics itself is pretty unusual in and of itself so I can't comment on what's normal practice
Hey everyone, how could I make hinged doors that interact with a character controller?
This says to ignore layers pass a layermask and only select the ones you are interested in....
But its colliding with other layers that I haven't selected still?
Physics.Raycast(ray, out hitInfo, layermask)
Is this a unity bug?
2021.2.19f1
Could you show me your code? :p @stuck bay
RaycastHit rinfoSlope;
Ray rSlope = new Ray(transform.position + walkDir, Vector3.down);
if (Physics.Raycast(rSlope, out rinfoSlope, layermask)){
charactercontroller.Move(walkDir);
}
LayerMask is an inspector field:
public LayerMask layermask;```
but it also picks up NPC layers... why..?
Debug.Log("Hit : " + rinfoSlope.transform.name + " > " + LayerMask.LayerToName(rinfoSlope.transform.gameObject.layer));```
Any clues? :c
Add the layermask here : Ray rSlope = new Ray(transform.position + walkDir, Vector3.down, layermask);
it seems like you're using a raycast to cast another raycast
In my own code :
I don't use this line there :
it is there though?
Thats just a ray
uhhh
if i instead use this it works:
Physics.Raycast(rSlope, out rinfoSlope, float.MaxValue, layermask)```
This picks up wrong layers:
Physics.Raycast(rSlope, out rinfoSlope, layermask)```
i had a similiar problem in this project before and that solved it there too...
oh i remember why >.>
its using the wrong overload ....
I think it's because you forgot to add the max distance yeah
yeah and no error becuase LayerMask converts to int
.>
damn..
such a stuupid mistake
it happens ¯_(ツ)_/¯
not sure what channel to ask this in but: Is there a way to make a rotation of a 3d object the new 0?
ex. I have a capsule and I want rotation 0,0,0 to be what would currently be 0,0,90 or it laying on a side.
You have to edit the mesh in blender or ProBuilder or wrap it in an empty parent object
A simple way to do that without editing anything out of Unity, would be to give your capsule an empty parent, and then add the components & scripts needed to the parent instead
How do you all deal with 3D characters / AI / etc that have unintended collisions with other things and it causes your 3D objects to pop up high in the air. Do you put a invisible ceiling to stop it? Kill zone? Check for Y and if > some # despawn? Do you modify the rigid bodies and etc? An example is spawning out of a simple object spawner, say you spawn and the object doesn't move, now you spawn a second one directly in the first and it pops straight up. I am going to get around this specific instance by just not spawning if there is a object in the way, but I do randomly get pops on stuff like dashing into things etc.
- don't spawn things on top of each other
- don't let your object pass through other objects (Make sure you're moving your objects in physics-friendly ways)
- disable collisions between those objects entirely if you want them to just ignore each other
do you recommend kill floors or ceilings for any stray gameObjects that escape the reality of my game 😄
or not really and its better to try to not have things pop than kill them off if they do
it's better not to have them escape reality, but it's also not a bad idea to have something in place to handle them if/when they do anyway
You can't necessarily foresee all the issues and the internet is full of videos of people "getting out of the map" in... basically every game ever made
ok. ill see what i can do thanks
maybe a better way to phrase my question: what is the best way to isolate and substep a single rigidbody within a physics scene using Physics.simulate? is there a workaround using the RigidBody.isKinematic property?
@empty sand I guess thats why you'd wanna use a kinematic character controller for multiplayer
It shouldn't be too hard to convert your character to use capsulecast?
There's this recursive step you need to do where you cast some capsules and get some projections
To slide along surfaces in 2d or 3d
Hi guys
Using a "Hinge Joint" why it sometimes completely breaks like in the footage below?
I set the axis to forward (positive Z) shouldn't it be locked to that axis? why it jiggles like that rotating in other axles..?
Anyone knows why the first one doesn't collide but the 2nd does
is that at runtime?
nothing specifically about these colliders/rigidbodies would prevent a collision per se. What are you expecting it to collide with?
A mesh, I already fixed it, idek how it worked but I just changed their y from 100 to 102 and it works lmao
why is the box collider inclined? any way to change it
okay i got a solution, adding empty child object
Bumping this because I also have this problem, and nothing online fixes it
Well.. if you just after a workaround, this issue caused by 2 physics objects at the end of the "bridge". when the ball pushes the plank too hard it goes fast beyond your limits and through these two objects.
The "bug" (IMO) is that the hinge then ignores your min\max and axis limits.
I just removed those two objects and now cannot reproduce this glitch.. but this hinge issue isn't fixed.
Another problem I got with hinge joints is that the hinge himself can be moved?? If you push against the object, the hinge & the objects can be pushed around, and there is no option to make the hinge / anchor FIXED and immovable
If the rigidbody the hinge is attached to is kinematic, that won’t happen
it does :/
Hi all, I have some cars which when they collide with each other they just float upwards, like they're ignoring gravity, but they both have mass, gravity, rigidbody and colliders, does anyone know what might be the issue?
Idk how you have moving kinematic bodies
But something sounds seriously wrong there
I just tried and my bad, it doesn't happen anymore. But now, they don't even rotate
Well only one of them should be kinematic
The object that should move on the hinge should not be kinematic
Ok, so I've been working on this for a while and I cannot figure it out. I'm trying to "lock" two game objects together rotationally. So if one rotates, the other rotates the same amount. (think like a Fixed joint. Where if one object moves it moves the other and vice verse. And if one object collides with a wall it stops the other for moving too... except for rotation) I'm not trying to have them rotate around each other so I can't parent them. They need to move independently of each other. but rotate together. I've been trying to find the source code for the Fixed joint but no dice. I cannot figure out how to do it. The real problem comes with I'm turning object A and object B collides with something. the physics engine handles the collision and I can't find a way to get it to use that information to stop Object A. Anybody have any ideas? My team and I have been working on this for a week and a half now and we cannot figure it out.
2d or 3d?
use target rotation of ConfigurableJoint
I'm going crazy... when I add a mesh collider to my wheels and check the convex options ( must be convex cus the car has a rigidbody ) the colliders arent round... any way to fix this? I tried using sphere colliders but the results are horrible.
The mesh itself is pretty round in blender
This only happens when i don't use "Apply transform" during FBX export... If i use "Apply Transform" the mesh collider is round. However the axis are incorrect relative to unity axis...
I'm going crazy with this
So basically:
-No apply transforms: mesh collider not round, but wheel axis aligned with unity axis
-Apply transforms: mesh collider round, but wheel axis not aligned with unity axis
Wdym by "round" or not
if you see the first picture the green collider is not round but more like an hexagon
last picture it's completely round and follows the wheel perfectly
this results in an undrivable car
You can change the axes in blenders fbx export window to match unity.
fixed it by unflagging "use space transforms" in the fbx export
How can I stop my camera jittering when.I rotate with my Rigidbody player?
I tried setting the rigidbody's extrapolation to on
that didn't work
and I tried making the camera a separate object and having it slowly follow the player
but that doesn't work because it's a multiplayer game and I have to keep the camera as a child of the player
Any ideas?
why do you need to keep the camera as a child of the player?
Because I would have to have the prefab be the container for both the player and camera
but I don't want to do that because I have to put my NetworkIdentity (using Mirror) on the container
so what
then do that
No I can't because my player has a NetworkRigidbody component
and the child cant have it
That changes the desired angle of the joint as a whole with each game object on both side... thus moving each game object to a desired position. Im looking to just rotate each object in whatever its location in. We tried that option and cant get the desired results
2D. Sorry should have mentioned that
oh yeah my bad, you should use script actually
wrong tag
wait configurableJoint can actually rotate whole gameobject
hello i want to make a active ragdoll character im not sure which joint to use (i dont want a gang beasts or human fall flat kinda character i want to have lots of control over the character kinda like the character feels light and not very heavy i want to make it so the arms legs and head like wabble around alot)
How do I prevent enemies from pushing me around if they use a rigidbody while i use a character controller? the cc doesn't have a kinematic tickbox option, so i'm lost
If you just added rigidbody on character controller, it was not designed to use one and will conflict with it. Like I've mentioned I haven't used it in practice but probably it involves manual handling of all interaction events with it if you want interaction. You should find a tutorial illustrating how to setup interaction with CC properly.
how can I control which objects can interact with other objects but not allowing them to go through each other, basically some physically interact with each other and others treat each other as kinematic but they are not (that way they can use gravity)? pls ping on reply
because using Physics.Ignore allows them to go through each other and so does changing the layer interaction to ignore each other
and also is this even possible because it would be kinda wack if you cant have 2 objects not push each other and gravity at the same time
hey so I have a bug in my racing game where when the player(a sphere collider) is on the road sometimes it just jumps like in the video if I get two blocks and let the player drive between them this also happenes so I am gussing when it goes bettween these it thinks it should kinda jump but the height differnce of these colliders (the two ground) in minisculare to nothing so it shouldn't do that and for the road I am using a mesh collider and I the ground isn't fully flat because somewhere in the road it goes up
The best solution to this is to make your whole track out of one seamless mesh. This is a pretty common problem and can be googled
Hey lads, have a question: I wanted to make a game where the player swings using a chain. The chain is made up of 4 links which each have a Rigidbody2D, CapsuleCollider2D and a HingeJoint component. The chain is then connected and parented to a square sprite with Rigidbody2D and is kinematic. This square is the parented to the player. The chain on it's own works great, but whenever I attempt to move the player it just falls appart. Also the collisions between chains and player are turned off in the Start(); function. Anyone knows a fix?
I will send some pictures and a video.
Inspector of 1 Link
Inspector of the square parent
Hierarchy
Joints
Video:
There is no script written for the chain btw
oh and please ping me if you answer
Fixed it, I just had to use a force rather than position to move my player :D
but it's already one mesh yeah the walls are a differnt mesh but it "jumps" because of the road
Why not BoxCast first then move only as far as the BoxCast allows?
BoxCast isn't appropriate for checking if a particular position is already colliding. You'd use OverlapBox for that. BoxCast doesn't hit objects that the box begins the cast overlapping
I just watched your video
Looks more like a your code problem than a Raycast or BoxCast problem
Again you should really just do the check before you move the object and don't move it if there's an obstacle
so wheel colliders are a joke right?
that is dope
hey so Im creating a pirate boating game and Ive created a way to keep the player on the boat while its moving by adding the boat velocity to the players velocity so then it follows along, however the player keep jittering with the velocity added. im not sure how to fix this
That doesn't make sense. Raycasts hit colliders. There must be colliders for the Raycasts to work.
I'm also just saying Raycast first, move second.
how can I stop discrete rigidbody from going through rigidbody as when it is going fast it doesn't detect the other wall and the wall has a rigidbody(but I can remove it if you think that might help) and I have to have the discrete rigidbody be discrete as it stops another bug.
continuous collision detection mode is the way you make objects not tunnel thru each other when they are moving fast. trust me, coding it yourself so discrete colliders can't tunnel through each other is going to be 100x harder than just fixing the original bug and using continuous collision detection...
what is the bug?
The player jumps when moving on the road because the road isn't a perfect flat road and it is also aesh collider
afaik that's quite heavy process and should be avoid when possible. if you use kinematic rigidbodies on the moving objects and use Rigidbody.position instead of Transform.position, the update on physics engine should be immediate.
I'm not sure. some sources suggest objects with colliders on it shouldn't be moved using transform because it can be expensive (physics engine considers objects without rigidbody a static object that is not meant to move)
those are mostly quite old pages I have been reading so it may not be that expensive these days
Why wouldn't it work?
But yes you do normally need to wait for the physics update unless you sync transforms manually
Is it possible to essentially "pick something up" by sandwiching it between two colliders?
Im thinking of physically articulated hands but im not sure how that'd be in both practicality and performance
ignore last lmao
I have 3 doors, eastern (e) , western (w), central (c). (e) + (w) are opened when a game object that corresponds to those doors are destroyed. The (c) door opens upon both the (e) + (w) doors opening. The (e) + (w) doors can only be opened one by one, but doesn't matter which way round. How do I set a boolean so the (c) door will open regardless of if (e) door is opened first followed by (w) door OR (w) door is opened first followed by (e) door?
Having a ton of trouble with Raycasts and Trigger
No combination of settings or Query interactions is netting me a Trigger hit
You're probably focused on the Trigger thing and missing something else.
am i in wrong channel again?
Hey guys is there a way to use MovePosition with a non kinematic rb or how can I use moveposition without moving through objects?
What's stopping you from using it with a non kinematic RB?
I use it currently with a non kinematic rb problem is that my player goes through the wall currently
Hi, I'm having some issues with collisions:
- Player is using the character controller and is using charactercontroller.move()
- Test object does not register any collisions: player and test object have both colliders, rigidbodies and collision matrix is set up
- Made a test collision script for test object with only OnCollisionEnter (actual OnCollisionEnter script is on player)
- With the test collision script ON TEST OBJECT, the OnCollsionEnter script ON PLAYER now works as intended (??)
Any idea what's happening here and how to solve the issue?
does the wall have a collider? Can you show your code?
OnCollisionEnter is not going to work with a CharacterController. It only works with dynamic Rigidbody.
and if you have a dynamic Rigidbody, that is not compatible with CharacterController
unless you're saying the other object has a dynamic RB?
But why does it work if I just put a test OnCollisionEnter on the test object?
show what you mean
show the components on both objects when it does and doesn't work
On the player there is a rigidbody, charactercontroller and some custom scripts, one with OnCollisionEnter
On the test cube there is a collider, rigidbody and a test script with only OnCollisionEnter
This way the player registers collisions but if I remove the testcript on the test cube, the player doesn't register any collisions. So it works, but only if the test object has a script with an OnCollisionEnter.
same doors, but one inverted, one hinge joint breaks and the other doesn't. Both have colliders inside
I'm trying to get a door to open upon two doors being opened, but the door needs to open regardless of which of the doors are opened first and only after both doors are open
the gate index issue i have is, with each gate unlocked, add 1, so the first two gates should make it 2 right and so for the last gate i did > 2
im sure thats right how ive done that
you're just doing gateIndex++ every frame (twice) whenever your HP is <= 0
Also your doors are going to fly away into the sunset because you Translate them forever
not sure what you mean by "regardless of which of the doors are opened first" because both of your doors just open at the exact same time
also why do you have so many random unecessary empty scopes... { }
i know before one door opened when a target was destroyed and then the same would happen to the other. now they both open which is not what i want and the hp bar no longer works on one of them. what i wanted was open either door a / b in any order and door c would open one both doors are open (regardless of order).
once* both doors
the index i was trying to do so that door a and b equals a number and when the number is higher than a value door c would open
i know ive probably done it all wrong
What you're describing and the code you've presented don't seem to be in the same galaxy of functionality 😛
I would expect each door to have its own hit points variable for what you described, for example
Hey I'm trying to apply gravity to a character that has animations such as idle, walk, etc. The issue I'm running into is that when the game starts, the idle animation is applied, and the character doesn't fall by gravity because of it. Is there any way to fix this?
This is the character's inspector:
I find that the easiest way to get physics and animation to play nice together is to put the physics components (rigidbody/character controller, collider) on the parent and put the rendering components (mesh renderer + animator) on a child. That way the animator can do whatever it wants to the thing being rendered without messing up the physics
however, that probably would not work with root motion
also, you should not have both a character controller and rigidbody on the same object. Use one or the other
Alright I'll try that, thanks! Is there a reason why the physics and animation get wonky like this if they're on the same gameobject?
And thanks I'll remove the character controller
because they don't talk to each other and both are fighting to control the same values. Physics says "Oh, the object should be moving left" and animation says "oh, the object should be moving right" and there is no way for them to resolve who wins
by creating a hierarchy of GameObjects, you're telling the two systems how to cooperate
ahh alright that makes sense. Thanks again for your help, I appreciate it
https://learn.unity.com/tutorial/physics-best-practices#5c7f8528edbc2a002053b5b4
This info is profoundly outdated right?
I don't think you need to slap kinematic rigidbodies on everything that moves anymore... isn't this what the "static" checkbox is for?
I'm trying to make a pinball game in unity, what scale should I apply to my table? thanks in advance for the tips
Scale 1 to my mind
But when you need to scale down an object (like the ball) wich have a collider, put this object in an empty parent, and scale the parent
for object wich have collider etc, the best practice is to let his scale at 1,1,1
hello so I have a road I made in blender and then I import it to unity and give it a mesh collider I want to know is this the best option as then my player(a sphere collider) bumps into the ground's small changes in height causes it to kinda jump I was told I need to make the ground seemless does that mean I need to change my way to give it a collider?
this is the bug
can you show us the collider ?
it's just a sphere collider but
I was told to maybe make a script in order to keep the sphere collider(player) on the ground but I think I didn't do it well
if (grounded == false && stickToGround)
{
Debug.Log("going down");
rb.position = hitPoint;
rb.position = new Vector3(rb.position.x, hitPoint.y -(0.989f), rb.position.z);
}
esciantially It checks if the player is on the ground if not it tries to bring the sphere collider(rb which is the collider of the player) to the hit point but a bit heigher up so it just touches it
never mind I was able to fix the problem in the brackeys server thanks to a user called molibloo.
That information looks correct to me. If it moves and interacts with physics, it should have a rigidbody (and the movement should be controlled via the rigidbody, not by moving the transform directly). The part about triggers not working without a rigidbody is definitely true.
That article was updated in Feb, 2021. That's not that old and the Unity physics system has not been totally overhauled since then.
If you don't believe the info is current, it's not that hard to profile the difference yourself. Just make scene with a bunch of interacting objects and try it with rigidbody vs without rigidbody and check the profiler.
so this is what the enemy reptile should look like
but when i hit play he is in the ground
it has a nav mesh agent on it
where is the pivot point in play mode?
where is the pivot point period? Make sure you have tool handle position set to Pivot, not Center.
And... probably yeah your code is just dumping him in the ground
Hey everyone! Im having a problem considering hinge joints, I don't know why, but they all start flying into the distance when I press play, or touch them.
Here are the components they have, (the 4 wheels share the exact same component, I linked all objects for better reading)
Problem solved! The constraints of the rigidbodies were causing it!
where do i see the pivot point?
the pivot point is where the move Widget has its center (the red green blue arrows)
You can switch over the the scene tab / window while the game is running.
i fixed it by offsetting the agent nav mesh
base
hello
i am making a mobile fps
i have created the movement,shooting,AI and the map but the problem is i am trying to create a health system
the health system should update everytime the AI shoots me (i am using the Raycast feature for the shooting on the bot)
i found a tutorial but instead of using raycast he made a projectile and used the istantiate function.
can anyone help me make the health system please
is there anything similar to Chaos in Unity that unreal has?
Like you could create objects that shatter and break
Closest i got to it was make a blender model then cell fracture it then add rigidbody, mesh collider and a fixed joint to all the cells then when u shoot it for example the object shatters. But if the fixed joints have no connected body they dont have gravity so the object just like floats in air after you shattered the support. Then if you add a connected body to all the joints it just shatters instantly.
for your strategy though rather than deal with a million joints etc, I'd just swap out the "intact" object for the "broken" objects when the thing is supposed to shatter
I was planning to make like big complex objects able to be shattered and broken. So if there would be like a tall building you could shatter the bottom and then at some point the building would fall and shatter even more when hitting the ground. I got it working pretty well with unreals chaos system but idk if something like this can be done in unity atleast easily.
yeah rayfire is made for that
not free though
I have no knowledge of Unreal features so not 100% sure what I'm comparing to
I think chaos is free built in destruction system. That unity doesn’t have but you can use assets made by others as praetor is suggesting (or build your own system which sounds very complicated)
For 2D, how can I handle slopes? I have a circlecollider for the ground, but I slide down slopes
Increasing friction makes me unable to climb them
there are some nvidia blast integrations for unity
@atomic lintel^
pretty sure unreal used to use nvidia blast for their fracturing framework too (to be simulated with chaos)
blast is essentially what is successor of their apex destructions fracturing tools, it's just different concept now
(ue4's destruction was still apex based - unless you went to experimental chaos builds)
Does anyone have any resources that could help me make an active ragdoll? (Unity)
i am working on a rigid body vr hands set up
the tutorial im following says to use primitive colliders
i want to use a mesh collider
will this cause a problem
https://www.youtube.com/watch?v=HF-cp6yW3Iw
would this work
This is all I learned while making active ragdolls in Unity. I hope you find it useful or, at least, interesting :D
The actual tutorial: https://bit.ly/3lKsfk2
Github repository: https://bit.ly/2VxnU98
----- Social -----
Twitter: https://twitter.com/sergioabreu_g
Ambient Generative Music by Alex Bainter [generative.fm]
-...
mesh colliders will be ok for individual pieces of the doll as long as they are convex.
and as long as you aren't expecting them to deform with the mesh
I can't figure out why ragdolls created using the wizard on Mixamo character rigs are getting stretched, ive tried re-doing it like 5 times with 3 different rigs in t-pose:
ive had plenty of success with this in the past but its been a while, not sure what im doing wrong
Hello I'm still having issues of when the two lower gates in the highlighted picture, when they go down (see gameplay video) the upper central gate is supposed to go down as well
both lower gates need to be down but can be moved in either order, just need the central gate to register that
I've tried doing this with a gate index
this is incredible. Sorry I have nothing helpful to say.
hi
i made a parachute acctually my friend did and now we dont have the file we only have it on workshop steam we want to download this mod and split some parts like we made 2 parachutes we want to remove one of them can any body help us to split them from each other (just take one and remoe other files)
Have you any advice PraetorBlue to my above post?
Are there any method for making liquid physics. Like pour, shake etc
Found this https://github.com/ElasticSea/unity-fracture Works very well even better than unreals in my opinion and needs no setup for the mesh (In response to my previous question)
So I'm having an issue where OnTriggerEnter2D isn't being fired in a certain scenario. I have a Collider2D that I'm toggling enable state on. If the target object is already in the collider's space when the collider has its enabled set to true OnTriggerEnter2D surprisingly does not fire. This only happens if the rigid body has 0 velocity. If the object is moving, then OnTriggerEnter2D will detect the target object.
Is this expected? Or is this a bug?
it's a known, annoying quirk
@timid dove Roger, thanks.
Is there a common known solution? I feel like the hack would be to switch to stay instead of enter and add logic. We did notice that toggling"IsTrigger" as well solved it.
Basically everything that triggers a physics engine update for the object. A tiny movement. Add/remove a collider, switch to/from kinematic etc. all should work
uh super noob question, I assume these red and blue spheres are the joints from the animator or something?
For some reason they sometimes desync/follow a different physics system than my actual model. Any idea why/where to access them?
why is this happening? (Blue is perpendicular, Red is normal)
nvm, had to change the raycasts from starting in transform.position to groundcollider.bounds
though how do I make it so that it doesn't kinda "fly"/start falling when it's at an angle where it should be able to walk?
Ok im back asking again about ragdoll, it seems like my ragdoll joints are breaking but they have infinity force, screenshot from the frame before and after being enabled
So I tried adding context to my mesh collider and it didn’t enable collisions
"convex" Also make sure it's physics driven and not pulled through by code.
then why would there be any collisions
Because there is two colliders? Do you have to code collisions in 3D?
What do I need?
and you need the object to not otherwise be moved/positioned by your code or other componnents like animators/CharacterControllers
Dynamic rigid body I did not know that
Rigidbody is the thing that the physics engine actually simulates
without it, there is no physical simulation at all
I have a regular one
A "regular" Rigidbody is a dynamic Rigidbody
This part is important too though
Sec I just posted it
Here you go
But it falls through the world long before I try interacting with it
the code looks ok
You must not have the proper colliders set up
maybe show the inspectors of the two objects you are hoping to collide with one another?
I just changed from a box collider to mesh collider
One moment
and the inspector of the object you want it to collide with
setting velocity in Update
should be fine as far as respecting collisions go
they'll have a problem with setting y velocity to 0 and presumably having gravity enabled
Oh, my bad, i turned it off for testing
it doesnt change the results anyways'
im sure its a stupid mistake but i cant see what im doing wrong
Should start with simple configuration to make sure you didn't make any mistake. But what you really should do is to follow Unity Learn course covering physics. I think Essential Pathway covers it as well.
Oof it was going through the world, it was physics going cracked
ill chat that out
in 2D i didnt really have to worry about this as much
Oh yeah, forgot to mention, I didn’t set velocity in fixed update cuz I’m a trash monkey
This is my first dive into 3d so a lot of new stuff
There's a very good reason to go through well structured courses instead or relying to grab what you need currently from random tutorials or even manual.
You'll be exposed to almost complete set of features, including some that you would encounter only randomly stumbling into.
So you would be able to play with full set of tools. Even if you don't remember how everything works you'll be aware of it and know where to find information about it. And would be much better equipped troubleshooting stuff like this.
Im going through it right now, thanks
im working on a vr game and for some reason the hands keep clipping through objects
i tried increasing the physics iterations but it doesnt change anything
the radius of the sphere hands that im using are 0.2
Possibilities:
- You've made your cube very thin in terms of the y scale. That can lead to tunneling: https://gamedev.stackexchange.com/questions/192400/in-games-physics-engines-what-is-tunneling-also-known-as-the-bullet-through
- Your animator could be phasing your object through the ground
generally your hands are being controlled by the VR controllers which means they're just teleporting around and ignoring physics.
Thanks I’ll try 1 thickness going forward
If you want them to convincingly move other objects around you'll want proxy objects which have kinematic Rigidbodies and follow your VR hands in FixedUpdate using like Rigidbody.MovePosition and Rigidbody.MoveRotation
Simple problem I can't seem to solve.
I have a physics mat with bounce = 1, bounce combine = max, friction = 0, friction combine = min
I have a ball and paddle with this mat applied
I have walls with colliders but no physics mat
When the ball collides with the wall, it bounces off with no decrease in velocity.
When the ball collides with the paddle, it bounces off, but loses a good amount of velocity.
No scripts doing anything other than spawning the ball and giving it an initial force.
how are you moving the paddle
kinematic, but atm it's just standing still
so when it bounces against the same material it loses energy but with the default material it bounces nicely?
yeah
that does seem odd...
if I remove the mat from the paddle, it still slows down
tried lots of configurations but can't figure it out
screenshot of the scene?
sure, sec
what happens if you remove the Rigidbody from the paddle too? (you said it's not moving currently, right?)
let me try that before I take a few ss's
ah, does not lose speed when I remove the rb
interesting
I cannot explain that to you... but at least we seem to have found some kind of pattern
I added the rb back and now it doesn't slow down... such is life
thanks @timid dove 🙂
I'm not sure what I've done but you're welcome haha
Hello. Is it possible to do like a Vector3 MoveTowards that takes a vector3 for speed, instead of a float?
I'm adding acceleration to my system, and there's a bit of "snow/icy" slipping to the movement. So I always want to be MoveTowardsing a target, but not necessarily directly towards it every time
I was just adding accel to my velocity, and then adding velocity to my current position, but I end up overshooting the destination
You're trying to do two different things that are in tension with one another
- Stop perfectly at the exactly place you want to
- Make gradual changes to your speed, rather than instantly going from one speed to another.
the easiest way to do 1) is to just stop instantly when you arrive at your destination. That's what MoveTowards does
the naive approach to doing 2) that you already tried made you overshoot
in order to do both 1) and 2), you have to predict when you are going to arrive and start slowing down BEFORE you get there, so your velocity gradually approaches 0 as you get closer
that's not a particularly easy problem to solve in a really general way
using something like PID control (https://en.wikipedia.org/wiki/PID_controller) is one way to handle it
though that's probably more complicated than what you're looking for
Thank you Tachyon! I had a nagging feeling that I was trying for something fundamentally impossible, but couldn't tell you why. That crystalizes the issue a lot
And I don't think I need a perfect solution, but that has me thinking. If I can decrease velocity & maybe increase acceleration (so the velocity is more directed towards the destination) then I think it'd be good enough
And holy crap this PID article is amazing, I think this is the answer to something about my car I've wondered about since I was 16 
like - how does cruise control work?
hello just wandering if u could make dashes and grappling hooks with character controllers as i think u can only do so with rigid bodys
Yes you can
It would require some strong math. It would be easier to do with a rigidbody.
Anyone knows how i can rotate the wheelcollider contact point ( the little bubble on the left ) so that it faces down?
nvm solved
i rotated the parent object instead of the object containing the mesh
my wheel collider is in the wrong direction. how can i fix that?
wheel collider always aligns with +z (the forward direction)
it's not the wheel collider that's in the wrong direction, it's your model
ah okay thanks!
i have the colliders under a separate game object and when i rotate that the colliders wont turn
they use the Rigidbody's orientation
ahhh okay thanks !
Hello I want to make physical water and I want t add pour effect to it. Can somebody help me (I dont want an asset I need a tutorial, doc. or something else)
this is like grad school level complex particle simulation stuff
either find an existing asset or start reading SIGGRAPH research papers
I understand that this is not easy
Maybe look into marching cubes to start with. That's one way to render "blobby" amorphous kind of objects
so is there no way to make the mesh colliders work properly with rigidbodies. Like if you cut a hole in a cube with blender then import it to unity and add a mesh collider to it, the collider completely ignores the hole in the cube. If you turn convex off in the mesh collider then it works perfectly but then you cant use it with a rigidbody.
Why did they even remove that functionality. I dont want to downgrade to unity 4 :c
Like i simply have a cube with a hole in it. It wouldnt take alot of resources to allow the mesh collider to work properly on it but with convex enabled it just puts like a box collider on it and ignores the hole
Concave colliders are only supported for kinematic rigidbodies
You can just build a Collider up out of several primitive colliders such as BoxCollider
Hey, I was wondering if anyone had an idea why I can't get my ArticulationBody to move using drives. No matter what target I set, nothing is happening. I'm using the SetDriveRotation extension method here (https://gist.github.com/Gustorvo/50fb28e7b348f4a3f74c631891c535bf) and I see it is changing drive values in the editor. This is what my editor looks like...
according to the docs the force formula is:
F = stiffness * (currentPosition - target) - damping * (currentVelocity - targetVelocity)
If your stiffness and damping are both 0 I would expect no force
Weird, I thought I tried that and it didn't work, but sure enough... that did it. Thanks!
Is there a way to assign different gravity values for different objects in 3d?
I want to change the players gravity dynamically throughout, without changing the gravity of everything in the scene
uncheck Use Gravity for the rigidbody and write a script to apply a custom gravity force to the object
oh of course, thank you!
is there anything i can use other than a mesh collider as collision for a mesh
if i have a 2d top-down third person game where you can move around as the player character and there are enemies that chase you, should i make them use dynamic or kinematic rigid bodies? i thought the latter made more sense but then i discovered that kinematic objects arent stopped by static objects. should i make even the objects that will never move kinematic to get around this issue?
Ai is usually easier to implement for kinematic movements
You’d handle collisions or rather avoidance thereof, through some form of navmesh and local avoidance
but does that mean bad hitboxes for the static objects then
Define ‘bad’
well wonky and something that clearly doesnt fit the sprite
are we talking about a grid based solution
up to you to implement a nicely working navmesh/grid and proper avoidance movement for your game
still simpler than making ai work with forces and random collisions
i see but how do i implement collisions for the player character
by checking for collisions manually with raycasts
so like make it cast rays in like four directions or something and see if any ray hits something within the radius of the players hitbox?
can i just make the rigidbodies dynamic and find my own way to deal with the AI problen
i mean the enemies arent meant to be very smart here, theyre like rpg battle initiator triggers
which happen to be monsters of which many arent that smart
in that vein i wanna ask how you can disable ricochet effects because i dont want those in this game
apparently theres a material property named bounciness you can set to 0 though some people online have said that doesnt always work... i guess ill try it anyway though
what is the alternative for puppet master ?
built-in ragdoll physics? https://docs.unity3d.com/Manual/ragdoll-physics-section.html
How exactly do I use the inertia tensor to calculate torque given angular acceleration vector?
The moment of inertia, otherwise known as the mass moment of inertia, angular mass, second moment of mass, or most accurately, rotational inertia, of a rigid body is a quantity that determines the torque needed for a desired angular acceleration about a rotational axis, akin to how mass determines the force needed for a desired acceleration. It ...
Use it to calculate the scalar moment of inertia around the axis that you have acceleration (see the Wikipedia link for the equation)
Then use the standard torque formula to find the corresponding torque that would result in that acceleration
Can someone tell me plz how to change the motor speed of a slider joint in unity2d in c sharp
I'm wondering if someone could give me some guidance. I have a number of clickable items in my game and I've noticed that when the frame rate is not as good as it should be they stop working. Is there a way to poll collider interactions more often or at the same rate regardless of what the frame rate is?
I have rigidbody 2d components on player and enemy. should I set interpolate option of both of them as Interpolate?
how do i fall faster without increasing gravity or mass
cuz when i increase grav and mass my walk becomes too slow
anyone know how to have this tilemap collider become like straigh
AddForce downward
Are you using the sprite to generate the collider? If so, you can set a custom physics shape for the sprite in the sprite editor (in sprite import settings) that has a simpler shape. It'll use that for the collider
Is there a way to disable springing in Configurable Joint like in a Hinge Joint?
Guys, with physicssimulation, how would I go about doing something similar to Physics.Raycast(ray, out hit, 100, m_LayerMask)?
as you can see my hitboxes are fine, but somehow my character hovers over the platform
it falls just right but just stops too early
Any ideas, i'm out personally
Check the platform collider boundary
Figured this out, I have to get the physicsScene and call physicsScene.Raycast()
I've got an active ragdoll setup working, but the fellow is a little shaky and veers off to the side. What methods do people recommend for stability? I'm currently keeping the hips upright using the configurable joints forces, though i may move that to a kinematic configurable joint which pulls the character towards that, then move using that.
Tldr; how to i help stabilise my active ragdoll to prevent veering to one side?
All objects fall at the same speed regardless of mass. This is a fundamental feature of gravity. Changing mass will not be helpful.
To make something fall faster gravity itself must be increased or you must add an additional downward force on the object.
This is also basic physics - it's a good idea to have some knowledge of real world physics because Unity mostly complies with those laws
Use the physics engine to move your character instead of teleporting around via the Transform.
I do love me some physics
your options are as praetor said.
If you want to learn about physics, there's a website available called Physicsandmathstutor, which has loads of stuff in it. its aimed at gcse and a level students but its good for anyone. hope it helps if you choose to check it out ^^
i mean. assuming real, not ideal physics, mass affects the counterbalance force (weight) to air resistance allowing denser objects to fall faster
since weight is mg and weight is the force that pulls you down
and air resistance tries to keep you up
you break through air resistance faster with more mass and less surface area
amd increasing gravity but keeping friction/drag constant also means the weight of the object (the effective inertia) is greater so it takes more force to make it walk on the ground
i am an a level student 😭😭😭
acceleration due to gravity is always the same but air resistance applies force in the opposite direction
hence a feather falls slower than a brick
i suppose unity doesnt have air resistance ig
Unity has linear drag, which is the drag field on rigidbodies
i also found with my character than heavy legs is good for making it walk
I might play with the mass scales, since heavier rigidbodies tend to be more "responsibe" to configurable joint rotation motors
amogus
you can actually see the platform boundary in the first screenshot
i'm still super confused
used Unity for a while never encountered
and my scene is just these two objects
Crossover question between Physics and VR but in the case of an active ragdoll for the player, how would one keep the head still and sync it with the head's tracked pose driver?
Hello, how i line my colliders prefect to fit these peaces under each other? In photshop I made them in same size everywhere.
If you are making Tetris I highly recommend not using the physics engine.
video not loading for me but you probably attached a Rigidbody component to it and didn't make it kinematic or static
its not a video but alr ill check that
it worked thanks. And if i want my character to not fall thru the floor would i need to add a collider on both my charachter and the ground?
Is there anyway I can make Angular X and YZ drives object space? I want to be able to parent 2 cubes to a bigger cube and say if I twisted the big parent cube they wouldn't try to correct themselves on the Y and Z
I'm not too familiar with the angular drives but honestly anything like that would be good
Ooh wait I just figured it out. My bad!
Is there any way I can make this only limit one side? Right now this sets the limit on both sides. I'm trying to make sure the elbow doesn't bend backwards
Why is your axis set to 180?
It only needs to be set to 1, having it set higher has no difference
also
Try playing with the primary axis until you have the x axis of the joint is along the bend of the elbow
Oh I see now, it's the green outline. What other components are on the platform and the object? Any Rigidbody? Maybe boundary issue there?
maybe you've done like I did yesterday and added a second collider not realizing I already had one on an object?
there is a rigidbody on the top one
I haven't been able to figure out how to make a realistic inner tube for a water slide, currently I'm just using a sphere collider and locking the inner tube's rotation, but that's not very realistic to how an actual inner tube would behave (as you can see, as it goes on the walls, the rotation doesn't make sense). How would I go about doing this?
I understand why this is happening at the moment, but how would I implement physics that would make it more realistic to an actual tube slide?
I've asked this a few times in the past year but I haven't found any solutions. If there's anything that you want me to clarify I'd be happy to
I've already tried a mesh collider, but with that it got stuck, and multiple primitives didnt work either
I'm thinking some path based system where speeds change? I have no clue where I'd even start with that though and i don't know how i'd implement the tube reacting with the sides of the slide
I think I'm getting kind of close
Making the slide and the tube zero friction seems to help
but it also makes it jump up into the air randomly
like spin out when it shouldnt
Making sure that you have realistic size/mass set for your rigidbody is probably a good start
e.g.
tbh, this might actually be realistic behavior for an empty innertube on this kind of slide
it flips over fast, but bumping up and moving chaotically seems reasonable
how do you think i could simulate it to be as if a person was on it?
I expect that spending some time trying to set stuff up more like the real situation would help. Start w/ having the innertube be very light but adding another object with much more mass in the center (attached with a stiff spring joint, maybe? Or fixed position joint?)
next level might be actually setting up a ragdoll to act as the person's weight
I'm not 100% confident this approach will solve your issue, but it might
I'm assuming you actually want to simulate it
if you just want it to look good
just making a bezier curve path for it to follow might be easier
🤷♂️ or that might be 10x harder
idk if that will be reasonable for the game i'm making
Since in it you'll be able to make your own water slides
ok i definitely set that up wrong LOL
this is probably not helpful, but in my undergrad physics classes marbles rolling down curved tracks like this was the classic example of a problem where Lagrangian mechanics is easier to use to solve the problem than Newtonian mechanics (just offering keywords to search if you'd like). Theoretically you could bake a solution to the equations and precalculate the path you'd take down the slide and follow that path instead of doing a realtime simulation of it. But... it'd probably be a pain in the butt
yeah, you'd probably want a really strong spring. Fixed point is probably just better, honestly.
I've never tried to do a simulation like this in Unity, so I'm just guessing as to what's going to work.
there's quite a few marble run games. This is pretty similar to that
trickier, but similar
fixed joint is kinda working but it gets stuck going up
I wonder if you need some kind of force field pushing it forward to simulate the water flowing down the tube
fixed joint seems to weigh it down a lot
I can't find any documentation to put me in the right direction
still acts like this, tried adding another object with more mass with joints, increasing mass for the rigidbody, and nothings worked
when it doesn't have the zero friction material it doesnt slide at all
it just rolls a little and stops
Which object needs to have the OnTriggerEnter() function? can either have it, or does the object with the trigger need to have it
hi, can i ask a question about a asset inn here
Hi, I am making a game based on physics2d..so I want to move player using forces not velocity. but controlling with forces is not smooth. is there proper way to do it
plzz help, I am trying to find a way for months
There's nothing inherently "not smooth" with forces. If you want help you need to describe your setup in detail.
There are also tutorials which point out how to to use physics components and when to apply forces properly.
Yeah, my player is basically a box and entire world and game depend on all physics. when I use rigidbody2d.velocity to move it, player is moving fine...but when I interact with hanging objects (I have physics ropes and items hanging end of ropes, I use them to cross some places by jump over them) they are not moving independently while player is on them, I think their velocity is affected by player even player is a child under that object. And I got other problems as well. When I use physics forces...all fine but I have to use liner drag to control movements, due to large linear drag its gravity motion or vertical motion also affected. without linear drag some how makes player uncontrol with forces, it move instantly and hard to control. Also stops while after I hold up the key...So I need some physics moment as smooth as velocity moments like in game LIMBO. I think it needs some extra calculations or something right. thank for any help in advanced.. sorry for long expression
Parenting does nothing for physics objects, it's just a container in that case.
drag is nice to control maximum speed of physics object, don't use it to stop character though. Instead when direction input is not used multiply Vector3.x of the velocity by a very small number and feed it back in to overriding and arresting momentum. This way it's not completely instant and you have control over it
Also with drag present you would need to add some constant downforce to have character fall more naturally
Physics based controller if a bit fiddly and you need to cover some corner cases, but it handles more naturally than complete override and keeps natural objects interaction.
Thanks for the reply. Can you show me some example or a code plz..I actually did not get that vector3.x part properly. I will show you my code
I was referring to velocity. Yea it's Vector2 in Rigidbody2D https://docs.unity3d.com/ScriptReference/Rigidbody2D-velocity.html
You take the value, multiply to a small number to reduce per physics frame, and then assign it back
X only because you don't want it to affect the jump
It should happen when move controls are not touched
do you have a tutorial or something sir
This code should be in FixedUpdate as well
yeah its in fixedupdate, I call move function from fixed update
note to not add button presses checks in fixed update. This input works in FixedUpdate only because it's axis based.
Yeah I use inputs from unity inputs. horizontal and vertical
not buttons
I want some thing like, that when I hold or press the arrow key player should move with its high speed (not an accelerating) and when I hold up the key, player should stop instantly
It's a simple trick to reduce momentum.
[SerializeField] Rigidbody2D rb;
void YourFixedUpdateRunningMethod(){
// if your horizontal input is not pressed here run this code
float smallNumber = .01f;
rb.velocity = new Vector2(rb.velocity.x *smallNumber , rb.velocity.y);
}
ahh, you mean when I dont hold my arrow keys, use this code to stop player from moving. right
yes
on opposite way
not just stop but smoothly force to a halt
okay I will try it, thanks,
sure
Heya, I'm trying to get around the "Non-convex MeshCollider with non-kinematic Rigidbody" issue. I've got an airship that i want to apply physics to via a rigidbody (i tried the non rigidbody movement and it was horrendous in VR), the convex mesh collider for it is awful and the overall shape i feel is potentially too complex for a compound collider so I'm having difficulty actually applying the rigidbody in a way that works. Do you know of any other workaround for this?
You need to build up the collider out of primitives/convex colliders
my fear of that is that it'll feel weird to interact with the ship in VR unless i go through adding each individual step etc.
idk why but in my head that's too many colliders and counter intuitive ?
I need some help boys, I'll send a video in a sec
As you can see what i am first doing that is how it should rotate, Is there anyway i can make so the gun also follows along without it being werid
look the whole video and you'll understand what i mean by werid
@slate copper You see where it says "center"?
Make it "pivot"
And if that doesn't make the rotations correct, the problem is in the model
alr let me try 😄
Btw this won't affect how the transform.rotation, Rotate etc works
They are all from pivot by default
Thanks man
np
Any body know how to make a good car??
@spark comet A single body car or a proper realistic car?
More so the driving physics part. I want it to be able to maneuver really well. Currently when I try to do much of a turn it flips or slides too much??? Can’t seem to get a good balance.
Hmm, I'd try to have a single body and worry about the wheels at all
Then I guess there arent many things that can go wrong
I don't know if you are doing it this way or maybe with wheel colliders
Or something else perhaps
Maybe pushing the vehicle or wheel down will help you achieve better grip
Or maybe you just need to configure the wheel colliders better
Maybe you can copy and paste some values from an existing vehicle that's made with vehicle colliders (if you have vehicle colliders that is)
Currently I don’t have any cars other then the ones I’ve made if you know or have a good car to learn from that would be very appreciated. Currently I’m using wheel colliders.
I don't have a car thats good enough to show here, it was an overly complex one
And I don't know of one that might suit you
But if I were to build one as I said, I'd explore the solutions with a single body
I think rocket league also would have single body cars
With a single body vehicle you can configure the static, dynamic frictions
And it'd work more robust
What’s single body
???
A single rigidbody box and thats your car
Can you just add forces let me look it up thx
you can lift it via raycasts from 4 corners if you want
to simulate the suspensions and stuff
There should be assets that does this as it'd be a common use case
Hhmmm thx for the ideas I’ll do more research
np have fun
Which character controller should I pick for fast fighting game? Character Controller looks good but has no physics (don't have experience yet to code my own gravity/mass). Rigidbody is nice but has no things like walking on stairs etc.
I mean which one would be better in that case and easier? Is it even possible to tell?
Sorry with all the delays in response, trying to hash out my own errors that are getting on my nerves. Wish Unity would put out something that just worked with out all the crap weirdness. Rigidbody is good but what about it's boundaries? No duplicate colliders? You mind sharing on github? Or maybe setup a temp project with simlar setup and share on Github? I will take a look
there is everything about the scene here
if you really need the scene i'll share it but I don't think a scene this simple needs it
it's because of the offset
you objects are wayyyy too small
0.03x0.05
make them proper sized
good morning
need help with something - I want to stabilise the head of an active ragdoll character, enough to make it suitable to use for a camera, or to find an alternative
Would I just use the head and hands as normal with the vr controls and follow them with the ragdoll?
SUS
"Non-convex MeshCollider with non-kinematic Rigidbody is no longer supported since Unity 5."
Hi, I'm trying to make a boat with crest oceans, but on collision, it goes straight through. I can't use a different collider or make it convex, because the buoyancy script relies on it to work.