#⚛️┃physics

1 messages · Page 62 of 1

stuck bay
#

I'll try to figure out my shit tho

#

it really fuck me up that a simple issue as that is making me reconsider my 7 years of unity devs

outer bone
#

Yeah I read that Adri2, and its a bit too above my paygrade.

stuck bay
#

and the fact that I know what it is coming from is really infuriating

outer bone
#

I got about 8 years of unity experience, and about 6 months with physics ugggh

stuck bay
#

??

#

what is above your paygrade.

#

?*

outer bone
#

The problem you posted 😄

stuck bay
#

oh

distant coyote
#

@stuck bay just watched ur clip. looks physically accurate to me ❤️

stuck bay
#

well I know why does this occurs, I just can't solve it

#

that heart really blows a fuse in my brain lmao

distant coyote
#

but srsly, is the human human-sized?

#

(2m-ish)

stuck bay
#

you mean unity scale related?

distant coyote
#

worldscale, yea

#

dont care what Transform says

stuck bay
#

it's 1, 1, 1

distant coyote
#

if you spawn a default capsule next to it, is it about the same?

stuck bay
#

so I assume it is?

#

I'll see that

#

okay maybe a bit more

distant coyote
#

maybe a bit 3x 😛

stuck bay
#

yeah 😆

distant coyote
#

surprised laddy isn't blue and rockin a tail.

#

anyway, whats the collider setup on the character?

outer bone
#

Thanks again guys, and good luck, imma get going!

stuck bay
#

you welcome partner

#

@distant coyote I'll show you something

distant coyote
#

is that a threat? 😛

stuck bay
#

lmao if you think my d is too... okay I'll stop there ah ah

#

no seriously look

half narwhal
#

trying to eject some shells from my gun, and give them some rotation when they instantiate, but i can't seem to get them to rotate very fast at all

stuck bay
#

if I use my slowmotion addon, it works fine

distant coyote
#

@half narwhal there is a default "Maximum angular velocity"

half narwhal
#

rb.angularVelocity = new Vector3(0f, 800 * Mathf.PI, 0);

#

with this code they only rotate a few times a second

stuck bay
#

so my guess is that the physic doesn't have time to process all that mess, what are your thought?

distant coyote
half narwhal
#

cool

stuck bay
#

what AngryArugula said

half narwhal
#

thanks!

stuck bay
#

I edited the link, might be better!

distant coyote
#

@stuck bay if you decrease your Time.timeScale and Time.fixedTimeStep stay proportional, you will inevitably end up with more steps per second.

stuck bay
#

that's what I understood, thought I want my player not to be forced to use the slowmotion addon

#

but I feel like I'd have to

distant coyote
#

yea so OnCollision just drop your FixedTimeStep to a very, very small number

#

if you dont want to do slowmotion

#

you might also have to set Maximum Fixed TimeStep

#

to prevent it from just charging ahead

stuck bay
#

but wouldn't that act as a "lag"? when you modify the fixedTimeStep you also have to change the time scale now don't you?

distant coyote
#

nope

#

fixedTimeStep respects timeScale

stuck bay
#

ah so the other way around create those "lags"?

distant coyote
#

so if your timeScale is 1, and your fixedTimeStep is 0.01, you get 100 steps per second

#

if your timeScale is 0.1, and your fixedTimeStep is 0.01

#

you get 10 steps per second

stuck bay
#

oooh that makes sense!

distant coyote
#

similarly, you can also set your Rigidbody's mode to Interpolated, instead of "None"

#

that only effects the Transform, not the Rigidbody

stuck bay
#

well.. I'm too tired to keep coding right now so I'll have to do that tomorrow! may I ping you tomorrow then?

#

mmmmh, okay I can try that quickly

distant coyote
#

if your physics sim explodes, Interpolated wont help you

#

it sjust to smooth out hitches/framerate differences between physics and display

stuck bay
#

aaah alright!

#

okay I'll give it a shot tomorrow, I'd love to try and do the fixedTimeStep right now, but it would interfere with my current workflow, and I don't wanna mess it all up! well thanks!

distant coyote
#

and sure; ping whenever 🙂

stuck bay
#

great! 😋

#

I'll show you the end result tomorrow then! Have a good night, or good day depending on where you are!

proven sequoia
#

as it is detecting the input

stuck bay
#

@distant coyote Dude marry me! I was struggling for 2 days straight with that issue and lowering the Time.fixedDeltaTime definetly fixed my issue!! thank you soooo much!

thick jetty
#

Hey, so I have started making a procedural spider myself using unity and everything is done, except the rotating the body based on the height differences of the legs
I kinda don't get the math i guess and have been struggling to get this for a few days now. Could someone please explain me how can I achieve the rotation of the body based on terrain irregularities that effect its IK Legs?? i have referred this video https://www.youtube.com/watch?v=e6Gjhr1IP6w

I tried to explain procedural animation in 10 steps.
Check out my twitter: https://twitter.com/CodeerDev

▶ Play video
frigid pier
#

@thick jetty Don't cross-post

stuck bay
#

@frigid pier ??

#

@thick jetty it happens that I followed this tutorial myself, you should normally not have an issue with the rotation of your body since the legs move back to the transform you assigned when there is too much difference between this transform and the tip of the leg, could you please show a video of your issue?

frigid pier
#

@stuck bay Don't tag people out of conversation.

stuck bay
#

How did he cross post?

frigid pier
#

You do know how search feature works?

stuck bay
#

In the most recent messages he didn't cross post, so not relevant

frigid pier
#

Also how time stamps work

stuck bay
#

Yes I do but look my previous message

frigid pier
stuck bay
#

Okay I see you are having a bad day let's leave it here alright.

frigid pier
#

!mute 362993911255400448 1h

flint portalBOT
#

dynoSuccess Adri2#5277 was muted

karmic sedge
#

hy guys i have a question, i have applied inverse kinematics to my spider so i can move the leg to the target

#

but how would i find the next point where i have to place the leg?

#

using this tutorial

lofty dew
#

hey guys im working on a project with a mech that can turn around the turret so the turret and the base can be rotated independently, my problem is that when im shooting is shooting right but as soon as im turning around with the base of the mach it starts to shoot for the base directon aswell,
so basicly it shoots the direction where the mech base is looking, how can i sole the problem ? any idea?

lofty dew
#

can some one help me please?

iron wing
#

Hey everyone I wondered if there was a possible way to avoid this problem while rotating a character instantly ^^'

timid dove
#

what's the problem?

#

what are you expecting?

iron wing
#

well hum, he is kinda stuck inside the wall

#

He clips through the colliders and I'd like to avoid that

#

(Only when I rotate him)

timid dove
#

is it a Rigidbody2d?

iron wing
#

yup

timid dove
#

use MoveRotation instead of setting the transform rotation

iron wing
iron wing
timid dove
#

yes

iron wing
#

Alright thanks ^^

#

Uh wait

timid dove
#

?

iron wing
#

this method is to make him rotate at a certain speed

#

but I can't make him go to a specified angle

iron wing
#

I did

timid dove
#

Rotates the Rigidbody to angle (given in degrees).

#

that's all it does

#

no speed involved

#

you just give it an angle

#

it iwll collide with stuff as it rotates - are you trying to avoid that?

iron wing
lofty dew
#

this is the bullet script

fiery marsh
#

Quick noob question

#

I have a player with rigidbody and box collider and a trigger object with box collider, but the trigger is still solid?

fiery marsh
#

Might be worth mentioning that the trigger is child of an object with rigidbody, would that inherit?

sour bone
#

Hi, guys, I have this OverlapSphere call and I was wondering if I can somehow configure the radius visually through the inspector. For example, sphere colliders can be visually edited in the inspector, is there a chance for me to edit a radius used for OverlapSphere from the inspector?

lofty dew
sour bone
#

Nope

fallow loom
sour bone
#

Krisztian already answered for me in a private message, because he couldn't post the answer here for some reason.

fallow loom
#

i can give a better answer

#

it is very gut

#

dm me

sour bone
#

Can't you just paste it here?

fallow loom
#

no dm pls

sour bone
#

Okay, dm me then.

fallow loom
#

u do i am busy

#

pls

#

pls

fallow loom
#

i love physics

#

@zinc plume

sour bone
#

<@&502884371011731486> Is it a normal practice to give help and code over DMs? Sounds weird.

frigid pier
#

Yes, if you both agree on the conversation. But it's not the purpose of the server. Others are learning on public answers.

storm fractal
#

