#⚛️┃physics

1 messages · Page 77 of 1

teal ore
#

this is on all of the wheels

#

this is on the main car object

vernal spindle
#

How would I make multiple triggers react to randomly spawned objects (Without triggers)? The script with the onTriggerEnter2D is on an unrelated object. Someone said tags, but idk how I'd implement them when the script doesn't recognize any triggering at all

timid dove
vernal spindle
#

Yes. But the script with the ontriggerenter has to be on the triggering object, doesn't it?

flat palm
#

When optimizing colliders using multiple primitive colliders do you add the primitive colliders as a component of the game object? Or do you make a seperate collider in blender made of primitives and apply it to the game object in unity?

unique cave
flat palm
#

yea that doesn't make sense now that I think about it

unique cave
#

@flat palm yep. Very common way to optimize mesh colliders is to make simplified version of the model and set that to the collider so you get less vertices for physics object but maintain good visual quality. If your collider needs to change their shape runtime (for instance, hitboxes for moving character), use primitive colliders instead. Simplified mesh colliders are super cheap, theres usually no need to optimize them anymore

flat palm
#

Is there a general rule of thumb for primitive collider counts on a single object? I have an object with 8,400 triangles or so and I removed the mesh collider and added in some box collidiers. I have roughly 80 box colliders on it right now which is 900 tris or so for the collision.

unique cave
#

”tris” of primitive colliders doesnt exist. Primitive colliders doesnt use the ”mesh” of the collider to calculate collisions. Sphere collider for example should have infinitely high tris count (or super high), still sphere collider is lot faster than box collider.

flat palm
#

That's interesting I wouldn't have guessed that, where are you getting that from? I've been trying to find something in the docs or collision optimization but can only find hearsay, nothing concrete

unique cave
#

I dont have any specific reference. The order of performance is (usually) sphere > capsule > box. You can find some comparison videos from yt for example

flat palm
#

forsure, thanks for the info I appreciate it I will look into it more and do some tests

flat palm
#

@unique cave Wow! I was doing some test runs, I tested 2 of the same prefabs with different colliders attached. One constructed of 143 box colliders and one constructed of 148 capsule colliders. In each test run, I spawned 10 at random rotations and had them collide and watched the frame rate. On the Box collider test, I went down to 29 fps and at max hit around 80 fps once the objects settled. On the capsule test I stay above 300 fps throughout the whole simulation.

unique cave
# flat palm <@!689758471003963472> Wow! I was doing some test runs, I tested 2 of the same p...

nice, the performancy highly depends on the exact situation, sometimes there's barely any difference between different collider types because AABB checks takes care of most of the collisions. in general capsules are faster than boxes because they are such simple shape mathematically: 2 points and radius, sphere is even simpler: 1 point and radius (cube has center, rotation and scale or smth like that). but yeah, capsule and sphere colliders are very cheap which is pretty nice. capsules are very good colliders to use for fps characters hitboxes etc.

#

mesh colliders are surprisingly cheap when building static scenaries with simplified collider meshes for example. it's better not to overshoot with optimization. you can use profiler to profile the cost of physics and if you get too high performance hit, you can try to optimize the performance with compound colliders etc.

gritty jolt
# unique cave mesh colliders are surprisingly cheap when building static scenaries with simpli...

Ok, I came here to simply to ask about mesh collider vs box/circle/whatever simpler colliders.
After reading mesh colliders are generally heavy I went all out to make all colliders of my teams' game's main building. The idea seemed simple enough, a block here, a block there...
After 29 colliders, I did it, it works, it isn't heavy in any way, I hate it.
So people actually do that, or am I doing crazy stuff?
It is just a four floor building and it seems like I overkilled it beyond recognition.

mighty sluice
#

Does anyone have an opinion or insight/info on the concept of moving the world around the player instead of moving the player through the world in physics based controllers?

gritty jolt
mighty sluice
#

a box collider is basically just a center position and some offsets to establish its bounds, while a complex (and especially concave) mesh collider can be many thousands of vertices and other accompanying datas. Solving collisions on those complicated meshes can be even more of a problem

gritty jolt
mighty sluice
#

only add colliders if you have a reason to

gritty jolt
#

And goddammit, doing 29 colliders, that is a nightmare to edit and I know I will have to do it later.

#

probably will end up nearish the 40s if I keep doing this

mighty sluice
#

wouldnt a static mesh be even harder to edit?

gritty jolt
#

not if you have someone whose work is literally this xD

#

doing a simplified version of the original mesh is trivial for him

mighty sluice
#

for design and art, complex meshes are fine, it's only collisions you need to worry about

#

big box colliders for floors and walls are fine, and can be grouped together pretty much

#

static objects can be included under the same hierarchy, but you can separate them out to move them around easier (like blocks or staircases, etc...)

mighty sluice
#

yea, you could either add many box components to the same object, or just have many copied + pasted box objects that you use to shape your stuff

gritty jolt
#

oh yeah I did it

#

still hate it

mighty sluice
#

there are performance implications in terms of simulation fidelity as well as computational speed

#

it's still worthwhile

gritty jolt
#

even considering the way bigger games that even a phone can handle...? .____.

mighty sluice
#

it's about physics sim

#

so this depends on how much you're stressing unity's physics systems

gritty jolt
#

that is my point

#

we are not xDDDDDDDDD

mighty sluice
#

if you wanted high fidelity and repeatable stuff (like for networking) then there is benefit

#

if you want vert fast moving rigidbodies, that too

gritty jolt
#

that is why I think this is an overkill, the game is not physics based in any way

mighty sluice
#

then why use colliders?

#

just for raycasts?

gritty jolt
#

well the character has to move and all

#

I mean it has basic physics

#

I mean I am not making stuff roll over or blow up

mighty sluice
#

im guessing it's player colliders (capsules) moving around and shooting raycasts?

#

do they move with physics or is it a manual controller script

gritty jolt
#

nope, not a shooter, but yeah first person

#

it does use physics to make it move

#

I am reading that static objects as mesh colliders are not dangerous to performance if not overcomplex

mighty sluice
#

some meshes have millions of vertices

gritty jolt
#

like I said

#

low-poly

#

not our case

mighty sluice
#

it's a qestion relative to the size and detail of the mesh, the way you're physics interacts with it, and the budget of the platform; you need to test

gritty jolt
#

also, even if a mesh is high-poly, simplifying it is not that hard for this purpose

gritty jolt
#

I mean, if our target platform were smartphones I would at least be trying with my mid-range phone to see if it works, but in PC or any console I cannot see us comparing to any big title that actually kills framerate.

pastel sphinx
#

I am having serious collision issues

#

im not quite sure why, but basically i have a part of my game where the entire level starts rocking back and forth

#

and no matter what configuration of rigidbody collision types I use my player is quite literally going inside other meshes

#

I went into blender and even made the meshes thicker to no avail, which didn't matter anyway because i shoved a giant cube under this one part and the player is going inside the cube

#

now my only theory as to why this is happening is that I'm controlling the rocking using the animator which for whatever reason may be simulating at a locked 60fps even though my game is running at a higher FPS

#

hang on let me try locking the frame rate to 60

#

nope that did little to nothing

gritty jolt
timid dove
#

You'd have to use Rigidbody.MovePosition for it to work properly with physics

pastel sphinx
pastel sphinx
#

the player is a sphere if that matters

#

a rolling sphere

#

the level is like a combination of box colliders I placed manually since I assumed I could garuantee better accuracy doing that, but there are some spiral staircases that I had to use meshes to make collision for

#

so for those I went and made sure the meshes were fairly thick

#

but I wouldn't be able to tick "is convex" on a semicircular wall

#

i dont remember what required that I had all mesh colliders ticked as "is convex" it might've been the rigidbody

gritty jolt
pastel sphinx
#

if i didn't there wouldn't be any collision at all right

#

the collision works perfectly fine until the level starts swinging

#

2021.2.5f1 if that's relevant at all

gritty jolt
# pastel sphinx if i didn't there wouldn't be any collision at all right

of course, don't mean to offend. I don't know the level of knowledge of anyone I find here. I am not that experienced with unity, but as a programmer I have seen that sometimes programmers need someone else's view to see the obvious... I will always try to assume the easiest even if dumber solution first like "did you turn it on?" instead of trying to find some inner weird bug... anyway, I don't know enough to help you besides stating the obvious for now xD

timid dove
#

Like I said you need to move via rigidbody

#

Otherwise you're not moving the object you're teleporting it.

pastel sphinx
pastel sphinx
unique cave
# timid dove Like I said you need to move via rigidbody

Well, yes, you have to move via rigidbody but not using rb.MovePosition. MovePosition is same as rb.position but with interpolation (visual interpolation, the interpolation doesnt affect any physics calculations), it doesnt prevent objects from moving through each other.

unique cave
pastel sphinx
#

ignore the ridiculousness of what you're about to see

#

the reason the whole level rocks is because i want the actual forces to affect your ability to move straight

#

like getting pulled toward walls and such

#

i could do that with code but it would take me a while to figure out how to do that convincingly