is it possible to apply -currentForce from a joint in order to nullify it?

#

ive tried doing it in FixedUpdate using AddForceAtPosition but its behaving weirdly

frigid pier
storm fractal
#

that wont do it for me

#

i need to get rid of the joint force and add my own force immediately

median rampart
#

hey i'm using transform.translate for running and rigidbody physics for grapple hook swinging

#

but they seem to be conflicting

#

if I run after swinging it seems like it saves the physics up until I'm done transform.translating and then does it all at once

supple sparrow
#

I never mess with rigidbodies and transforms at the same time. Not sure that's a good idea.

#

you could eventually add to the rb.velocity

median rampart
#

when I said I had a really physics based game and asked if I should implement run with rigidbody a bunch of people told me to use transform.translate lol

supple sparrow
#

or try with rigidbody.moveposition

median rampart
#

i'll do that

supple sparrow
#

Maybe they meant to use your own physics system and dont trust physX, a lot of people hate it

#

I reckon it can be hard to tweak sometimes

median rampart
#

ok that's not working either

#

now the player doesn't run, but sometimes teleports when you hit the run button

#

is there a way to cancel rigidbody motion?

#

like if my player starts walking just tell the rb to stop all motion

supple sparrow
#

should be done inside FixedUpdate()

#

Try to set rb.velocity to vector3.zero

#

or multiply it by a fraction of itself to "brake", like *= 0.1f maybe 🤷‍♂️ try some things, see how it behaves

#

I never tried AoT gameplay, sounds fun 👍

median rampart
#

I'll post a link to my website once I get an alpha version up and running

#

new problem tho

#

now I need to be able to tell when I'm swinging and when I'm standing on something

#

I tried using oncollisionenter, but that applies when I hit the sides of walls too

supple sparrow
#

you could watch some platformers tutorials, get ideas how they handle isGrounded state and such

unique oak
#

Hello, I have a question. As collisions can only take place if there is a rigidbody attached. How come that my wheels go through the object? There is a rigidbody attached, and a collider

#

and its still passing through objects

#

Truly baffling,

foggy rapids
#

what is the collision mode set to?

proud trellis
leaden jay
#

@unique oak
Is the car is moving really fast, in which case the collision detection is not fast enough¿ (use continuous)

Or, did you move the car by updating the transform of the object¿ (Use rigidbody forces)

fiery cedar
#

I don't know how to make it more performant. would adding a RB to the objects on Contact be better?

leaden jay
#

@fiery cedar
Er. Perhaps GPU instancing for those same colored blocks?

Seems like a lot of the performance hit was rendering since it occured right as you looked in that direction.

fiery cedar
#

@leaden jay Unfortunately, the material on the cubes are greyed out, They're auto generated

#

I don;t know how to access them to turn that on

#

I don't know how i can see why rendering is taking a massive chunk

halcyon cipher
#

Does anyone here use the VR Interaction Framework and can assist me with a hinge?

#

I have this hinge, and no matter what I do, it only opens a little and then slams shut

fallow loom
#

hi

halcyon cipher
#

how do i stop my drawer models from all being stuck open??

idle crescent
#

Has anyone else had problems with the hinge joint? Its incredibly unresponsive and I really cant figure out the issue. It will move very slowly when the game starts, and will rarely respond to the player touching it (which sends it flying)

proud condor
#

It seems unity can't solve OnTriggerEnter if the trigger object is created later?

charred ocean
#

The capsule colliders attached to my CharacterController components will often get stuck on one another. How do I avoid this?

foggy rapids
charred ocean
#

In a similar vein, they will hang onto ledges by just the very edge of the capsule collider, like someone holding up their own weight with only their toes

timid dove
#

Well - CharacterControllers aren't "real" physics

#

if you want more realistic physics, use a Rigidbody

#

And be cognizant of PhysicMaterials on your colliders

#

that's what determines friction and bounciness of everything

charred ocean
# timid dove And be cognizant of PhysicMaterials on your colliders

Ahh, good point. I haven't dabbled in physics materials at all, I'll look into that. I'll also give some thought to using rigidbodies but all my NPCs and code currently use CharacterControllers because I have my own code for more arcadey movement that uses the CharacterController.Move function

distant coyote
#

so you end up with somethin that looks like this

stuck bay
#

why collisions work so bad in my game

#

i get knocked out

#

for 10 meters

#

with huge force

#

whenever i step on item

#

is it because theres custom gravity applied to the item with AddForce?

#

and it influences the player when he steps on it

#

if yes, then is there a way to make that force work only as gravity and not push other objects? (eg not push player)

foggy rapids
#

physx uses force to move everything. That means when there is a collision it will use the physics materials to apply the correct amount of force. Sometimes this gets out of hand with large forces. Especially when something is moved into a collision without force.

stuck bay
#

ahh i use both raycast and

#

force

#

on player

stuck bay
#

How do i stop pick ups from pushing player? I have 3d object drop onto ground and when player is close they fly at the player and when collide they pick up but when the collide they push player (I don't want that) if i make collider a trigger it falls though the floor 😦 idk how to fix

foggy rapids
#

you can use collision layers (project settings) to ensure it collides with the ground and not the player. then you can use a simple raycast or overlap to determine when it hit the player

split lily
#

Does anyone know if particle colliders are precise enough to use for game logic? Right now I raycast and emit a fast moving particle with collision quality set to high, I'm wondering I can safely consolidate this and not have to worry about the particle collision not registering

naive gorge
#

So when I zoom in on two objects I have colliding, I notice their colliders arent seperated by somewhere around 1/6th a unit. Whats the max distance they can be apart and still collide?

distant coyote
#

@naive gorge configured in project settings

#

@split lily if you're moving objects fast enough that you're concerned about missing collisions, use raycast.

split lily
#

Thanks!

naive gorge
#

@distant coyote Thank you so much!

distant coyote
#

👍

raven solstice
#

Anyone know why when I instantiate a shattered object it blows up? I'm not adding force to it, but if I add it to the scene as a normal object it crumbles as I'd expect when I hit play.

timid dove
#

not sure why that would be different with Instantiate vs having it in the scene at the start

raven solstice
#

Yeah, I thought that too, but the prefab working properly when I just put it into a scene made me think that its not a collider thing.

#

I posted on the Unity forums with some video/code, hoping someone can see whats going on. 😄

#

Followed Brackeys shatter tutorial and didn't get the same results, definitely weird.

timid dove
#

Maybe try disabling the colliders and instantiating it like that?

#

Just to see if it's a collider thing

#

if they still explode it's not a collider thing

raven solstice
#

I've tried setting them to kinematic and after I instantiate the prefab setting then back off, still blows up.

#

Will give that a shot.

timid dove
#

The other possibility is maybe that if it's in the scene at the start, the rigidbodies are asleep at the start?

raven solstice
#

I haven't tried the entire collider on each shard yet.

timid dove
#

and when you instantiate, they start awake?

#

🤔

raven solstice
#

Yeah

#

Just tried with disabled colliders, I instantiate them, then loop and re-enable all colliders and it still blows up. lol

timid dove
#

but I'm not sure how dynamic you need things to be

#

that will make the object break the same way every time and you won't be able to interact with the pieces

#

but maybe that's OK for your use case

raven solstice
#

Just trying to setup a rock in game that when a player mines it, it shatters and just crumbles to the ground. Wouldn't have thought it would be this complicated, but always something!

timid dove
#

Two more options to look at:

  • have the "shattered" rock be a child of the actual rock, but disabled. When the actual rock is destroyed, enable the shattered rock and hide the real one. Maybe that will work since technically it is in the scene at the start rathre than being instantiated?
  • assign PhysicMaterials to the colliders on the shards with low or zero bounciness
raven solstice
#

The shattered pieces have no bounciness, and dynamic and static friction of 0.1, so they slide pretty well by default. I'll try the child one, thats not a bad idea, then I get around the instantiation explosion.

#

Think I found it, and it doesn't make sense but whatever.

#

So I'm destroying the rock, then instantiating a new prefab shattered rock at the same position and rotation.

#

Apparently the collider for the original rock is still there for a frame, so the new rock collides and blows up.

#

So I just disabled the collider on the original rock, then destroy it, then instantiate the new one and it works fine. Talk about weird frame timing.

#

Or if I call the shatter in update instead of fixedupdate I don't have to disable the collider.

timid dove
#

It kinda just gets "scheduled" for destruction

unkempt summit
#

Just to confirm, unity is "mostly" deterministic on other hardware right? So my networked rigidbodies should stay in sync for a good while on all clients assuming no packet loss?

timid dove
#

I don't think there are any guarantees of that

#

Floating point calculations are notoriously performed at different levels of precision on different hardware. That would be the point of the "syncing" bit - to reign in error over time.

sly violet
#

Today I learned: Unity's Rigidbody2d.AddTorque is in Radians. Angular velocity is in degrees. I'm like WTF is this factor of 57.29578, but it turns out that's just the conversion ratio between degrees and radians.

#

Unrelated question: Is there any difference between using force mode force of x versus using force mode impulse of x times delta time?

frigid pier
halcyon cipher
#

Weird physics question here. I have a model I made in Maya. It has a box collider and rigidbody. and when I go into play mode it falls through the floor. It's on the same layer as the floor and both layers are set to collide. It's not kinematic.

If I start the object at an angle, it will fall to the floor and lay there. If I then pick it up and drop it again from a flat angle, it will fall through the floor again.

#

These things don't happen on other similar objects.

sly violet
#

Both the object and the floor are very thin and you're doing no interpolation, so it might be just skipping it entirely in a single frame. That would also explain why it collides when it's not straight.

#

Recommendation: Thicken the floor! If that's not feasible, you'll probably need to turn on interpolation.

halcyon cipher
#

I turned on interpolation and I get the same result.

vernal spindle
#

I have a small ball and a large box.
Both of them are rigidbodies.
Whenever the ball lands on the box, it goes through.
Is there a collision detection mode thing going on?

halcyon cipher
#

@sly violet I turned interpolation on AND thickened the floor. It no longer goes through the floor, but it goes through furniture and literally anything else

#

I also made the object's collider a little bigger

#

Collider is twice the thickness of the object, still goes through the furntiure

supple sparrow
#

Try Collision detection to "continuous" ?

halcyon cipher
#

I can do that, but that's going to really hurt performance since I have multiple of these objects and I'm building for VR.

#

that's also why I don't want to make the object's collider much bigger, or it will be noticeable to the player

supple sparrow
#

yeah your memory card is not really supposed to move that much anyway I guess

sly violet
#

...I don't know why I wrote interpolate when I meant continuous up above....

#

How many objects are we talking?

halcyon cipher
#

maybe 7 or 8 at at time

sly violet
#

That shouldn't be a problem even on a low power device.

supple sparrow
#

@halcyon cipher When you export from your 3d program, are you used to click some kind of reset transform and normals and such ? maybe normals are inside out ?

#

oh nvm is a box collider from unity

halcyon cipher
#

Yes, I disabled the colliders that exported with the object.

supple sparrow
#

that box collider is so tiny though 🤔

stuck yarrow
#

transform.up = Vector3.Lerp(transform.up, gravityUp, rotationSpeed * Time.fixedDeltaTime);
I am using this function of Vector3 and I am wondering if there is a way of doing this without affecting the local Y rotation of the transform? I am quite new to Unity so any help would be appreciated

supple sparrow
#

@halcyon cipher box collider with 1 unit scale each axis falls through the floor too ?

#

(jsut to test)

halcyon cipher
#

No, no other objects have this issue

supple sparrow
#

alright maybe the size then. Sorry never used objects that small, I think I can't help

halcyon cipher
supple sparrow
#

🤷‍♂️ I'll let someone else help you

vernal spindle
#

mass related?

halcyon cipher
#

mass isn't making much of a difference

#

Tried putting the box collider on the parent. No difference

vernal spindle
#

try making an entirely new collider of the same size and shape

halcyon cipher
#

@vernal spindle Just did that. It fell through my 1-unit-thick floor

vernal spindle
#

narrowed it down a bit I guess

halcyon cipher
#

oop wait

#

added rigidbody but not collider. derp. 2 secs

#

ok. similarly-sized brand-new collider has the same behavior 1-unit-thick floor stops it, but .5-unit-thick table does not

vernal spindle
#

¯_(ツ)_/¯

#

what's the best collision detection mode for a rigidbody player

supple sparrow
#

continuous

#

and raycasts

#

even collider casts if need be 😛

vernal spindle
#

spherecasts; player's a sphere

supple sparrow
#

check manual, it will explain better than me

vernal spindle
#

not particularly

halcyon cipher
#

OK, found the issue! Looks like mesh collider on the table in question wasn't working well. Replaced it with a compound box collider and everything is fine

distant coyote
#

(if anyone encounters this again, increase your Substep count until it stops)

sly violet
#

Heh. That'll work, but I use it as a last resort, because usually there's another less expensive way to do it.

sly violet
sly violet
distant coyote
#

@sly violet the only difference between Impulse and VelocityChange is that the former respects mass

#

they both have a cumulative effect on velocity

distant coyote
#

additionally unless you have several hundred dynamic objects rolling around at the same time, 12-20 substeps is fine

#

(even on mid-range modern smartphones)

quick gyro
#

i have a 2d rigid character and he bugs into tiles when touching them from the side

#

how can i fix this

#

its only if force is applied. So while walking into it from the side the player bugs

distant coral
#

Hi guys, i'm using this code to prevent player rigidbody to slide when WASD isn't being held; the problem is that it just works in one direction (when player rotation is 0 0 0), when i try to face in another direction and move my character just gets yeeted out of existence

edgy aurora
#

How can i move a rigidbody using add force without acceleration

#
    void FixedUpdate() 
    {
        Vector3 Move = Vector3.forward * Input.GetAxisRaw("Vertical") + Vector3.right * Input.GetAxisRaw("Horizontal");

        Physics.gravity = Vector3.up * Gravity;

        float ModifiedMoveSpeed = Acceleration;

        if (new Vector2(RB.velocity.x, RB.velocity.z).magnitude >= MoveSpeed)
            RB.AddForce(new Vector3(RB.velocity.x, 0, RB.velocity.z));

        if (new Vector2(RB.velocity.x, RB.velocity.z).magnitude > 0 && Move.magnitude < 0.01f)
            CC.material = Friction;
        else 
            CC.material = NoFriction;

        RB.AddForce(Move * ModifiedMoveSpeed, ForceMode.Acceleration);
    }
#

i tried setting modified speed to 0 when the player is moving too fast but that then i cannot change movement directions when im already traveling in one direction at full speed

warped fable
normal holly
#

maybe the collider isnt right sizes

warped fable
#

My problem is not that my character enters the shrine of the wall or ... My problem is the jump that happens when I hit the wall. For example . Suppose we go to the wall with the D button. This jump happens if our character hits the wall and we still hold the D button. Of course, I think this problem will be solved if I do something that disables the motion code when it hits the wall. :)

#

But if there is any other way but to use the code, tell me. Thankful :)

stuck bay
#

I have raycast collision problem.

I changed my character controller to use raycast instead of force to stick to ground. This proved to be better at really huge distances from world center (eg 40000 meters) some of you may know that your game physics and other factors start to break after 10000meters+/- mark. due to floating point error precision.

so raycast solves that issue very well (at least with movement and sticking player to planet)

but in return it messes upp all my collisions completely (i **think ** raycast is the culprit, but dont know for sure)

for example it pushes objects when i dont want it to
or it gets pushed by them very far

what would you guys do?

timid dove
#

ALso raycast suffers the same problems far away from the origin that everything else does. You should really look into floating origin systems if you have a world that is more than ~1000 meters square

stuck bay
#

i mean sticking to raycasthit.point does better job than addforce

#

far from world center

#

by sticking i mean eg rigidbody.moveposition

timid dove
#

Wait so you're using both CharacterController and Rigidbody on your character?

stuck bay
#

im not using controller i just called my script that

timid dove
#

oh

#

ok that confused me a lot

#

yeah if oyu MovePosition your Rigidbody to the raycast hit point, it's going to immediately cause a collision

#

and the physics engine is going to try to remedy that with more forces

#

maybe MovePosition to a position slightly offset from the raycast hit point?

#

like ray.GetPoint(hit.distance - .01f)

stuck bay
#

it will still cause collision if it hits anything

#

also im pushing objects that are set to isKinematic

timid dove
stuck bay
#

im using MoveRigidbody

timid dove
#

oh oh

stuck bay
#

is it bad?

timid dove
#

the thing you are moving is Kinematic

#

yeah that works

#

that's fine

stuck bay
#

whats fine

timid dove
#

I thought oyu meant you bumped into a kinematic object and the kinematic object moved

stuck bay
#

i mean if MoveRigidbody casues this issue

#

i walked into it

#