#

it would also have a knock-on effect with the other things that aren't part of the stage that is rocking

#

so the only reason the player isn't clipping there is because that box collider is huge

#

the other colliders it goes through with enough speed

unique cave
pastel sphinx
#

i was usiong the animaator

#

rigidbody was cos i thought it would allow me to change collision detection type

unique cave
#

animator is absolutely not the way to go. you need rigidbody if you really want to move the whole level but that doesn't seem good idea

stuck bay
#

Hey so I got 2 collider objects using gravity, but when i place 1 below the other they just start floating in the sky. Ive tried everything from using kinimatic and turning gravity off, im so stuck and confused. *** Fixed the issue, turns out had too many rigidbodys on things i didnt need them on.

pliant tusk
#

Hey is it possible to desactive the LightReflection only with the an PrimitiveGameObject
Please ping me for respond

timid dove
#

If you MovePosition a non-kinematic rb it will not go through things

#

It is very different

unique cave
timid dove
#

Ofc

pastel sphinx
timid dove
#

same concepts apply

pastel sphinx
#

ah ok

tidal linden
#

I'm trying to detect if a capsule collider is intersecting with any other colliders, I've found CapsuleCast and RigidBody.SweepTest to be unreliable because they don't work if the starting position is already intersecting another collider. And CheckCapsule isn't useful because it does return any information about the colliders that were detected, so they can't be used for what I would need afterword.
I could use OnTriggerEnter (and not OnCollisionEnter because I'm trying to avoid the rigidbody physics system). But the only problem there is that it takes place after FixedUpdate, so It would be completely out of step with what I'm trying to do.

tidal linden
hearty hollow
#

I think this is the right place to ask about this? My (Character Controller) character refuses to move in play mode, it's completely glued to the floor, and even teleports there when I press play.
I'm not directly dealing with its transform in the movement script at all. So what could be causing it?

hearty hollow
timid dove
#

Try disabling it for a minute

hearty hollow
#

OK. That works. What part of my animator could cause it?

timid dove
#

If your animator is animating your player's root object

#

It shouldn't be. It should only animate child objects

#

Otherwise it's going to set the player's position as you're seeing

hearty hollow
#

Interesting... OK I don't know how to actually fix that, but that gave me the idea to apply root motion, and now I can move the character with my controls (yay!)

#

But... only left and right. And the animation stopped working. :(

timid dove
#

The way to "actually" fix it is to make sure your animation clips aren't key framing the root object's position

hearty hollow
#

I wish I knew how. I'm just using Mixamo for animations.

timid dove
hearty hollow
#

OK. Thanks.

coarse prairie
#

Hi guys, i wanna make jelly physics like this can you tell me how , thank you

wide nebula
coarse prairie
timid dove
#

It works. It's just not trivial to integrate into your game.

#

Another option is to use physics joints with several rigidbodies on a rigged mesh with SkinnedMeshRenderer

#

it's not as granular as something like Obi Softbody but it uses only build in Unity tools and if you don't have that many bones it performs fine

patent pivot
#

Hello, Im having an issue I've never faced before. I'm using Unity 2020.3.6f1
I started making a 3D scene of a racetrack. Building the environment is really the only thing ive done to this project. However, whenever I add a rigidbody and collider to an object they immediately start moving backwards. no other components are added. happens even with a basic cube. im seriously at a loss. any suggestions would be greatly appreciated.

timid dove
patent pivot
timid dove
#

disable the collider

wind meadow
#

Question if i call upon ignore collision between object A and B and set it to true

#

then call ignore collision layer between A and B and set it to false

#

does it allow A and B to collide again?

timid dove
#

no

wind meadow
#

so ignore collision has higher precedent than ignore collision layer?

timid dove
#

All ignore collision layer does is set up the layer collision matrix in the physics settings

#

If you have explicitly set two colliders to ignore collisions, they are not going to collide, regardless of layers

patent pivot
timid dove
#

You can put an OnCollisionEnter in your script and print out what the name of the object it is colliding with is.

#

that might help you track down the problem

patent pivot
#

good idea, thank you very much

#

yup, one of the prefabs i added had a giant collider attached to it. wow, you're a godsend

wind meadow
#

ok thanks

stuck bay
#

Hey currently i am moving my ingame character with rb.velocity = moveDirection; How can I archieve same physics but use something like AddForce, which is constantly the amount of moveDirection?

jovial wraith
stuck bay
#

That is smart! I will test it out👍

#

ThanksUnityChanwow

timid dove
#

What's the point though? The end result is the same

#

except now it's subject to floating point arithmetic error

coarse prairie
rugged lotus
#

Do i add a rigidbody to a parent of static gameobjects with colliders in 2D?

#

for example i have a floor that doesnt move, and a bunch of dynamic rigidbodies are moving above it

timid dove
rugged lotus
timid dove
#

no

rugged lotus
#

alright

umbral pulsar
#

Anybody got pointers in how you would rig up a "monowheel + character"? Using 2d physics. I mean how can I get the character to be upright etc. The wheel is probably just a "wheel joint 2D", the character is rigged with joints normally, but how can I get it to behave nicely when the wheel is rotated. I was thinking of negative gravity for the character or something...

rugged lotus
#

Rigidbody2D.velocity being changed changes local velocity or global?

timid dove
rugged lotus
#

does calling MovePosition and then .velocity right after cause any weird issues?

#

for example if i try to get the direction using the transform position and target position

#

i was correct; .MovePosition has a delay so grabbing the transform.position right after that code doesnt actually grab the position that u want to move the rigidbody to

timid dove
timid dove
#

Have your code read the Rigidbody position, not the Transform position

rugged lotus
#

ok so it either needs to wait a frame, or to use the actual move vector im using

rugged lotus
#

eeh since im using a vector3 i cant use rigidbody.position so ill stick to the vector 3 copy i do

rugged lotus
#

why does having a lower fixed timestep , like 32 updates a second, an object moving have a stuttery constant velocity that seems to be in a repeated pattern every second?

lapis plaza
#

you kinda explained it already... you have low 32Hz update interval that's running fixed rate so it's impossible to have it in sync with the main rendering, sometimes your physics updates will inevitably happen close to rendered frame timing and sometimes they will be further away

#

you could use interpolation etc to smooth it out if it's an issue

#

if you draw a timeline pulse of the fixedupdates and your game updates, the intervals you see probably make more sense to you

wind meadow
#

is there a way to allow for an object to move normally but not be pushed around by the player?

#

like basically i want the enemy to be able to move normally and use rigidbody for say jumping and other physics things. But i don't want the enemy to be pushable by the player.

bleak umbra
wind meadow
#

eye sea

rugged lotus
#

the thing is just a background visual of stuff passing by, it doesnt really interact unless i decide it can colider with eachother

lapis plaza
#

@rugged lotus easiest solution is to just enable interpolation for simulated rigidbodies

lapis plaza
#

just enabling interpolation for simulated rigidbodies

#

of course it all depends

#

but without knowing the practical limitations, that would be always my first recommendation

#

like, if your target is a game that runs locked to 30 fps, it could be beneficial to just lock physics steps to actual update rather than fixedupdate

rugged lotus
#

i do try to make it as performant as possible, since im putting this project in a wallapaper engine so it runs in the background

rugged lotus
#

i assume the physics are running at 32 fps, right?

lapis plaza
#

no

#

Unity by default has fixed timestepped physics so your physics will always be async to rendering even if you try to match those fixed timestep settings

rugged lotus
#

🤔

lapis plaza
#

but you can disable the stock physics updates from running automatically and call physics.simulate yourself whenever you want

rugged lotus
#

aka each fixed update, for example?

lapis plaza
#

I wouldn't recommend that route unless you really understand how this all works in the background though

#

well. sure if you want to but doing that each fixed update would beat the whole purpose of not letting the engine do that for you 😄

rugged lotus
#

lol ok so its the same then

#

i dont get it why it doesnt update consistently then if i have fixed timestep on 32hz

lapis plaza
#

if you look at Unreal Engine 4 for example, they run physics always at main update so physics is never async there... and they have separate substepping option for physics that just splits the physics updates between these frames if main game runs too low fps

#

scheme like that lets you avoid interpolation altogether

#

but really... simplest way to do this is to run physics as low rate as you can without it glitching and enabling interpolation

#

unless you can really see the interpolation costing you too much, you shouldn't worry about it

rugged lotus
#

when u say physics, u mean the fixed timestep value?

lapis plaza
#

in this case yes

#

you shouldn't really run anything but simulation (typically physics) at fixed timesteps even

rugged lotus
#

alright so i guess ill just put it back to 32 instead of 50

#

oh, i have a coroutine of an AI moving but im not sure if i should be multiplying it by the fixed delta time, should i?

lapis plaza
#

around 30Hz is still somewhat acceptable for physics unless you do really fast paced stuff... but you can find the place where things start to explode yourself

rugged lotus
#
rig.MovePosition(rig.position + (moveDir * moveSpeed * Time.fixedDeltaTime * Vector2.right));

            yield return new WaitForFixedUpdate();```
rugged lotus
lapis plaza
#

lower the value, more objects have time to sink into each others when they collide and more things will explode when physics engine tries to solve those situations

lavish rose
#

Howdy! Just a little question, if i may : I have colliders all setup and stuff, but apparently, they dont go well with anims. Is there any way to prevent player from clipping through boxcolliders (like on the pic), other then making them larger then the object itself?

rugged lotus
#

her let me show u what it really just is

lapis plaza
#

@rugged lotus I'd just... enable interpolation and lower the physics rate as much as possible, if it's slow paced thing you could get away with 20Hz etc

#

interpolation keeps the whole thing looking smooth

rugged lotus
rugged lotus
lapis plaza
#

measure it

#

don't guess

rugged lotus
#

🤔

lapis plaza
#

why do you need physics for that clip?

rugged lotus
#

the AI interacts with the ball for example

lapis plaza
#

nothing there looks like it should require any physics

#

you can calculate the ball distance yourself

rugged lotus
#

the asteroids there im doing use rigidbodies to move 😛

rugged lotus
lapis plaza
#

ok maybe use physics then 😄

rugged lotus
#

heheh

#

the Ai also uses rigidbody to move and have gravity

#

probably not needed but it helps set stuff

lapis plaza
#

I mean this isn't complicated math but I do get the appeal on using existing things

rugged lotus
#

dont get me wrong, would love to just remove the in-engine physics system and just use my own

#

but u know...i dont know jack shit on how to do that 👀

#

that and URP already needs the package anyway so might as well use it...

#

no clue why it needs it but whatever

lapis plaza
#

typically you'd just fake everything in such scene and write some quick pseudo-physics on the char movement

#

URP needs physics for it's volume system

rugged lotus
#

ah, the triggers stuff?

lapis plaza
#

it checks if you are inside volume by abusing the physics colliders

#

ye

rugged lotus
#

heh.

#

wish that was a separate extension but whatever

lapis plaza
#

I'm personally not very fond of that

#

it's silly because Unity also has bunch of other physics engines on DOTS side

rugged lotus
#

on a rendering pipeline that they say is fast, it sure uses a lot of packages that dont seem to be needed

#

urp uses JSONSerialize, of all things

#

and UI

lapis plaza
#

it does have debug UI you can toggle on at runtime on dev builds (and in editor)

#

no idea why they need json

rugged lotus
#

and because of that it includes it in release builds

rugged lotus
#

Renderer 2D Data for example

lapis plaza
#

ah, I haven't really played with 2D side

rugged lotus
#

well not just 2D

#

any of these

lapis plaza
#

but yeah they could be doing stuff like that.. I always assumed they just used some SO's to store things but haven't actually looked what type of data assets those are

rugged lotus
#

¯_(ツ)_/¯

lapis plaza
#

I don't think Unity has any mechanism for different built type requirements, so I guess this is something where you just can't win unless you manually remove the requirements using custom URP package

rugged lotus
#

right..

#

back to interpolation

#

i assume all my rigidbodies will need it

lapis plaza
#

only ones that move dynamically

rugged lotus
#

since ive noticed the AI also have a somewhat jerky movement even though its much slower

#

dynamically?

#

the meteors are kinematic, i just add velocity to them; still jerky

lapis plaza
#

I'm not 100% sure which all configs get the interpolation with Unity, typically the bottom line is that if physics engine simulates the movement, it gets the interpolation. so if you move via velocity, it should interpolate

lapis plaza
#

2D physics solver without any collisions are really trivial to code yourself too but I get if people hate math 😄

rugged lotus
#

not hate as much as i cant xD

#

needless to say not the best at math

#

hell, i wanted to find out a formula that calculates how long it will take for the meteor to reach the out of bounds box from any location to any direction, but ye...

#

wouldve saved me an Update method for each object

lapis plaza
#

but yeah, interpolation is just a setting on rigidbody... use interpolation instead of extrapolation for least amount of glitching

rugged lotus
#

mhm

lapis plaza
#

you get tiny extra latency with it since you are always rendering the physics sim like one frame late with interpolation but that doesn't matter for visualizations

#

even for most games that's a nonissue

rugged lotus
#

hmm

#

i could probably make the timestep to 20 if interpolation works well

#

i do want to make the meteors collide with eachother later on , so im not sure how well it will go then

lapis plaza
#

main limiting factor on your scene are the characters

#

they will start to sink in the ground and colliding get more wonky the lower you go

#

find some place where it's a good compromise with perf and visuals

#

interpolation cost is overexaggerated on docs... unless Unity does something super silly with it, it's very simple math that shouldn't cost much

#

it's literally just one lerp for position and slerp for rotation

#

(for each rb)

#

you can do thousands of these operations in single frame with most devices

rugged lotus
#

mhm

lapis plaza
#

so... just measure the cost before making any assumptions

rugged lotus
#

using the profiler i assume

lapis plaza
#

yes

rugged lotus
#

i dont see teh AI sinking into the ground tho

lapis plaza
#

AI doesn't jump?

#

why it has gravity then?

rugged lotus
#

to settle in on the ground 😄

lapis plaza
#

but your ground is all leveled

rugged lotus
#

the ball can go over the AI's heads

#

if 2 for example pinch it , it goes up and over

lapis plaza
#

you can also just constraint some of the axis on rigidbody's physics settings

rugged lotus
#

i could probably get away with no physics at all if i remove the ball from the equation with my current scene

#

already is

#

since the AI doesnt need to rotate

lapis plaza
#

yeah, I mean you could just freeze Y too if you don't need them to move up/down

rugged lotus
#

but yeah ill still need the physics for future updates

#

the thing is im lazy to see what height they need to be exactly so thats why i just let gravity to it's job

#

its not gonna be just this one scene, but this one is the most physics-heavy

#

ive got a forest one where everything (for now) is just a static thing, and its just the AI wandering around

rugged lotus
#

@lapis plaza well that seems...bad?

#

are the spikes just the 20 fps timestep kicking in?

lapis plaza
#

0.13ms cpu cost is bad for you?

#

for the reference, 60Hz is 16.67ms

rugged lotus
#

yeah i know

#

im just wondering why teh spikes though

lapis plaza
#

those are probably your physics steps

#

it doesn't do physics simulate each frame

#

just look what the profiler says :p

#

I mean, that's the whole point of using it 😄

rugged lotus
#

huh, my coroutine's at fault maybe

#

i do have a yield return new WaitForFixedUpdate(); while its "wandering"

lapis plaza
#

you really shouldn't worry about costs in this ballpark at all

rugged lotus
#

still wondering though

#

is WaitForFixedUpdate a constant value that i can cache?

lapis plaza
#

none of this matters

#

if you really care about micro-optimization on this level, don't use built-in physics at all 🙂

#

but really, unless you have some badly performing part that costs you several milliseconds you don't have perf budget for, maybe then start to look into optimizing it

#

otherwise it's just all premature optimization for no good reason

rugged lotus
#

hahah alright alright ;p

#

my reasons are that CPU usage is about 4% when its running so idk

rugged lotus
# lapis plaza none of this matters

its a free performance boost tbh; and gets rid of GC alloc- i just put WaitForFixedUpdate as a static in my manager script; saved me multiple calls per timestep that also allocate CG

lapis plaza
#

ah, don't get me wrong, you should always aim for zero GC when possible, that comment was purely based on the perf impact

stuck bay
#

so question, this object had childs in its prefab and those childs have a collider each, as u can see in pic green lines, but instance itself doesnt have any collision, in course he said if u add rigidbody to gameobject it will detect the children colliders and it will work, but now when i add rigid body it doesnt work. any idea what i can do so game object detects prefab children colliders?

timid dove
#

If you're moving the Transform directly it's not going to matter either way

gray acorn
#

not sure if this is the right channel for this question, but here goes. I'm trying to make a simple 2D platformer with a tilemap that makes up the level. i have a tilemap collider 2d on the tilemap object, and a capsule collider 2d and rigidbody on my player. i move the player with rigidbody add force. as the player "slides" across the tilemap making up what constitutes a floor, the player will hit the corners or joins of the tiles in the tile map and either slow down temporarily, or bump up in the air momentarily before gravity pulls the player back down. is there any way to prevent this? i think i've read something about using Havok physics and "welding" joins together or something along those lines, but i'd prefer to use the built in physics engine.

rugged lotus
#

and interpolation made everything look prettier xD

#

not sure if i should make my AI's collision detection discrete or continuous though

#

the thing they interact with, the ball, is continuous; so idk if the AI also needs to be continuous

stuck bay
#

Q=mc∆θ

#

I like this one

quiet ivy
#

why just having rigidbody2D on an object makes it jitter even if i move with transform.position

#

and interpolation does absolutely nothing

#

moving with velocity makes it even worse and interpolation still won't do anything

quiet ivy
#

tbh interpolation makes it only worse

#

updated unity and now its fine with rb on the object but still no idea how to get smooth movement with velocity

#

From left to right:
RB, Velocity, Interpolation
RB, Velocity
RB, transform.position
NO RB, transform.position

#

this driving me mad already

quiet ivy
#

it seems to be absolutely fine in 3d, why that isn't the case in 2d?

jovial wraith
#

interpolation is trying to guess where the rigidbody is going to be between physics frames. If you are updating its velocity yourself, it makes it so all of the interpolation guesses are wrong, which is why it introduces the jitter

#

moving an object with a rigidbody on it using transform.position is generally a pretty bad idea. It makes the physics system get out of sync and can introduce all kinds of hard to track down bugs

#

and just look bad often

#

I find Rigidbody2D.MovePosition is a good option when I want to manage my object's velocity in my own code, rather than letting the rigidbody work it out based on forces

quiet ivy
#

I tried MovePosition and it was pretty much the same problem

#

In 3d tho setting velocity of the physics object with interpolation is buttery smooth

supple pawn
#

I believe Unity's 2D approach is Box2D and 3D Approach is PhysX right?

supple pawn
#

or iterations I think

quiet ivy
#

I found a short-term solution by setting it to 140 updates per second

lapis plaza
stuck bay
#

It's not a physics channel

#

There is no scientific discussion about physics

#

I need help...When I start my game the character just falls through the floor

#

Any know how to fix this?

lilac garden
#

Constraints are on, local center of mass is manually set (correctly), inertia tensors (both) are 0, I still get rotation on axis that should be 0.
localRotation.y == 0.001 (?)

    private void Start()
    {
        rb = GetComponent<Rigidbody>();
        rb.centerOfMass = Vector3.zero;
        rb.inertiaTensorRotation = Quaternion.identity;
    }
stuck bay
#

so i want to recreate something like an analog stick inside unity

#

how would i move it along a sphere(? i guess thats how its done)
and also restrict it to like that circle edge

#

imagine the transform would be uhh the top of the analog stick

#

idk maybe like this i cant really draw good xD

#

Ball/Sphere to show its moving not on a plane

inner thistle
#

Make the ball and stick one object and rotate it so that the pivot is in the middle of the ball

#

like it does in real life

stuck bay
#

so rotate the ball? 🤔

#

hmm good idea

#

but how do i resrict it like the analog example?

#

like i could say if you just turn it left/right you can check if angle < 30 && angle > -30 or something

#

but if its up/down AND left/right then you cant really do that since its a circle not a square so idk how to change the checking angle

past grail
#

Guys, I probably got it here with my questions. But there is one that has been haunting me for a couple of days.

There are enemies, I cling to them with the hands of my player with a cutter joint that hangs on the player's hand. The joint is default.

The problem is this: there are two options for my player (2 skins in fact). In one player, this bone, which I am hooked on, is rotated so that the Y-axis initially looks vertically, in another skin the bone is rotated differently.

When I use the first player option, I grab the enemy normally, nothing trembles. But when I grab the enemy with the second version of the player (where the axes are rotated differently), the mob begins to very much sausage in all directions, everything is set 1 to 1. Only the rotation of the bone is different. How can this be fixed? Someone worked closely with joints. THX

inner thistle
stuck bay
#

Hey everyone, so I have an object and I want it to go down a slide, but it just gets stuck when it hits the slide, it doesnt slide down. What do I need to do to make it "slidey"?

timid dove
#

that allows you to change the default friction settings

#

Any movement scripts you have for the object could also be potentially causing issues.

stuck bay
#

thank you @timid dove I found it out anyway, but thanks anyway!

#

I already typed this in another channel and was suggested to go here but

#

Im in a middle of different project so I haven’t started this, but I wanted to know how to make something like this in 2D: If you were to collide with a surface with a high enough velocity, immediately jumping off that surface would give you a higher velocity than you did before the collision.

#

Also if you wait too long, then you’ll lose that built up speed and your jumping will be normal.

timid dove
spark sphinx
#

Is there a relatively cheap way to simulate pools of water? I'm talking about having water conform to the shape of its container while also applying water physics to objects in its volume.

runic surge
#

will DOTS physics ever support multi-platform determinism

#

the only possible way rn is using dots and SoftFloats/FixedMath

lapis plaza
#

time will tell

#

wouldn't expect it to happen in following few years

#

they keep talking about it being some distant thing on their roadmap they are not focusing at all atm

#

@runic surge

#

here's a recent staff comment about it

#

you can read between the lines that it's firmly sitting in the backlog and has very low priority atm

#

same people used to give more optimistic estimates of this few years ago

#

it's just really clear it's not in any near term plan anymore

runic surge
#

Alright

#

I built my own solution anyways

#

but it would be nice to have a DOTS solution

#

@lapis plaza thanks

pulsar cypress
#

Does anyone have a recommendation for a good tutorial that helps provide a thorough understanding of Unity physics including but not limited to Rigidbody, AddForce etc

lapis plaza
#

@pulsar cypressI don't have any beginners tutorial to recommend, there this more in-depth talk that may give some insight to why certain things happen (but it's really geared towards people who've already used physics engines for a while): https://www.youtube.com/watch?v=NwPIoVW65pE

GDC

In this 2015 GDC talk, QWOP creator Bennett Foddy explains how to make your game feel solid without writing your own physics engine or breaking your entire game.

GDC talks cover a range of developmental topics including game design, programming, audio, visual arts, business management, production, online games, and much more. We post a fresh G...

▶ Play video
stuck bay
pulsar cypress
#

It's not a good idea to involve Time.deltaTime when calling rb.AddForce() in FixedUpdate, right?

lapis plaza
#

no

#

it's horrible idea, considering force itself as concept includes the time component already

pulsar cypress
#

Thanks, wanted to just check my intuition 🙂

lapis plaza
#

@pulsar cypress

pulsar cypress
#

Great tip, thanks!

wind quail
lapis plaza
#

@wind quail forcemode is just the optional parameter in AddForce, there's no AddImpulse for example in Unity (like there is on some other engines), instead you just do AddForce(value, ForceMode.Impulse)

#

not sure if you meant that or something else

wind quail
#

oh

#

that is what i meant

#

thanks :)

#

also, for my player movement, after my character falls for a certain amount of time the x+z velocity starts to decrease exponentially

#

and i can't figure out why

runic surge
runic surge
#

the easiest way to get cross-platform determinism right now is to use Fix64/SoftFloats with a modified physics engine (replace float math with fixed math and ensure stable sorting and no random number generation). I did it with a C# Jitter Physics port, but I could have also used DOTS

lapis plaza
#

oh, nice

wind quail
#

how would i go on about simulating artificial gravity for player (that scales up as you fall down)

stuck bay
#

hello, I'm using AddRelativeForce and I see speed in the inspector but I don't know how to access it in code...

#

nvm

verbal hamlet
#

Why does my player sometimes get stuck?

unique cave
# verbal hamlet Why does my player sometimes get stuck?

that's probably the capsule collider hitting the edge at perfect position. what method you use to move the player? changing .velocity straight sometimes leads into physically incorrect behaviour. it would be better to use .AddForce instead.

verbal hamlet
#

It works now

#

I disabled friction whilst the player is in the air

eager remnant
timid dove
eager remnant
stuck bay
#

im having issues with uh hdynamic bones rn

#

two separate issues

#

created a dynamic bone for the hip and it only added one circle

#

and on the video im wathcing it says two

#

and then somehow my skirt/dress physics wont even work

#

even though i added exclusions

#

but like

#

if i remove them the legs become jelly

timid dove
maiden pawn
#

If I'm launching an object with the mouse, what system would be better?

#

Adding an impulse or angry birds style?

lapis plaza
#

whatever works for your gameplay better

sweet snow
#
  1. is how I would expect such a mechanic to work. But what 0lento said is prob what you should do.
verbal hamlet
#

How do i create a contact filter 2D with Usetriggers enabled

tawdry wave
#

Help! Fast-moving rigidbodies go through walls constantly. Setting the collision mode to "continuous" does not fix it, does anyone have a solution?

tawdry wave
#

They seem to go through mesh colliders. Switching to a different type of collider is not an option. Does anyone know how to fix it?

timid dove
#

Or are you just modifying the Transform position directly?

unique cave
#

(MovePosition and rb.position are not physics-friendly ways either)

merry plinth
#

Also, quoting the documentation entry on the Collision Detection Mode...

Use this to set up a Rigidbody's for continuous collision detection, which is used to prevent fast moving objects from passing through other objects without detecting collisions. For best results, set this value to CollisionDetectionMode.ContinuousDynamic for fast moving objects, and for other objects which these need to collide with, set it to CollisionDetectionMode.Continuous. These two options have a big impact on physics performance. Alternatively, you can use CollisionDetectionMode.ContinuousSpeculative, which is generally cheaper and can also be used on kinematic objects.

https://docs.unity3d.com/ScriptReference/Rigidbody-collisionDetectionMode.html

sly wave
#

hey quick question. I was using a raycast to detect if the character was grounded but a issue came up where the character would technically still be in the platform (part of the hitbox is still on the platform) but the center of the ground check is already off the platform. Is there a better way in which i could check for the size of the hitbox if it is grounded or not? I tried the check sphere but i ended up being able to check the "is grounded" of certain walls and angles where I wasn't meant to

tawdry wave
tawdry wave
raw estuary
tawdry wave
raw estuary
# tawdry wave Yep

Hmm, that is interesting. Do you have the possibility to share a project where this can be reproduced? Would be interesting to look at. I never had that issue with static geometry so it would be interesting to look at a case where it happens.

timid dove
#

One of which is that your mesh geometry is messed up

#

Otherwise, this sounds like your bog-standard tunnelling situation

tawdry wave
timid dove
#

Options to mitigate tunneling are:

  1. Use continuous collision detection
  2. Decrease fixed timestep
  3. Make your moving objects larger
  4. Make your static objects thicker
  5. Make your moving objects move slower
  6. Do your own custom raycasting to detect collisions pre-emptively
raw estuary
#

My understanding was that tunneling should not happen with continues detection and a static collider.

tawdry wave
#

Well apparently it does happen, and very easily too. And I can't do my own custom raycasting

#

I'd like to use the built-in rigidbodies because my own raycasting solution would take too long

tawdry wave
timid dove
#

continuous collision detection is not perfect

#

But I'm kinda thinking you might just have a mesh with messed up geometry if it's happening so easily.

tawdry wave
timid dove
#

Nope, nothing is perfect. Physics engines are one big tradeoff between realism and performance

timid dove
#

and how big are they

#

And can you share your code

tawdry wave
timid dove
#

Which force mode?
How often is it called?
What is the mass of the body?
How long is it accelerating before the collision?

#

if it's a 1 kilogram mass, then a force of 250 will accelerate it up to at least 250 m/s after just one second

#

which is very fast

#

Mach 1 is about 350 m/s for reference

tawdry wave
#

The objects go through walls VERY easily

timid dove
#

For a pickup script it's almost definitely not be using AddForce

#

seems too finicky

#

I'd just use MovePosition to interpolate it into your hands

raw estuary
timid dove
#

Yeah - show the code ideally

tawdry wave
#

This script does use AddForce

raw estuary
#

I just added an impulse force of one million to my cube and it did not go trough the wall. Did you set your collider to trigger or something that makes it go trough walls? We are reaching the point where we need to be mind readers to help you. It's quite frustrating to have to try to drag information out of you just to help you.

lapis plaza
timid dove
#

Honestly guessing going through the wall at this point is not related to normal movement of the body, rather it's something to do with your code after it's being "held" - where it probably is moving due to being parented to something or similar that doesn't obey physics

tawdry wave
#

Nothing else

timid dove
#

Anyway show how your scene is set up

#

based on that tutorial there's no object anywhere that should be positioned somewhere that the object could go through

#

so like... give us a clue as to what's happening

raw estuary
# tawdry wave Nothing else

There is something else than physic forces affecting the position of your object. I'm happy to help you if you share your project but I don't want to go trough a youtube tutorial just to help out. 🙂

tawdry wave
raw estuary
#

What is objRig?

#

ah nvm it is declared there.

timid dove
#

This tutorial is awful

tawdry wave
#

MoveObject() is the part where the rigidbody moves

timid dove
#

If they're telling you to use AddForce in Update like that

raw estuary
#

What is holdParent that you set objRig to be a child of?

tawdry wave
#

Which tutorial is good then? for picking up objects

tawdry wave
#

just an empty gameobject

#

and the object should follow that point, and it does, but goes through walls easily for some reason

raw estuary
#

But if you set your picked up object to be a child of that point, it means your object will teleport with holdParent

timid dove
#

Yeah another reaosn why this tutorial is bad

#

there's no reason to be parenting anything to anything

raw estuary
#

If holdParent moves that movement will affect your objects position without physics.

tawdry wave
#

Ok but which tutorial is good then?

timid dove
#

don't have one off the top of my head

raw estuary
#

What happens if you do not set it to a parent of holdParent?

tawdry wave
#

One moment i'll check

raw estuary
#

Maybe we can repair this one 🙂

tawdry wave
raw estuary
#

Great to hear! And that is why you should share your code when you want people to help you find issues. Even if you're a professional programmer who spent 20 years coding there will be things you miss. 🙂

obsidian herald
#

is it possible to add gravity to charactercontroller? i tried already rigidbody but it didnt work is there a betther way than scripting it by myself?

timid dove
#

You have to script it yourself

#

It's not complicated

unique cave
timber mason
#

Why does character controller and root motion cause gravity?

outer radish
#

What do you mean by cause gravity

timid dove
static glen
#
        var ray = new Ray(new Vector3(x, 2, y), Vector3.down);
        Debug.DrawRay(ray.origin, ray.direction * 10, Color.red, 10);
        if (Physics.Raycast(ray, out var hitInfo))
        {
            print(hitInfo.transform.name);
            if (hitInfo.transform.name.Equals("Road"))
            {
                return false;
            }
        }

Why does this code ignore the Road?

dapper yarrow
#

some one know how to get the obj that the Physics.CheckSphere(transform.position, .1f) get?

static glen
nocturne shell
#

Hi, I'm looking for examples of 2d top-down physics based controllers - ships, boats, cars, etc. Especially how to control AI

timid dove
static glen
#

Yeah

slate lily
#

Why when I set my fixedtime step via script 1/60 it laggs and when I set it in the time settings it doesn't?

#

any help

#

?

vale latch
#

is there any way to make custom collisions based on models that work with rigidbodys in present unity?

stuck bay
#

What would be the best animation rigging constraint for dynamic pelvis? for natural animations on uneven terrain.

slate lily
#

Anyway I fixed it tho

slate lily
#

I have another question when I have higher frame rate like say 120 do I need to make physics timestep lower as say 1/120 or no need for that?

slate lily
#

in general is having high frame rate effect fixed update call cause it works fine for me at 1/60 at 60 fps if someone have say 120 fps will it be called less or at same rate?

inner thistle
#

If you set the physics time step to 1/60 then it'll always be called 60 times/second regardless of frame rate

#

They're not connected. That's the entire point.

timid dove
slate lily
#

Thank you

haughty steeple
#

the circle around the player is too big so the box collider works like this

#

cravity is on how can I fix that?

haughty steeple
velvet berry
#

is there a way to disable backface culling for mesh colliders?

#

or at least make it cull front faces instead of back faces

#

flipping normals of meshes is not an option for me
i have thousands of objects with millions of triangles, it will probably take weeks to flip normals

timid dove
#

MeshRenderer yes

velvet berry
lapis plaza
velvet berry
lapis plaza
#

also... why you even have that kind of source material?

#

doesn't sound very game ready

velvet berry
#

im trying to import the map of an AAA game into unity. the tools for extracting the map of this game have only one problem: flipped normals.

lapis plaza
#

these tools are not really built for being handy to import sketchy source material, assumption is that people import things that are designed to work in certain way so your best option is to just fix the material 🙂

#

there's really no reason why your mesh colliders normals would need to be inverted in normal conditions

velvet berry
#

but they added an option for culling front faces in materials

#

not much people would use that too

lapis plaza
#

it's a rendering thing, there are real reasons for being able to render both sides

#

physics work differently

#

you get all kinds of physics colliders too, not just mesh colliders. there's no such thing as inverted normal sphere collider primitive for example

#

point being, having invert normals option only for some specific collider type could get confusing to users

#

also if you really need it, you can just write your own conversion tools to handle it, nobody would do that amount of asset processing manually if it's a repetitive task

velvet berry
#

the easiest way to do it that i can think of is, editing blender fbx exporter code to make it export everything with flipped normals.

lapis plaza
#

I don't use blender but if it has any macro capabilities, you might be able to automate the normal flip and export on single operation

stuck bay
#

ok so i have this tileset in my game which has a physics material that has 0 friction, which is what i want, however, i do want there to be friction for a specific type of object in my game, but no friction for anything else. how?

#

ok i did it with this
gameObject.GetComponent<Rigidbody2D>().AddForce(-gameObject.GetComponent<Rigidbody2D>().velocity * FrictionMultiplier);
which is basically
f = μN

#

if anyone knows a better way to do it though lemme know

timid dove
stuck bay
#

i thought about that too but i feel like that would be less performance efficient

outer radish
#

Create a material instance through script

timid dove
#

How would that helpful

outer radish
#

You would be able to set the friction for the specific item unless i misunderstood?

timid dove
#

You can do that in the editor

stuck bay
#

i mean like the tileset has 0 friction

#

so no matter how much friction the specific item has its still 0 friction for some reason

timid dove
#

Couldn't you have done it the other way around

#

Give tileset normal friction

#

Give the items 0

outer radish
#

Yeah thatd be the proper setup

timid dove
#

Unfortunately in 2D you don't get friction combine options like in 3D

#

2D might always use average or something which wouldn't work

stuck bay
#

the issue with that would be every time i make an object i would have to add the no friction material

#

so it would be less work efficient

outer radish
#

Thatd be where an automated script comes in handy

stuck bay
#

putting this gameObject.GetComponent<Rigidbody2D>().AddForce(-gameObject.GetComponent<Rigidbody2D>().velocity * FrictionMultiplier); in on collision stay works really good so ima keep that ig idk

stuck bay
#

ok so how do i make a 2d object that can only collide with the bottom face of the player's box collider and only collides with it if the player is moving downwards

#

and also make it so that the player can fall through it if he presses S

#

like terraria platforms kind of

timid dove
# stuck bay ok so how do i make a 2d object that can only collide with the bottom face of th...

In this video we have a look at Unity's 2D effectors.

● Download Sprites: https://www.assetstore.unity3d.com/#!/content/73728

♥ Support my videos on Patreon: http://patreon.com/brackeys/

····················································································

♥ Donate: http://brackeys.com/donate/
♥ Subscribe: http://bit.ly/1kMek...

▶ Play video
#

The platform effector is the one you want (8:44 in the video)

stuck bay
stuck bay
#

bruh player can still collide with it even after i disable that in the collision matrix

#

how

wicked night
#

So I'm tryna make very realistic physics, like Boneworks level for my VR Metaverse. Anyone got any good references that could help?

outer radish
wicked night
#

Probably something to read

#

Like some documentation or something

outer radish
wicked night
#

I have Havok, was wondering if there is a way to make it better, or if there was something even better than Havok.

outer radish
#

That, I don't know, sorry.

wicked night
#

Alright. Thanks for trying though!

timid dove
#

For example proper conservation of momentum or angular momentum or something?

wicked night
#

Like I want them to be near real life level physics. It's hard to explain

lapis plaza
#

Havok in Unity is DOTS setup, it's not really that useful today

#

Unless you actually are coding your gameplay in ECS

#

(would totally recommend against it today)

timid dove
# wicked night Like I want them to be near real life level physics. It's hard to explain

Well basically anything you run in a computer simulation is going to be an approximation. Nothing will be perfect. PhysX I would say is "near real life level physics". But it's going to be hard to help unless you mention some specific interaction or something that you're wanting the physics engine to support better. For example, are you looking for SoftBody physics or something? Determinism across varied hardware?

#

depending on your answer, there's different routes you should be pursuing.

wicked night
#

I think I want the VR character to act like a human being, like it should have mass, you should be able to pull yourself up onto things etc.

#

would that still be physics?

#

or more vr?

shell hill
wicked night
#

Ohh yo thanks

#

This helps

tender gulch
#

Anyone has experience with implementing custom wheels or have a comprehensive understanding of unity wheel colliders forces formula?

#

I'm trying to write a custom wheel, but I'm stuck at the calculating the forces applied by the wheels/tires based on the slip of the wheel...

jovial wraith
# tender gulch I'm trying to write a custom wheel, but I'm stuck at the calculating the forces ...

I don't have specific knowledge of unity wheel colliders nor have I implemented custom wheels, but a BS in physics is better than peanuts. I'm happy to lend a hand trying to muddle out the right eqns. What do you mean "based on the slip of the wheel"? Slippage should be determined by the forces, not the other way around, right?

Probably not perfect for what you're doing, but my favorite physics reference has an article on tire friction specifically. http://hyperphysics.phy-astr.gsu.edu/hbase/Mechanics/frictire.html

halcyon nest
#

Hi! I'm executing Edit Mode tests that include physics by simulating the steps manually.
The rigid bodies are moving correctly but they don't seem to generate collision events when they collide with each other.
Is it possible to generate them on Edit Mode?

flat atlas
#

I need help

#

i have a capsule as a character but when i add capsul collider it keep flying

mellow oyster
#

does it have a rigidbody on it aswell

flat atlas
#

yes it does

timid dove
timid dove
halcyon nest
coarse willow
#

Hi there, I'm brand new to Unity, but not entirely new to making games, so I've been going through some basics to get the hang of things and I am running into an issue with 2d rigid bodies and colliders. more specifically, i have 1 rigid body representing a player character that i've also assigned a 2d collider to. separately, i have another asset representing some ground for the player character to move around on that I've also given a 2d collider to. I am using stock settings on all of these components right now and both the ground and player character models are on the same sorting layer. despite that, my player character continues to fall through the floor whenever i hit play to run the game. haven't had any luck finding any answers in my own research / messing around with settings. any suggestions?

jovial wraith
coarse willow
jovial wraith
coarse willow
#

nothing on trigger, and the body is set to dynamic. should it be kinematic?

jovial wraith
#

What physics layer are the objects on? (just called layer in the upper right corner of the editor when you have the object selected)

#

sorry, I g2g. Hope someone else jumps in to help you debug

coarse willow
#

they are both on the default layer atm

#

thanks for hopping in while you could

coarse willow
#

if anyone else has any thoughts, i am all ears. still haven't found a solution and I really have no clue what's causing it. T_T

halcyon nest
#

@coarse willow
can you show a sreenshoot of both rigid bodies and colliders?

long egret
#

Hey guys, running into a physics issue with a prototype I'm working on and feel like I've exhausted most of my troubleshooting options, so hopefully someone can shed some light on this issue.

I'm currently prototyping a game similar to Katamari Damacy, where the mechanics involve rolling a sphere around an environment to pick up progressively larger objects. When the sphere comes into contact with an appropriately-sized object it should pick the item up and become attached to that sphere to make it larger, much in the way one would roll a snowball.

The issue I'm currently having is apparently something to do with the collision detection of child objects attached to the sphere. I'm able to detect collisions and attach appropriately-sized objects to the sphere, however the collision for the attached object seems completely off, as if it's colliding way too early. As a result the sphere will do approximately 1/2 of a full rotation and stop as if it has hit a wall instead of continuing to roll as expected. It's worth noting that if I disable collision for the object when it is attached to the sphere the sphere will roll as expected, however doing this defeats the "snowball" effect that I'm trying to achieve.

This is how I'm currently implementing this feature in code, not sure if this is somehow incorrect when dealing with physics and rigidbodies:

    private void OnCollisionEnter(Collision other)
    {
        if (other.gameObject.CompareTag("rollable"))
        {
            other.rigidbody.isKinematic = true;
            other.gameObject.transform.SetParent(transform);
        }
    }
long egret
#

lol and of course after I type all of that out I found my answer apparently

#

(for anyone curious, apparently destroying the rigidbody component is the fix)

coarse willow
#

the first one is the grass with its collider and the second is the player character with its collider and rigidbody2d components.

halcyon nest
#

@coarse willow
The Box Collider on the Grass is not a BoxCollider2D

coarse willow
#

well then...that makes sense. i feel silly for not having noticed that. though i do wish the 3d ones were just named rigidbody3d or collider3d. oh well. thanks!

nimble crater
#

anyone knows about wheel colliders physics? i want to make my car more responsive because it has such a delay steering idk how i can fix it

timber canyon
#

okay, 2D question: i'm trying to do something like this where an arm with a weight at the end drags behind as the object it's connected to moves, but i can't seem to get it to behave properly. how do i make this work?

wraith junco
#

custom wheel colliders in general is something that isnt on the unity forums

#

pretty difficult topic

cunning finch
tender gulch
timber canyon
tender gulch
timber canyon
#

so that when the main gameobject moves, the hanging gameobject drags behind

tender gulch
#

If only there was source code for the current wheel collider implementation,it would've been simpler...

wraith junco
#

mine is heavily based off of this

#

it's the only relevent thing I could find on the topic

tender gulch
#

I've seen this one, but it didn't fit my purposes.

tender gulch
#

I only wanted a wheel that detects collisions at several points. The default wheel collider does only one raycast, making wheelies(on bikes) extremely buggy.

#

I managed to get that part down and suspension too, so there's just the friction part left.

timber canyon
cunning finch
#

i think its simple

wraith junco
#

I ended up removing about 60% of the code and cleaning it up, since the friction stuff didn't seem to work well, or I just wasn't setting it up properly. Then I used some dot product magic to counter gravity on the left vector of the car, since it slides down slopes in a really nasty way

#

countered forward gravity too to prevent rolling on uneven surfaces

cunning finch
timber canyon
wraith junco
#

It's always been on my mind but I never attempted it yet

cunning finch
#

the moving object must have rigidbody too but you can set him to Kinematic

timber canyon
#

ah, i see, i'll give that a try. thanks!

cunning finch
#

No problem

#

🙂

patent fractal
#

hi there, i've got a weird problem. I'm using a raycast to shoot a projectile towards a target point, and when it intersects with the ground I create an explosion. This works perfectly in the editor, but in the build it doesnt. Any ideas why?

tender gulch
stuck bay
#

hey i need help with rotation of the object in 2d

#

i want the yellow and green to also spin in same direction as orage (left and right rotation)

#

but they move in a weird y rotation

#

how can i fix this?

#

nvm i got it!

jovial wraith
# tender gulch Sorry for the late reply. What I meant to say is how to calculate the final forc...

If the wheel is slipping, the force applies should be the maximum possible kinetic friction force (uN, or umg in most static cases). Anything in excess of that accelerates the slipping, and if less force than that is applied it means that the forces being applied are not enough to overcome kinetic friction, so its not slipping.

If you're applying it at multiple points, a first approximation would be to just divide the force equally across all your contacts. Not sure how those results would end up. If you want a nonuniform distribution of force across the contacts, you could take the magnitude of the vertical component of each normal and use that for weighting how much of the weight is distributed to each contact.

The next step after that would probably be to start considering the torque applied at each contact as well -- that seems like it'd probably provide diminishing returns.

If you're trying to also account for the suspension's effect on this, then you're getting into systems of coupled ODEs land. That seems to be what the PhysX code Olento posted above is doing.

wispy tinsel
#

Soooo, I want to make pipe system that is similar to electricity circuits as works like lego blocks.
Here all important details:
https://github.com/bustedbunny/GasExpansion/issues/1

Any help with solution to this problem is appreciated.
P.S. no idea how to actually ask help with such questions, if you know I did smth wrong, let me know

GitHub

For efficient pipe network ticking, all connections should be resolved outside of ticking. Upon installation of pipe objects, or changing it's flow data. Currently raw data available in suc...

stuck bay
#

I have a question that may sounds dumb but I'm still at the beginning:

I have a car that has a box collider (a simple cube) that when collides with another car (still cube) passes through it, like the collision exist but the forces it implies are necessary to ignore the collision. How can I solve it? I can send a little video if needed.

timid dove
#

if you are moving them directly by setting their Transform positions, they will go exactly where your code tells them to go, ignoring all physics entirely

stuck bay
timid dove
#

you need to move it in a physics-friendly way

stuck bay
#

that's the problem, right?

#

So I don't have to use transform.Translate?

timid dove
#

You can't use that if you want things to interact with physics

#

you need to give your objects Rigidbody and move via setting the velocity or AddForce on the rigidbody

split hill
#

anyone know the best way to get physics like in TABS?

plucky crag
#

Hey! I'm new to unity, been using c# for a few months now. I want to make a golf game, I found a ball flight physics model I want to use but it's written in python with numpy to do the math. should i re-write this in c#? can/should unity use numpy/python for this? does unity have a way to use 3rd party .net libraries or how does that work? Does unity have it own math libraries for this kind of stuff? i need to solve linear alg / calc / differential eqs

hollow echo
#

You can pull in DLLs from third party libraries but you also have to pull in all their dependencies. There are tools that make it less manual, but I would not really advise getting too deep into it if you're just starting.
What's complex about the flight model that requires it needing all this maths? Are you going for something more than a basic ballistics curve?

plucky crag
#

it's a golf specific model that takes inputs from measured data from a golf launch monitor, so you actually hit a golf ball and it measures spin, angles, velocity etc. the model takes into account wind speed and barometric pressure

#

i suck at math, i had to take pre-calc three times

#

numpy.interp(x, xp, fp, left=None, right=None, period=None)[source] One-dimensional linear interpolation for monotonically increasing sample points.
i need to do stuff like this

#

i would have to use numpy in unity somehow

timid dove
#

Unity has interpolation functions in Mathf and in the Unity.mathematics package

#

Although that seems to include a bunch of other things like a periodic interpolation which you'd have to do separately, e.g with the % operator.

hollow echo
#

The built-in math functions are going to have less of a scope than numpy afaik. But you can probably find some .NET math libraries that will cover other things you need. Or even just C# versions of certain functions. I'd probably be more worried from an architectural sense. I have little familiarity with python, and if you have little familiarity with Unity/C#'s libraries then there might be confusion that will be very difficult to fix when manually translating between libraries

#

I've tried to port some things in the past, and you spend a bunch of work and get to the end and it doesn't work and you're like... 😐 okay but which part did I screw up

plucky crag
#

I read something about ironpython and unity? Would it practical to run python in unity? It's just a calculation for a single ball flight not complex physics like a "action" game so performance might not be a big deal

hollow echo
#

Can't speak to that, sorry. Might be worth asking about it in one of the code channels

timid dove
#

Might save you a ton of development time if it's easy to set up and the performance is acceptable

#

Assuming the thing you need is ready to go in python already

plucky crag
#

ok thanks for letting me pick your brains, this community is huge!

stuck bay
#

how would you "grab" something in unity?

#

i made like a very simple hand but the item just falls off

timid dove
#

Lots of options

tender gulch
royal topaz
#

not sure if this is the right channel but im following a tutorial on making my enemy ragdoll when they die. Why is he not falling to the ground?

urban wolf
#

@plucky crag you can always run python standalone, take inputs, process them, and send them to an open unity application via sockets, or something like that

#

did that with face recognition a few years back, had no issues

#

unity was only used as a renderer

wraith junco
#

it could be a number of things

#

check if the rigidbody is kinematic first when hes supposed to ragdoll and die

royal topaz
lapis plaza
# tender gulch If only I could understand what's going on there.😅

it's pretty basic raycast suspension but they compute unsprung masses bit weird there, it's also quite unnecessary as the rest of their implementation is so subpar it doesn't really need that. there's also substepping scheme built-in to the physx vehicle where they actually integrate the vehicle's main body movement on it's own substepping when needed (Unity probably doesn't use this since it's running physics at fixed timesteps anyway). I do mention the substepping because it explains why they did certain things there, like have their own physics integrators there

#

vehicle code is actually part of the more readable part of physx internals, usually that stuff is super cryptic there 😄

#

if you compare say, bullet physics and physx source code for readability, it's like night and day (bullet is actually human readable)

tender gulch
lapis plaza
#

of course looking at the vehicle code without prior knowledge of the vehicle dynamics probably makes it more cryptic

#

all in all, their tire dynamics math is really simplified thing, you also won't get great experience with it but if it's all that you want I guess why not

#

that explains pacejka '94 algo, but he has like few dozen variants, that's just one

#

if you want to start with something simple, you could look at the end of that page and see the "Simplified Magic Formula"

#

it's not going to be great but it'll get you going, alternatively you could just draw the curve yourself with Unity's Animation Curves and just use that as lookup

#

basically you want some way to indicate that tire has more friction the more load it gets (more it gets pressed towards the ground) and that tire friction has some limit at some point where it starts to slip more

#

this is why you typically see graphs like these all around when talking about tire physics

#

if one wants to learn more about this stuff, there are plenty of good books on the topic, I've glanced over most of them so can recommend some of them

#

first one is really good intro book if you know nothing about the topic, and last two are "essential" reads if want to know more in depth about these topics, genta's book is kinda expensive though (but it also covers basic stuff too)

#

but if you just want arcade vehicle controller... just put some abstracted tire physics thing there and call it a day 🙂

#

@tender gulch

#

sorry for the wall of text (and images)

indigo stag
#

guys i created an object using 2d physics but it is crossing the collision depending on the applied force, how can i fix it?

stuck bay
#

xd

timid dove
young rapids
#

What's the equivalent of the AddForce code when using a physics shape instead of a rigidbody?

full perch
#

Whats the difference between these lines? Why is the result different? ```
rb.AddForceAtPosition(rb.worldCenterOfMass, transform.forward * Input.GetAxis("Vertical") * speed);
rb.AddForce(transform.forward * Input.GetAxis("Vertical") * speed);

inner thistle
#

it's different because the parameters are the wrong way around in the first one

tawdry wave
#

Help! All rigidbodies fall slowly like it's moon gravity, changing mass doesn't change anything. My gravity setting is the default (real world gravity), and my world's and all objects' scale is just like in real life (1 meter is 1 unity meter). Anyone know what the problem is?

timid dove
#

Or your timeScale is reduced

#

Changing mass will never affect the falling speed of the object by the way

#

Everything falls at the same speed regardless of mass

young rapids
#

I'm trying to follow the unity physics basics, but when I press play, everything is invisible

timid dove
#

Make sure your objects are actually in view of your camera

#

Including on the z axis

young rapids
#

Yeah, even in the editor view they disappear

timid dove
#

Wdym disappear? Are they still in the hierarchy?

#

What's their position in the world when they disappear?
Are they getting disabled?

#

There's only a few possibilities:

  • they moved
  • they were destroyed
  • they were disabled
young rapids
#

They are still in the hierarchy ,they just don't render.

timid dove
#

If they're not disabled/deactivated, then you've just moved them somewhere out of sight

young rapids
timid dove
#

I can't read the hierarchy in these screenshots but what am I looking at

young rapids
#

The objects disappearing when I press play.

#

I'm not really sure how else to describe it.

#

They are there in the editor, I press the play button, they do not show up.

timid dove
#

Which object

#

The sphere?

young rapids
#

You can see that the sphere and floor are not there in the second screenshot right?

timid dove
#

What's that whole ConvertToEntity script you have

#

I don't see the default object in the hierarchy anymore either

#

In the second one

young rapids
#

The one they said to put in in the Unity Physics documentation.

timid dove
#

So it's being destroyed

#

It seems like you're trying to use ECS?

#

Unity Physics is for ECS

young rapids
timid dove
#

Are you using ECS too? Pretty sure this stuff only works in ECS/DOTS

latent garden
#

Hello, im using Platform effector 2d
to be able to pass through the bottom but i cant pass from the borders.

lapis plaza
#

your object moved by physics that run on fixed update which is async to rendering update

#

@bitter rose

#

ways to deal with it:

  • not use physics or fixedupdate to move your game character
  • use interpolation if it has to be physics based
tawdry wave
tawdry wave
young rapids
#

How do I stop drag from effecting gravity?

#

When I turn up the drag to slow down my ball, it makes gravity really slow

unique cave
young rapids
#

I've made my own gravity script, and that seems to be working.

unique cave
young rapids
#

How would I do that?

#

A constant force acting against it's velocity?

unique cave
young rapids
#

Or, to do it realistically, is that a way to make the friction on the sphere be calculated by a small area at the bottom of the sphere rather than the exact point?

tacit jackal
#

not 100% sure this is the right channel, but anyways. I want to use the Unity Built in cloth component to make a cape for my character but I am facing some issues.

  1. When my player is accelerating the cape moves back as it should, but when the player reaches a constant speed the cape behaves as if the player is not moving
  2. My player has a character controller which has a capsule collider built in. The problem is that the Cloth component doesn't recognise that collider as a capsule collider.
young rapids
tawdry wave
#

Does anyone know why all rigidbodies fall slowly like it's moon gravity, changing mass doesn't change anything. My gravity setting is the default (real world gravity), and my world's and all objects' scale is just like in real life (1 meter is 1 unity meter). Anyone know what the problem is? And I don't have any scripts messing with anything either

#

Do I have to modify something on the rigidbody itself? It's all just default settings right now

azure mountain
#

Hi, (for the millionth time in gamedev history) I'm trying to "recreate" yet another pong clone lol but I have a slight issue...The force of the ball is increased if the ball hits a moving paddle instead of staying at a fixed speed... Is there anyway to have a fixed speed of the ball instead of it being affected by the force of the paddle?

(PS, in the version I'm trying to do, the paddle can move in all directions btw not just up and down, so if you hit the ball "running" towards it, the ball shoots off at high speed.

young rapids
timid dove
timid dove
azure mountain
#

hmmm any suggestions/tutorials that doesn't do this? Haven't found one that doesn't use rigidbodies

timid dove
#

Think about how they probably did it in the 70s

#

There were no physics engines to be had

tawdry wave
azure mountain
#

agreed...I am however, very shite in math so... 😛

timid dove
#

It's just objects moving at constant speed in a straight line and bouncing

timid dove
#

If it's 3D you have to apply your own extra gravity force

#

Just know that it's unrealistic, which is fine if you're not looking for realism

azure mountain
inner thistle
#

? Unity does have air resistance a.k.a. drag

#

set a higher drag to objects that should fall slower

lapis plaza
#

Unity's "drag" isn't actually air resistance at all

#

it's actually linear damping

#

them calling it drag is misleading too

timid dove
#

They would both be affected identically by Unity's drag

inner thistle
#

if you put higher drag on the feather it'll fall slower

#

It's set on individual objects, not globally

timid dove
#

Well yes

tawdry wave
timid dove
#

And no, AddForce would have to go in FixedUpdate

lapis plaza
#

huh?

#

unity doesn't expose the physx gravity setting?

timid dove
#

It does

#

Physics.gravity

lapis plaza
#

oh, @tawdry wave meant like per object

#

well.. then the only way to achieve that is to use custom gravity forces yourself

timid dove
#

Right yeah it doesn't

#

Only in 2d

lapis plaza
#

adding custom forces is not very complicated even

timid dove
#

There's only a useGravity bool for 3D

tawdry wave
#

Wait but what about the "drag" property? Does that not do what I want?

timid dove
#

It can as mentioned above

#

By @inner thistle

tawdry wave
#

Ah ok that would be an easier method than to have to make a new script, I'll test that

lapis plaza
#

Unity's "drag" is basically velocity = (1 - drag) * current velocity

#

if you omit some checks from it that is, but that's essentially the end effect it has

#

it's simply a multiplier for your current RB velocity

young rapids
lapis plaza
#

@young rapids adjust friction and damping for the object you are pushing?

young rapids
lapis plaza
#

I don't really see "bounciness" on that clip

#

just it being more floaty than what one might want

young rapids
young rapids
lapis plaza
#

remember than physics materials are using average of both sides phys mats by default

#

so if you ground has friction 0.5 and your object has 1, it will end up with friction of 0.75

#

in most cases you'd want to keep this behavior, but if it's some special case, you could just override the phys mat so it uses only one sides value

young rapids
#

I've just found the issue, and it's a leftover from me trying to stop the marble rolling

#

The marble's friction is 20

#

Oh my god it's perfect now

tawdry wave
#

Can drag be a negative number?

young rapids
#

That feels weird math wise

timid dove
#

Try it

young rapids
tawdry wave
#

It resets back to 0 when I try, so apparently I can't make the object fall faster than the default, looks like I need to make a script after all

lapis plaza
#

why would you even want to have drag as negative?

timid dove
lapis plaza
#

it would make your object accelerate even from smallest movement

timid dove
#

Then give the slower things more drag

tawdry wave
#

The object falls like a feather currently

lapis plaza
#

just add extra downward force to it

timid dove
lapis plaza
#

or that

tawdry wave
timid dove
#

Then it should fall normally

#

If it's not falling normally you have some other issue

lapis plaza
#

some people don't like realistic physics values

#

it's not unheard of

timid dove
#

Oh wait

#

How big are your objects

lapis plaza
#

many games have 2x gravity because of that

tawdry wave
#

It's a 1x1x1 meter cube and it falls like it's on the moon

lapis plaza
#

and yeah also could be issue with scale and such

timid dove
#

If you have really large objects... They might look like they're falling slowly

#

Sorta like a Godzilla effect

timid dove
#

How high are you dropping it from

#

Like I think your sense of scale might just be off

lapis plaza
#

I feel like it's more about weird expectations on how quickly real world gravity works

tawdry wave
#

Like 6 meters high

timid dove
#

Hard to say without seeing it ourselves, but yeah just increase the gravity setting if you don't like it

tawdry wave
#

I totally looks like a feather when it's falling

#

Alright I'll just change the gravity

lapis plaza
#

it should fall like one second or so I think

#

in real life

#

I didn't do the math, just approximation

#

ok did the math, it's 1.1s

#

also tested on Unity and it takes... 1.1s

#

@tawdry wave

#

I've timestamped part of this talk: https://youtu.be/NwPIoVW65pE?t=264

GDC

In this 2015 GDC talk, QWOP creator Bennett Foddy explains how to make your game feel solid without writing your own physics engine or breaking your entire game.

GDC talks cover a range of developmental topics including game design, programming, audio, visual arts, business management, production, online games, and much more. We post a fresh G...

▶ Play video
#

it discusses about the gravity in general

young rapids
#

Their material has like 0.05 bounce, so that shouldn't effect it

lapis plaza
#

too big timestep value for fixed update?

young rapids
#

Where's that

lapis plaza
#

project settings->time etc

young rapids
#

It's 0.2

#

Max 0.333

lapis plaza
#

0.02 is the default... it results in physics running at 50Hz

#

you could try on 0.01 and see if it improves the behavior

#

it does come with extra cpu cost though

#

you could also try different collision detection settings

young rapids
#

0.002 Has made it really smooth, but my acceleration seems to have also slowed down?

lapis plaza
#

0.002 is total overkill

young rapids
#

Yeah but when it's a small physics based marble game, I feel like it's ok to focus on the physics?

lapis plaza
#

basically you'd always want to set the physics update rate as low as possible while the thing still feels nice

#

but yeah, it's all combination of different factors

#

also if the timestep change changes your physics behavior you have some math error on your movement code

#

or it's just possible the whole game slows down because your cpu can't keep up etc

young rapids
#

The frames haven't been effected

#

0.005 is also fine by the looks of it

lapis plaza
#

there are small differences on the physics behavior if going from really slow update rate to faster but it shouldn't be huge difference at these speeds

young rapids
#

My movements done entirely by adding force in a movement vector

#

It seems to run at 2 different speeds in the game view, and build view?

#

It's like the timescale's slowed down

lapis plaza
#

@young rapidsyou use deltatime in your force calculations?

young rapids
lapis plaza
#

it is, hence asking

young rapids
#

Ah, no

lapis plaza
#

but even that depends

#

if you move by ForceMode.Impulse, then you have to factor in deltatime yourself again

#

(which would be silly since you could just use regular force then)

young rapids
#

it seems like the entire game timescale is lower. At the beginning when everything falls to the floor, it's slow.

#

Not just my code.

lapis plaza
#

check your CPU load per core

#

if the cpu can't keep up, it will slow down the physics

young rapids
#

How do you check per core?

lapis plaza
#

just open windows task manager etc

young rapids
#

Overall it's 12% use max

timid dove
#

What's your timeScale set to

young rapids
#

1