with MovRigidbody

#

and it moved

timid dove
#

the thing you walked into is not kinemetic right?

stuck bay
#

it is kinematic

timid dove
#

🤔

#

kinematic objects aren't supposed to move unless you explicitly move them with MovePosition

#

something is weird

stuck bay
#
        rigidbody.rotation = rotationStep;
        rigidbody.velocity += (planet.velocity - rigidbody.velocity).normalized * Time.fixedDeltaTime;
        rigidbody.MovePosition(positionStep);
#

thats my movement script

timid dove
#

it's unusual to both set velocity and use MovePosition

#

usually you do one or the other

#

also unusual to multiply the velocity by Time.fixedDeltaTime

stuck bay
#

why

timid dove
#

because velocity is already expressed as "units per second"

#

and makes the object move at a uniform, framerate-independent speed

stuck bay
#

but it makes things smooth

timid dove
#

multiplying by Time.fixedDeltaTime just makes your velocity a lot smaller

stuck bay
#

i see

#

i can remove that then

#

but its unrelated to the issue

timid dove
#

it does not. It's basically equivalent to doing this:
rigidbody.velocity += (planet.velocity - rigidbody.velocity).normalized * .02f;

stuck bay
#

the time multipleir thing

timid dove
#

but yeah setting the velocity means it will move automatically again after the movePosition happens

#

because... it now has velocity

#

the physics engine automatically moves objects that have velocity

#

(unless this object is kinematic)

stuck bay
#

ok ok

#

but i still can push

#

kinematic

#

things

#

btw do you add time fixed delta time multiplication to MovePosition?

timid dove
#

definitely not

#

MovePosition takes a position as its input parameter

#

If you scale that position... well your object is not going to go where you want it to go

faint sable
#

I have a question regarding Raycast collision detection.

#

I'm following along with a tutorial, and it uses Raycast to detect a collision with a tagged object, but I can't get it to work without toggling "Is Trigger" on the object, at which point it falls through the floor. I feel like I am missing something fundamental, can anyone offer some insight?

timid dove
#

🤔 That shouldn't make a difference. If anything, sometimes raycasts don't hit triggers

#

In order for the raycast to work you just need the following:

  • An activated GameObject with an enabled Collider
  • That gameobject should not be on the IgnoreRaycast layer
  • That gmaeobject's layer should be included in the LayerMask you used with the raycast (if you used a mask)
#
  • The ray needs to physically intersect the collider
faint sable
#

Game object is active, set to 'Default' layer, collider is enabled, and I haven't started using masks yet

timid dove
#

ok it should work then. Next step is debugging

#

first, why do you think it's not working?

faint sable
#

I honestly can't figure out why, it works when "Is Trigger" is ticked, but then the object falls through the floor

timid dove
#

gotcha - what I mean is

faint sable
#

been googling for the better part of an hour

timid dove
#

why do you say it's not working

#

what isn't happening

#

that you are expecting to happen

faint sable
#

gotcha

#

Player object is suppose to bounce off the top of the enemy object

timid dove
#

Ok what does your code look like?

faint sable
#

hmm, not sure how to show it

timid dove
#

save it there, copy the link here

faint sable
#

thats the code I was given

timid dove
#

Ok so first thing to do would be to put a line Debug.Log("Hello!"); right after the raycast

#

just to make sure your code is actually running

#

You could also log the actual hit distance and the tag of the hit object:
Debug.Log($"Distance: {hit.distance} tag: {hit.collider.tag}");

#

(by the way are you getting any errors in your console?

faint sable
#

nope

#

Well I added those Debugs and now it works

timid dove
#

lol.

#

🤔

faint sable
#

Wasn't the debugs, was the detect distance, my scale must be different from the tutorial

#

but it works now, thank you for your help

coral eagle
#

if im using raycasts for player collisions for a player controller script, should physics sit inside fixedupdate? i have both input & collision detection in update right now (no rigidbodies)

supple sparrow
#

Do your raycasts in Update()

coral eagle
#

i do

supple sparrow
#

so I guess I misunderstood the question

#

should physics sit inside fixedupdate?
You mean AddForce and such ? yes in FixedUpdate. Everything else can go in Update

coral eagle
#

No rigidbodies at all, all custom physics

glacial jolt
# coral eagle No rigidbodies at all, all custom physics

there isn't necessarily a right answer to this. If you run your game logic (including physics) in Update, how your game behaves will depend on the framerate the player is running it at. Multiplying things by deltaTime ensures that objects move at a roughly constant speed, but does not mean the game behaves identically at different framerates.

Having all your logic in a fixed timestep ensures that your game will run the same regardless of the framerate. This is especially necessary for networked games

coral eagle
#

Gotcha, thanks for the details!

dull finch
#

may i ask if unity uses the left or the right handed rule for things like joint.current.torque?

#

im not sure if im phrasing the question correctly

void snow
#

Hi all,

Is there a way to get all collisions in a scene? (instead of handling every individual collision in OnCollisionEnter, etc callbacks) As I understand it the physics engine calculates all collisions, and then calls these callbacks. Is there a way to get them at that stage?

I'm following an ECS approach for some things in my game through DOTS/entities but I'm trying to avoid the actual dots phsyics/rendering stuff as it's not stable yet. So I do want to process all collisions in one batch, but I don't want to rely on DOTS/physics.

From what I've googled it doesn't really seem possible with the regular phsyics engine? That would kind of surprise me.

west forge
#

@void snow if I'm reading your question right, it sounds like what you're looking for is something like Physics.Overlap<collider type>?

void snow
#

No, not exactly. I'm (currently) not interested in adding custom collision detection logic, in which case Physics.Overlap... would of course be handy. I'll try to rephrase: Currently the physics system works by taking all colliders/rigidbodies in the scene, doing some work to detect collisions, and then for each collision it will call certain callback methods (event handlers) on the game object scripts (OnCollisionEnter and friends). I'm interested in all detected collisions (the step right before the event handlers are called) so I can process them in batch (let's say in a 'data oriented way') instead of handling every collision in separate event handlers (let's say an 'object oriented way').

It is not clear to me, however, if it is even possible to get a hold of all collisions at once. Possibly this is not even exposed by the physics system? I know that DOTS/physics does enable this but I'm not comfortable switching to such experimental tech right now.

west forge
#

yeah that sounds like something that's not exposed to you, unfortunately.

#

hopefully someone who's more familiar with unity's physics system can help a bit more!

void snow
#

Alright, thanks. It really would be too bad if it isn't :(.

timid dove
#

Only way to do that is putting a script on a common rigidbody parent of the colliders(which means they're the same physical entity) or switching to ECS I think

visual furnace
#

Hey Guys

#

Need Help on how to do this
I want to get the position of where two objects moving towards each other at different speed will meet.

timid dove
visual furnace
#

Thanks @timid dove

timid dove
#

There's a formula in that quora answer you should be able to apply

visual furnace
#

so I guess to Simplify it is

meetingPoint = (speed1 * distanceFromEachOther) / (speed1 + speed2)

misty acorn
#

Hi guys. Sorry for spamming this question but I really need to understand this.

How do circle collidors work in Unity? Are they just simple formulas that check the distance against every other collidor on the same layer in the scene? Or does Unity implement some form of optimised function that ignores collidors that are very far away?

#

Sorry again 😓

timid dove
#

They use an optimized data structure involving AABB's (axis aligned bounding boxes) so they only need to check colliders that are nearby each other against each other

stuck bay
#

is there a way to make an object go up slowly almost as if it was in slow motion

edgy aurora
#

Why is my character sticking to the moving platform some times

#

im using a trigger collider and setting the parent of the player to the platform

frigid pier
#

@edgy aurora As was mentioned don't cross-post in other channels to redirect. If your question doesn't get attention you may want to consider adding more information meanwhile.
You have to examine what's happening, experiment. If the object is physics enabled, then parenting does nothing to the simulation unless it was deactivated by setting it to kinematic. Default materials also have some friction.

bitter totem
#

does anyone know anything about composite colliders

glacial jolt
bitter totem
#

how they work

#

and how to set it up

glacial jolt
#

any collider that is a child of a game object with a rigidbody is treated as part of that rigidbody's collision

bitter totem
#

thats it?

#

wow thats very useful

#

but does it need to have a collider tho?

#

or does it just do the outline?

#

bcs i need like an outline

#

collider

glacial jolt
#

not sure what you mean by "outline"

bitter totem
#

like i have a randomly generated dungeon

#

and i want to add collision

#

but cant

#

because its random

glacial jolt
#

if you are trying to add collision to static objects, you do not need rigidbodies

bitter totem
#

no i dont have a problem with that

timid dove
#

Just put box colliders on your wall prefabs

#

etc.

bitter totem
#

but there is corridors

timid dove
#

wahtever you're randomly spawning

bitter totem
#

it can block the way for the corridors

timid dove
#

corridors have walls

#

why would it block the way? You don't generate random colldiers

#

you generate random walls right

bitter totem
#

but then what about the room?

#

they override

#

which i dont want

timid dove
#

not sure what that means

#

how are you genrating your map

bitter totem
#

using a script

timid dove
#

you have some prefabs of map pieces which you place together randomly right?

bitter totem
timid dove
#

what are the rooms and corridors?

#

THey're not prefabs?

bitter totem
#

prefabs

#

ofc

timid dove
#

right

#

so

#

on those prefabs

#

put colliders

#

that make sense

#

that's all there is to it

bitter totem
#

u dont understand

timid dove
#

I don't

bitter totem
#

if i put colliders on the room

#

and spawn it

timid dove
#

mhmm

bitter totem
#

with the corridors

#

it will block the path

timid dove
#

why

#

you don't put collider on the doorway

#

if you have a room

#

with 4 walls

#

and a doorway

#

you use 5 colliders

#

3 for the full walls

#

2 for the wall with a doorway

#

and a gap in the doorway

bitter totem
#

i didnt understand :(

#

imma try figuring it out by myself

supple sparrow
#

🤷‍♂️

timid dove
#

heres your room

#

black are the walls

#

blue are the box colliders

bitter totem
#

thats the problem

#

i dont have a seperate prefab for each type of room

#

i just have 1 room prefab

timid dove
#

ok

bitter totem
#

and a corrridor one

timid dove
#

how does it do doorways

bitter totem
#

i dont have doorways

#

instead they are corridors

timid dove
#

ok now I'm confused

bitter totem
#

like the one in sould knight

timid dove
#

how does a corridor go into a room

bitter totem
#

or the game that dani made in 2 days

timid dove
#

or vice versa

#

without doorway

bitter totem
#

that are connected using corridors

timid dove
#

maybe show a picture

#

because I'm 100% confused

bitter totem
#

so u can walk into different rooms

#

one moment

timid dove
#

if there are certain places in the room that can randomly have a corridor attached, you just put box colliders on each of those in the room prefab, and if a corridor is there, you destroy or disable that collider in your script.

bitter totem
timid dove
#

right ok so

#

4 colliders

#

one for each wall

#

and if a corridor is there

#

you just disable or destroy the one on that wall

#

in the map generation script

bitter totem
#

im trying to do that rn

#

maybe i shouldnt have gone for a confusing design

#

should have done the one in binding of isaac

supple sparrow
#

it's not a confusing design, looks ok

#

Like Praetor said, you just need to disable a collider when you know where your corridors attach themselves to the room

#

can be only 4 possible values: left, right, top, bottom

#

you prob handle that visually too

#

like you carve a hole in the wall

#

Or replace if it's easier for you to imagine

hot edge
#

I have a ragdoll. I want it to follow the mouse around, but flail around a bit as you pull it. I tried using rigidbody.movePosition, and a fixed join attached to an object following the mouse. (attached to the root) Both of them the ragdoll just falls down instead of staying where the mouse is. It does follow left/right.

hot edge
#

Removing gravity helped, but the position still isn't 1:1 with the mouse.

glacial jolt
#

@hot edge are you able to visualize the fixed joint (sphere mesh or something) to ensure it is over the mouse cursor?

hot edge
#

I put on a sphere. It's matching the mouse position. It seems like the ragdoll just can't move fast enough to keep up, and if I move too fast the body pulls apart until it slows down again.

#

I feel like I had this working like six years ago, and can't remember the secret.

#

Part of the problem was the anchor wasn't lined up with the root. But now that they're lined up it causes insane spinning.

#

I'm going to try making a build to show how crazy it looks and for a fun record of the bug.

hot edge
glacial jolt
#

if you're just looking to capture footage of the error, you can use OBS with the editor

hot edge
#

Thanks, never used OBS before. Great resource.

proud edge
#

Does anyone by any chance know how to edit the physics of an individual tile on a tilemap? I have tried using the Custom Physics Shape on the sprite sheet, but that hasn't seemed to change anything. I am trying to edit the physics collider of these walls so you stop at the actual wall.

glacial jolt
#

yea looks like it might be having trouble satisfying the constraint of the fixed joint at the same time as satisfying the joints of the ragdoll. Try it with just a single rigidbody as the "ragdoll"

hot edge
#

They think it violates the ToS

#

Yeah, it's the two fighting. Damn. I swear I had this working perfectly years ago.

#

If I try moving the root directly with moveposition 1.) it spins like crazy 2.) The limbs don't respond at all to the movement.

glacial jolt
hot edge
#

That looks perfect, yes.

glacial jolt
#

note that I am just moving it in the editor, so you should be able to achieve the same

#

(moving the transform in editor is the same as setting transform.position)

hot edge
#

My ragdoll just won't move like that, if it goes above a certain speed it disconnects. It's almost like the parts have a high drag on them or their max speed is limited. They don't stick together like yours does.

#

Is that using the ragdoll wizard/character joints?

#

Also, thanks for all the help. I appreciate it.

glacial jolt
#

by disconnects, you mean breaks apart permanently? Or they all stretch apart briefly?

hot edge
#

Stretch apart. They move very slowly too, they don't move as fluidly as yours.

glacial jolt
#

and yea, using character joints

#

is Projection enabled on each joint? That will keep them together

#

you could also increase the mass of the ragdoll, I tend to use a fairly heavy ragdoll to keep it more stable

hot edge
#

yes, on all joints.

#

I'll give that a try.

glacial jolt
#

(total mass on the one above is 8)

hot edge
#

I did the default, total mass 20

#

So maybe it's too high.

#

I tired with 8 and 200 and neither helped. So weird.

glacial jolt
#

are you moving the transfrom via the editor, as my example above?

hot edge
#

I just tried that, with the head, and even that doesn't work for me at all. It's actually worse.

glacial jolt
#

hmm

hot edge
#

It went flying off like it was being pulled by the body away from where I was holding it.

#

I just don't get why the rest of the body is moving so slowly.

glacial jolt
#

I'd recommend trying to isolate the problem, build a 2-joint system, see if it works, etc. In case there is something off with your specific setup

desert gull
winter sun
#

Has anyone used the GGphys asset on asset store for physics I have some questions

blissful cape
#

I'm trying to build a system that instantiates gameobjects at random raycast locations. I got that bit working, but now I'm trying to adjust it so that if an object instantiates within the collision of another object, it will try to move itself to a new location until it finds one where it isn't colliding with anything. I can't seem to get the collision bit to work though

solemn beacon
#

Hello guys, I have two rectangles (p1 and p2) of the same size. There is a point on p1, and I'd like to retrieve the relative position of this point on p2

timid dove
solemn beacon
#

they do

timid dove
#

and are xi, yi, zi expressed in local space of the rectangle or world space?

solemn beacon
#

local space

timid dove
#

but you want the world space versions of x0, y0, z0?

#

or local space?

#

if it's local, you don't have to do anything

solemn beacon
#

world space ye

#

for the out point

timid dove
#

for world space you do p2.transform.TransformPoint(in)

#

if you have in expressed in world space, then it would be Vector3 out = p2.transform.TransformPoint(p1.transform.InverseTransformPoint(in));

solemn beacon
#

it looks great, thanks

timid dove
#

👍

wicked imp
#

I manually set my angular velocity to 1,0,0 on start, but if it is on ground, it decreases to 0.285, without any drag. why would that be?

viral ginkgo
#

@wicked imp I am not sure if that angvelocity is big enough but unity will limit angular velocities on all rigidbodies by default settings

#

try setting the ang velocity to 0.2, 0, 0 and see if it changes like that imo

wicked imp
#

@viral ginkgo isn't the limit for angular velocity is 7 by default?

#

also that happens only when landed

viral ginkgo
#

if thats the case then i wouldn't know

#

i see, then its irrevelant

wicked imp
#

I set use gravity to false and let it fly on the air, angular velocity is as it should be, 1

#

but when it touches the ground, it goes back to .285

#

weird thing is that if I pull it up, and let it fall once more

#

it stays 0.285 still

viral ginkgo
#

is this a sphere?

#

not sure but maybe both surfaces need to have zero friction

wicked imp
#

yes it is a sphere

#

with zero friction, ball doesn't move though

#

I need it to move too

green dove
#

Can please someone help me out. I have a game where player falling down and need to avoid obstacles which is flying up. For some reason sometimes OnCollisionEnter just not being called despite the fact that collision did happened in the game.

#

Is it normal behaviour?

#

I already tried to change collision detection, collider types, rb kinematic and non-kinematic. Same thing each time. Sometimes OnCollisionEnter just not being called

#

My player is a ragdoll and he is flying by force of gravity. And obstacle flying by rb.moveposition but I already tried transform and velocity

solemn beacon
#

Hi, when raycasting, do I need a rigidbody or box collider or something else ?

#

It looks like my object is ignored by the raycast

viral ginkgo
#

@solemn beacon maybe raycast is hitting backfaces

#

or you are mixing up 3d and 2d physics

steel verge
#

How can I fix this issue? The Rigidbody2Des jump upwards and flip around. I have no idea why.

feral pike
#

When two rigidbocies occupy the same space, the physics engine tends to "shoot" it out of it

steel verge
#

Can I fix it somehow?

feral pike
#

Im hazarding a guess, when a sphere "rotates" into another colliders space, it causes the issue

#

Hmm...

steel verge
#

I am spawning the boxes really quick in an Update loop when the player holds down their mouse. Can they overlap each other when I instantiate them?

feral pike
#

It looks like when they rotate at rest "falling off another cube" or "slide down" rotation causes a gitter

#

Are you using Change Position/Rotation or Velocity for moving the cubes?

steel verge
#

No. I am just creating a box that falls down because of physics and collides with each other.

#

There is nothing on the box prefab except a Transform, SpriteRenderer, Rigidbody2D and BoxCollider2D.

feral pike
#

Well, a quick fix might be going into your project settings and increasing the contact offset or Contacts Generations

#

Or trying a different Detection mode on your rigid body

#

If it is because they spawn on top of each other, you can do a Physics.Overlap check to make sure you arent spawning on top of something else

#

Im sure what happens to the physics engine if they spawn on top of another object 🤔

vestal swan
#

Any ideas how I could prevent that?

#

It just throws you like crazy

#

And it still goes into the wall sometimes too

coral eagle
#

if input is read in update, and movement is applied in fixedupdate, is it possible to avoid a few frames of reading input but not applying force?

forest tundra
#

i have an issue with the ignore collisions

#

the first collision is not ignored but the rest are

timid dove
#

and you will collide with things between you and your target

vestal swan
#

Okay, then how would I teleport to a position without pushing other objects inside the wall?

timid dove
#

you'd have to resolve that conflict somehow

#

do an OverlapBox or something

#

find everything in the place where you are going to teleport to

#

and... move it somewhere?

#

Basically you're letting the physics engine answer the quetion right now of where to move the thing

vestal swan
#

right

timid dove
#

and it's deciding to put it in the wall, because that's the closes place probably

vestal swan
#

Well I want the toaster to be moved away, instead of the props

timid dove
#

make the prop kinematic maybe?

#

at least for a few frames

#

while the toaster is teleporting

vestal swan
#

I tried setting it to kinematic at all times and iirc it didn't help

#

I'll try again real quick

timid dove
#

are you using isKinematic

#

or

#

Rigidbody2D.bodyType

vestal swan
#

bodytype

#

im just changing it in the inspector

timid dove
#

ok good

vestal swan
#

oh huh that just freezes them in the spot

#

okay so you're saying i change an objects that are in an OverlayBox to kinematic before I teleport and then back to dynamic after I tp there?

timid dove
#

tp back?

vestal swan
#

sorry misspoke

#

after I teleport there

timid dove
#

oh

#

well like...

#

after the physics engine gets a change to knock your toaster away

#

then change it back

vestal swan
#

hm okay

timid dove
#

not sure how to figure that part out exactly

vestal swan
#

well I still want them to react to the toaster

timid dove
#

maybe wait 1 physics update, or some number of seconds?

vestal swan
#

otherwise you can't interact with the props at all, no?

timid dove
#

well I'm not entirely sure how your game works

#

but you said you wanted the toaster to get knocked away instead of the prop

vestal swan
#

the toaster keeps the velocity of the ball

#

yeah I meant if its in a corner

#

I just don't want the bottle to get pushed into the wall, but in general they should be pushed around

#

I'll give what you said a try though

timid dove
#

right

#

ok yeah it's kind of a tough problem

#

the physics engine doesn't like teleporting obejcts 😄

vestal swan
#

hmm

timid dove
#

you could maybe do the overlaybox and try to find a clear direction for the prop to go in that isn't blocked by a wall with raycasts or boxcasts?

#

and then move the props right before teleporting the toaster?

#

something like that 🤔

vestal swan
#

that sounds really hacky and hard lol

timid dove
#

yeah i know haha

#

I wonder if the answers here might help your situation too

vestal swan
#

I don't really see how this relates to my issue though, the crazy toaster shooting issue I already fixed by increasing the mass a bunch

timid dove
#

It's talking about objects getting stuck in walls

#

apparently the getting stuck part is related to friction?

vestal swan
#

ah hm

#

well the object isn't really stuck per-say, it just kinda clips through and then it goes inside of the collision box

quick gyro
#

how can i prevent my 2d rigidbody player from bugging in collision tiles?

#

If force is added against the tiles by the player it happens.

spiral fractal
#

How do you code the ball in 3d ping pong to add force in the direction it got reflected in, so it gains speed and doesnt slow down

#

if it reflected downwards, how do you add additional force downwards

#

and how do you check how it is moving

solemn beacon
#

Hey guys, I have a point (startingPoint) on a rectangle (portal), and I want to translate this point at a distance (minDistance) from this rectangle

#

I tried the following Vector3 newPoint = portal.transform.TransformPoint(portal.transform.InverseTransformPoint(startingPoint) + new Vector3(0, 0, direction.normalized.z * minDistance));

feral pike
# spiral fractal How do you code the ball in 3d ping pong to add force in the direction it got re...

Calculate its reflected angle just like you do for light off a mirror in this example and apply a force going in that direction, at a high level https://math.stackexchange.com/questions/1844/how-to-calculate-reflected-light-angle

forest tundra
#

With ignore collision 2d, the first collision doesn't get ignored but everything else does, anyone else have this issue?

blissful rover
#

I'm trying to move my character through a sphere collider that has is trigger enabled but I can't pass through it, what am I doing wrong? I thought you are supposed to be able to pass through triggers

feral pike
#

Did you remove the mesh renderer + mesh?

blissful rover
#

I figured it out, apparently my raycast is at fault

#

thank you anyways though

feral pike
#

Happy hunting!

stuck bay
#

not sure if this is the right section but:

I have a ring of fences (86 seperate meshes) that i've combined into a single mesh, would it be better for performance to use the 86 simple box colliders or use a single mesh collider instead now it's all combined?

tender gulch
stuck bay
#

@tender gulch thanks, yeah everything with a mesh collider is static, this should cut down on my object count considerably, i'll have primitive collider versions for throwing about if I need to use Physics

tender gulch
#

I've done some tests. I have a huge city map that was made of separate objects. Most of them were using box colliders. I merged the meshes into bigger chunks and used mesh colliders for them. I used profiler analyzer on data before and after the merge and the mean and median difference of Physics.Process was less than 0.01 ms which might as well be a statistical error. I assume it's due to the count of collider reducing more than 10 times. While mesh colliders are heavier than primitive, if you exchange 10 to 1 apparently there isn't much difference.

feral pike
#

I dont think you could desern any performance drops until you are in the thousands of objects territory

#

If you do have thousands of objects, you want to combine, but not over combine such that object culling gets a hit

#

Id keep the combined meshes smaller than 100 meters by 100 meters

distant coyote
#

this is always a balancing act heh

proud edge
#

Hey everyone, I'm trying to get smooth surfaces across my level because my character bumps up and down if there is not an edge collider over where my floor is supposed to be (I believe this is due to the player character having a circle collider instead of a box). I am working on a tilemap for the level, and I have added 3 multiple edge collider components when there is a break in the ground. Does anyone know of a possible alternative to this? It seems inefficient to keep track of a bunch of edge collider components in my level tilemap.

low ore
#

how can I make my rigidbody stop quicker, when force isnt being applied?

low ore
#

allright, i will try it

timid dove
#

in general, to accelerate a rigidbody, you need to add force

#

accelerating means speeding up and slowing down

#

drag simulates a force being added opposite and proportional to the object's current velocity

low ore
#

alright

#

btw for more context, i am using add force, and i am moving a car left and right

#

and I wanted the car to switch directions quicker

timid dove
#

then more force is needed

#

F = ma

#

force = mass * acceleration

#

acceleration = force / mass

#

since you aren't changing the mass

#

you must increase the force

low ore
#

alright

#

so ill add more force, whenever it changes direction

timid dove
#

you could check if the direciton you are adding force in is opposing the direction of motion

#

and increase the force then

low ore
#

thank you

low ore
#

So my friend is playing my game, and sometimes randomly, the rigid body stops on the plane that it is moving on. Why does it do this

normal river
#

Anyone know if you use sphere colliders on a character it will prevent animations from clipping? like if I had a sphere collider on the hand and animated the hand to move towards the face it wouldn't go through the face

compact basin
#

Im having issue when applying rigidbody component to object disables its collisions with raycasts

#

using mesh colliders / renderes

#

Object collided with is "null" its unable to call the render component of object it collides with

#
        if (Input.GetMouseButton(0) && cooldown == 0 && mag > 0)
        {
            var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            Debug.DrawLine(firePoint.transform.position, Camera.main.transform.forward * 50000000, Color.red);
            RaycastHit hit;

        
            muzzleFlash.Play();
            mag--;
            updateAmmo();

            if (Physics.Raycast(ray.origin, ray.direction, out hit))
            {
                var objectHit = hit.transform.GetComponent<Renderer>();
                Debug.Log(objectHit);
                if (objectHit != null && objectHit.tag == "enemy")
                {
                    StartCoroutine(enableMarker());
                    hit.transform.parent.gameObject.GetComponent<zombieHealth>().takeDamage(damage * hit.transform.gameObject.GetComponent<multiplier>().multi);

                }

            }
        }
sullen loom
#

my rigidbody controller is really messy and its really glitchy

#

Problem 1: Doesnt move in the direction of the camera
Problem 2: Wobbles back and forth when pressing a or d
Problem 3: Stops moving randomly

kind kettle
tidal knoll
#

Hey guys - when I attempt to add a "Physics Material" (there may be a 2d version but I'm a little lost if I'm honest) to a GameObject's Rigidbody2D but I continuously just get the crossed circle saying I can't. If there's anything I can provide more information with then please let me know! This is what the Rigidbody2d looks like:

kind kettle
#

Try clicking the circle to the right and see which options you have

tidal knoll
#

I simply get "None", even if I add a 2nd straight into the "Assets" folder (though this could be the wrong place). Dragging is ineffective too. I'm not sure if I need to enable something or not, I'm struggling to find others struggling 😛

#

So I don't have the option to create a "Physics Material 2D" - I believe this to be the source of my issues. Do I need to have an option from somewhere or an Asset of some form loaded that I probably don't already?

kind kettle
#

Is the 2d component asking for physics material 2d?

tidal knoll
kind kettle
#

Even inside the 2d tab?

tidal knoll
kind kettle
#

No, near the top of the create menu in your first picture

tidal knoll
#

I hate myself.

#

It's there

#

I've been here 2 hours 😢

kind kettle
#

That sucks. I am usually stuck on some bug in two hours before I realize I haven’t attached the script to a game object or something stupid like that

tidal knoll
#

Works a dream though - thank you ❤️

zinc cloud
#

Is there a way to make particles individually destroy themselves when they hit a specific target but bounce off a different object?

open sigil
#

I'm new to unity, so here's a basic question: I'm making a billiards game and I'm trying to align the balls without them overlapping or being uneven. How would you go about this? I have managed to get them aligned by making a rudimentary triangle, but I don't know how to save their positions after that to use in the game without manually spawning, shaking, and despawning the triangle.

cold rivet
#

yo, im trying to use Physics.OverlapSphere, but it wont detect nearby enemies. Heres the code:

#

EnemyList = Physics.OverlapSphere(transform.position, 400, Enemy);
testText.text = EnemyList.ToString();

#

even when enemies are on screen, the text displays an empty array

#

anyone else run into this issue?

timid dove
#

what is Enemy?

#

e.g. what are you passing in as the third parameter?

cold rivet
#

the third parameter is the layer mask for enemy objects

#

to clarify, the enemies do have circle collider 2d attached to them

cold rivet
#

This statement does work with 2d colliders right?

tender gulch
cold rivet
tender gulch
cold rivet
#

just checked the API

tender gulch
#

I'd check the docs for what methods are available in Physics2D.

cold rivet
#

there an Overlap circle

tender gulch
#

Then you can use that.

cold rivet
#

got it, thanks dlich

cold rivet
#

anyone got a good script for detecting if an object is being clicked on in a 2D environment? Ive been going through scripts ive found online and none of them seem to work well

timid dove
#

Both of those options require that the object has a collider2D

cold rivet
#

yeah, thats what ive been messing around with

#

ive managed to use it to get a solution that works for what im needing it for

cedar grove
#

I'm making a bomberman game where the player can place a bomb at it's feet and walk away but can't walk over it afterwards.
Right now the player can go oob by using the push force of the bomb collider (I assume that's the reason).

#

It would be best if there was no force (for the player) until the player moves out of the bomb collider, but just not being able to go oob would be acceptable too.
The character, house and bomb all have a box collider without physics material.
The collider of the bomb and house are exactly adjacent.

#

The character has a rigid body with gravity off, interpolar none and Rotation and y position frozen.

#

I turned the global gravity y force off because all movement is on the x and z axis.

#

I would greatly appreciate it if anyone could help or push me in the right direction!

supple sparrow
#

is it grid-based ? Enable collider only when player leaves the tile ?

#

or I mean make it a trigger and act upon triggerExit ?

#

or yeah always trigger and prevent Enter (do nothing special on exit)

cedar grove
#

The player movement is not. Bombs are always placed in a grid though.

#

That I didn't think of that

#

thx!

#

But if I remember correctly, I won't get trigger events if the object spawns within my trigger

supple sparrow
#

yeah right

#

plus, the "prevent from entering the collider" part could be tricky if player has free movement

#

(trigger, not collider)

cedar grove
#

I was thinking of giving the bomb and player a trigger collider.
Then disabling the player collider when placing the bomb and enabling it on exit. but I think I won't get the Exit event.

#

Wait, the player could still walk into the house then. nvm

supple sparrow
#

yeah bad idea to disable player collider ^^

cedar grove
#

agreed

#

do I understand correctly that the force that pushes things out of a collider is the same force that keeps things from moving into it?

supple sparrow
#

Yeah probs because of that

#

You could instantiate bomb in front of the player ?

#

but it's different from your spec "where the player can place a bomb at it's feet"

#

🤔

cedar grove
#

Normally bomberman games put the bomb directly at the player

#

it feels better that way

supple sparrow
#

A distance check above a threshold to enable the collider after the player gets far enough might be easier....

#

but you'll get a sphere shape, not a box

cedar grove
#

That's a good idea

#

I'll try it out. Thanks again!

supple sparrow
#

You're welcome, happy coding 👍

olive creek
#

Hello

#

I am having a slight problem

#

I am using a character controller, and I want it to react to physics

#

More specifically, I want it to go up and down slopes

#

Whats happening is, it just flies instead of going down the slope

#

Can anyone help me

tender gulch
#

Although, it seems to be kinematic, so I guess you move it manually..?

olive creek
#

Sorry, I'm a beginner.

tender gulch
#

I mean that you don't use physics for the object to move.

olive creek
#

Yes

#

I dont

#

I mean, I use a character controller

#

not a rigidbody controller

#

So I dont think I do

#

The thing is, this works in my other game

tender gulch
olive creek
#

Well, I followed Brackeys tutorial

tender gulch
#

Code! Do you have it? 😄

olive creek
#

I got the raw axis of the x and z axis

olive creek
tender gulch
olive creek
#

Hello?

#

Sorry for disturbing you

#

I just started learning unity

#

So im a noob

#

😄

tender gulch
#

You're not applying anything that looks like gravity.

olive creek
#

Yeah

#

But still, in my other game, it works just fine

#

Im able to go down slopes

tender gulch
#

Then you've missed something.

olive creek
#

but in THIS game, IDK why, but ive looked back and forth, I cant go down slopes

tender gulch
#

At least in the code you shared, it won't go up or down. Only horizontally.

olive creek
#

Yes

#

Up and down as in, on the Y axis?

#

Then yes

#

I cant go up or down

tender gulch
#

and that's why you can't go down the slopes

olive creek
#

Og

#

Oh*

#

Well, then how did I do it in the other game

#

And not this one

tender gulch
#

You're supposed to be able to answer that question, not me. 😅

olive creek
#

True

#

lol

#

Well, I'll look into it

#

Well then, for the meantime, how do I detect if I am not on ground and move it on the Y axis until it touches the ground?

#

Wait

#

Nvr mind

tender gulch
#

If your character moves on y axis it means that something is moving it on y axis. Whether it's the physics system or your code.

tender gulch
#

Then you know what to look for in your other game.

olive creek
#

Ok

#

Thanks!

dawn spire
#

i want that if i walk to the object it should spin a bit and then fall (like in real life) but nothing happens , i m an FPS capsule

tender gulch
#

I've yet to see objects that spin and fall when you approach them in real life...

proud trellis
#

clearly you lack the power of Psychokinesis

#

@dawn spire have you written any code which facilitates this behaviour ?

tender gulch
#

That must be the problem ><

dawn spire
#

nope there are no scripts attached to those objects , only rigidbody component

#

and collider

proud trellis
#

well then, you would be needing to write some sort of code to do the same

dawn spire
#

oh!

old karma
#

Hi, I have a question about physicsScene.simulate. I am trying to draw the simulated trajectory of a grenade using a separate physicsScene but it is getting completely different results depending on what value I use for the step value in the simulate function.

I am applying the same force to the grenade in both the main scene and the physics scene but I cannot get it to match up.

#

Putting a lower value in the simulate step (i.e. 0.01f) seems to reduce the amount of force being applied to the grenade.

#

The red line is the main scene trajectory. The purple is the simulated using 0.01f steps. I am rendering the purple line using a line renderer with 100 points with the 0.01f time increments.

#

This is the same scene with the simulate step changed to 0.02f in code... The trajectory looks like more force is being applied to the simulated object.

old karma
#

Mmm I think I figured it out. I am now using Time.fixedDeltaTime for the simulation step and it (mostly) matches now. I didn't expect the differences to be so great between different step timings. On the separate physics scene it doesn't look like the physics are entirely deterministic either, I am still getting some jitter when bouncing off walls for some reason.

#

Also I figured the idea to predict grenade trajectories using a multi physics scene doesn't seem worth it for performance reasons. Calling 150 simulations (equating to 3 seconds of simulation at fixedDeltaTime) on the physics scene containing the grenade + a handful of environment wall rigidbodies absolutely tanks the framerate. It is going from 200+fps to around 20fps.

#

Does anyone have any good ideas on how to simulate these trajectories in a performant real-time manner?

supple sparrow
#

yeah physX is not deterministic

#

you could do your own parabola equation, would cost less 🤷‍♂️

old karma
#

I actually posted this problem in the unity forums now with the code I am using, the exact thing I am trying to replicate here is how Gears of War does it's projectile aiming:
https://forum.unity.com/threads/simulating-grenade-throwing-trajectories-using-multi-scene-physics.1057832/

glacial jolt
mystic hound
#

Anyone know how to make better jumping using Rigidbody? My character sort of floats back down. Have tried finding solutions but haven't come across any

rustic topaz
#

try increasing the mass on your gameobject, a feather (low mass) will float down, an anvil (high mass) will accelerate a lot harder

mystic hound
#

I have tried that but it doesn't have an effect at all on it

#

Decreasing drag speeds it up a tiny bit but mass seems to not change anything in game

rustic topaz
#

is your gravity scale set correctly?

mystic hound
#

I wasn't sure whether a setting like that may be messed up. How would I check?

rustic topaz
#

if you dont like the default physics behaviour, simply increase the gravity scale of your way down

#

if its at 1 thats okay

#

*on your way down

mystic hound
#

Where are the gravity settings sorry?

rustic topaz
#

under the rigidbody component

#

Oh might not exist on the normal one, I'm used to the 2D one, in that case yeah increase mass over time till you land

mystic hound
#

Hmmm

#

In my project settings it says the y value of gravity is - 9.8

#

No idea if that's where it should be

rustic topaz
#

thats fine, its the same as earth

#

in 2d bodies there is a gravity scale, appearantly not in 3d bodies, so when you are coming down from the jump either progressively add mass or progressively add a downwards force until the jump feels right

mystic hound
#

yeah, I've tried adding a force down, it's just quite hard however low I put the multiplier, and just haven't set it up yet so that it doesn't effect the character walking down a slope

#

Do you think you should use velocity changes or add force for jumping?

rustic topaz
#

really depends on the feel you're going for, i'd say experiment with both, personally i often use add force

#

its by trying out different things you sometimes stumble on something unexpectedly fun

mystic hound
#

Yeah that's true

#

Do you know a good way of finding when the player is at the peak of their jump?

#

I've been trying to use when the velocity.y goes starts to go below 0

#

but still having troubles

glacial jolt
#

using the inflection point of velocity.y to 0 works for finding the peak of the jump

#

note that many games use a much higher gravity for characters, since 9.8 can feel unnaturally slow. We use 25 in our game

mystic hound
#

Inflection point of velocity.y? What's that? (Sorry stupid newbie questions, haven't done this stuff for quite a while)

glacial jolt
#

as in, the frame velocity.y transitions from a positive number to a negative will be where the peak of the jump occurs

mystic hound
#

How would I work where that is out in C#?

glacial jolt
#

also, note that mass does not affect the speed an object falls https://www.youtube.com/watch?v=KDp1tiUsZw8

Courtesy: NASA - Galileo and Apollo 15
At the end of the last Apollo 15 moon walk, Commander David Scott (pictured above) performed a live demonstration for the television cameras. He held out a geologic hammer and a feather and dropped them at the same time. Because they were essentially in a vacuum, there was no air resistance and the feather ...

▶ Play video
mystic hound
#

That's what I suppose I was trying to do when seeing whether velocity.y was below 0

glacial jolt
#

are you trying to play an animation or something at the peak?

mystic hound
#

No, just literally trying to find where the peak of a jump is, so I can add downwards force to speed up the falling part of the jump

#

as currently character is falling quite slow

glacial jolt
#

ahh

mystic hound
#

to the point where they're gliding

glacial jolt
#

cranking up gravity might get you the effect. But you could just check if velocity.y < 0, add a force each frame. So downwards gravity would become much stronger

#

if you just do a huge force add the moment the peak is hit, it may look jarring

mystic hound
#
    void Jump()
    {
        if (Physics.Raycast(transform.position, Vector3.down, jumpRayDistance))
        {
            if (Input.GetKeyDown("space"))
            {
                RB.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
            }
        } else
        {
            if (RB.velocity.y < 0f)
            {
                RB.AddForce(Vector3.down, ForceMode.Impulse);
            }
        }
    }
}
#

Something like this?

#

The player falls down quite hard and violently with that

glacial jolt
#

you want ForceMode.Force

#

Impulse is for forces that are added once

#

like an explosion

mystic hound
#

Okay, let me try that

#

Thank you for your help btw

glacial jolt
#

np

mystic hound
#

Okay that's working a bit better now thank you. I think that's given me a good basis, just needs details tweaked about it

#

Thank you again

mystic hound
#

Now when I try build the game, the falling force doesn't take effect. Just works like it used to without the fall part? I've saved compiled everything obviously

glacial jolt
#

it's possible it is failing and you are playing on an older build

mystic hound
#

Build completed with a result of 'Succeeded' in 9 seconds (8536 ms)
Comes out in the console when I do it

glacial jolt
#

make sure the build you are running is indeed up to date

mystic hound
#

Yeapp I am. Just edited the script that contains the updated falling code to do something really visually obvious when I press "e" and that works. Just the falling part of the script isnt

#

Btw anyone got any advice on fixedupdate and multiplying by deltaTime. I was using Update() for my WASD controls and Jump, all of which use add forces and multiplying by Time.deltaTime which I've read you shouldn't do? Changing it FixedUpdate() and without the Time.deltaTime. What should I use for forces?

mystic hound
#

Okay so I've got it working in the build version now. Jump needed to be in FixedUpdate()

modern laurel
#

Hello! I'm having unfavorable results on my coin pusher physics. If anyone would like to help me out (i literally started using unity for 3d last night) I would LOVE the @ or a DM

#

I am currently live on twitch while i work on it, so you can see it, but I'm also ok to do screen sharing or whatever through discord.