#⚛️┃physics

1 messages · Page 58 of 1

lime nacelle
#

How do I make him not fall over. Does this only affect objects and once I add ridged players this won't happen?

Code Here:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    public Rigidbody rb;
    [SerializeField]
    float moveSpeed = 4;
    Vector3 forward, right;

    void Start ()
    {
        forward = Camera.main.transform.forward;
        forward.y = 0;
        forward = Vector3.Normalize(forward);
        right = Quaternion.Euler(new Vector3(0, 90, 0)) * forward;
        Debug.Log(forward.ToString());
        Debug.Log(right.ToString());
    }

    void FixedUpdate ()
    {
        if (Input.anyKey)
            Move();
        rb.AddForce(new Vector3(0, -9.81f, 0), ForceMode.Acceleration);
    }   

    void Move()
    {

        Vector3 rightMovement = right * moveSpeed * Time.fixedDeltaTime * Input.GetAxis("HorizontalKey");
        Vector3 upMovement = forward * moveSpeed * Time.fixedDeltaTime * Input.GetAxis("VerticalKey");
        

        Vector3 heading =  Vector3.Normalize(rightMovement + upMovement);
        rb.velocity = new Vector3(heading.x * moveSpeed, 0, heading.z * moveSpeed) * Time.fixedDeltaTime;
        //transform.forward = heading; 
        //transform.position += rightMovement;
        //transform.position += upMovement;
        
    }
}

Video here:

verbal karma
#

you can lock his rotation in the constraints tab

blissful lark
#

Hi guys , i have a question but i don't know if it's the right chat .
im usind Addforce.ForceMode(VelocityChange) to make my fps sliding mechanich.
but , instead of normally sliding like the video i watched to make the code , it Teleports forward in a very stiff way...
is there a way to make it smoother
ps. i use FixedUpdate

vernal tide
#

i don't understand where you get AddForce.ForceMode(VelocityChange) from... that isn't a real thing.
You would want to use something like this

RigidBody.AddForce(Vector3, ForceMode.Force)

vale light
#

Is there anywhere where I can find a place to learn vr physics I would love to know.

lime nacelle
#

are vr physics any different from just normal physics?

ember zodiac
#

having a problem with my jump code. form some reason, i can't get my character to fall ar what feels like a normal speed

#

player is falling incredibly slowly

#

I've tried:
doubling the physics, and even when i increase the jump force, its still falls slowly
I got rid of both angular drag and regular drag
i changed the collision detection

#

nothing got me closer

ember zodiac
#

nvm, i was resetting the velocity

rigid reef
#

Hey, how do I make Cloth work in Unity?

#

I've added the Cloth component to my cloth

#

have done the restrains too

#

but the colliders

#

how I make the cloth detect the skin of the player?

hot grotto
#

I'm making a game that uses faux gravity, but how to make the player jump? Everything I do ends up with the player going to the 'north pole' of a planet, instead of going away from the planet, what is a good way to apply force to a player that faces outwards a planet?

foggy rapids
#

lots of interesting ways. two common ones i've seen:

  1. get the normal of the face that you jump from and use that as the direction.
  2. have a child object LookAt the player from the center of the planet and use that as the jump direction and the inverse as the gravity direction
hot grotto
#

Very useful thanks!

viral ginkgo
#

@hot grotto Learn your vectors, you will need to use Vector3.Cross, Vector3.ProjectOnPlane or similar things. To find your directions.
Learn how to manipulate rotations, i suggest you use Quaternion.LookRotation(fowardDir, upDir) to make rotation from vector directions.

Use Debug.Drawray or Drawline to debug your direction vectors.

All these will be needed when doing character movement and camera handling

half phoenix
foggy rapids
#

friction

half phoenix
#

Yeah, but it makes no sense how the speed goes down so fast, and the lingers forever before coming to a full stop

#

Also, there is a physics material with 0 everything applied

foggy rapids
#

angular drag?

#

drag

half phoenix
#

Drag is 0, angular drag is 1

foggy rapids
#

angular drag will stop a ball from rotating

half phoenix
#

Right. Results are similar with regular drag too

foggy rapids
#

write your own physics so things behave exactly as you require 🙂

bright oar
#

I can't figure out why this code doesn't execute, I'm not getting "collider detected" in the console

#

the mask parameter is referencing a layermask variable that has the layer where the collidable objects spawn, they have a box collider set to trigger and a kinematic rigidbody

#

but the overlapsphere seems to be detecting nada

foggy rapids
#

save your parameters for the overlap sphere into the class
then implement OnDrawGizmos to draw the sphere.

bright oar
#

you mean to help with debugging? I did that already as I was curious if the sphere was in a wrong place, but it was in the correct spot

foggy rapids
#

must be the mask then 🤷

burnt ridge
#

So my player moves but there is momentum and it takes a bit longer than I would like to change direction and go into the opposite direction. Anyone knows what this is about? Has to be some kinda setting i can change.

slate sorrel
#

how can i use a 2d collider to allow it to pass through things, but run code when things collide? im making bullets in a galaga type game

viral ginkgo
#

@slate sorrel if you detect collision in oncollisionenter, collision wouldve already acted on the object

#

you can revert position rotation velocity angvelocity

#

you will save them every fixedupdate

#

if there's a better way around this, i'd like to know

slate sorrel
#

id just like to delete an object when it touches the ship, maybe add some particles

#

and probobly use a health mechainic

viral ginkgo
#

its easy
but ship will feel the impact for one frame

#

but i think thats not you were worrying about

slate sorrel
#

thats okay

viral ginkgo
#

you considered trigger colliders?

slate sorrel
#

no, how would that work

shut wind
#

is it possible to manually define the inertia matrix of a rigidbody

grizzled jacinth
#

Is there anywhere where I can find a place to learn vr physics I would love to know.
@vale light
are vr physics any different from just normal physics?
@lime nacelle
physics solvers / engines / APIs are not fundamentally different in VR but you do often encounter some unique challenges you wouldn't otherwise. like needing to account for very low latency, very high frame rate, perceptual cues / ghost limbs for collision and force so people don't get sick from their hands and limbs not appearing coincident with where they are in physical space. and things like.. how to deal with picking up an object like a stick / pole with both hands from either side of the pole and manipulating / moving it around naturally with inverse kinematics or force that transfers between both hands through the object, etc.

lapis plaza
#

in relation to that, if it were up to me to decide, I'd almost always disable automatic fixedupdate physics stepping for VR only games and just step the physics once for every frame manually

#

I guess if you have to target a whole lot of different headsets that could show some issues, like physics at 60Hz could have issues if you've dialed the physics work proper at 90Hz

#

but what you would gain with that approach is that you'd not get extra latency from physics sim not done on each frame, it would be done just right before you send the thing to render

solar bison
#

Hello! i need help with strange thing.

So i have platform, and when character touch plane, he get character.transform.parent = plane.transform.
Character have Character Controller. When plane is moving, character doesn't follow the platform.
The platform has Trigger box collider with attached script to make character child. And plane have rigidbody.
Child of platform have Cube, that have box collider on it.

Character can't stay stable on platform and slide in the opposite direction from where the platform is moving.

Here is example:

#

On video on right side we have character inspector and plane inspector (bottom is plane)

#

Any ideas?

solar bison
#

Nvm found problem.

stuck bay
#

I think this is physics...
is it possible to increase the size of a sweeptest collider relative to distance? so it starts small but gets bigger as it moves further away from the origin.

torpid prism
#

is there a fast algo for packing spheres on 3d mesh surface ? was thinking to do a classic approach with verticies , normals, distance comparison and maybe octrees and burst compiler , but something tells me that this will be too computantionally heavy to run on a phone

#

( will do 2 types of packing , large spheres first , small green spheres later )

late stratus
#

does anyone know how the fixedDeltatime works?

viral ginkgo
#

@late stratus its fixed until you start to lag

late stratus
#

when applying force to a rigidbody in my scene it doesnt seem to end up where it supposed to end up

#

only when my time scale is equal to my timestep

viral ginkgo
#

when you lag, it can increase up to 0.33ms

late stratus
#

srry let me specify

viral ginkgo
#

@late stratus you want determinism?

late stratus
#

i mean how it works in fixedupdate

#

what do you mean?

viral ginkgo
#

same input, same result regardless of lagging

late stratus
#

yes

viral ginkgo
#

you can fix the fixed time step

#

in time settings

#

theres a max value for it

#

its 0.33 by default

late stratus
#

ok heres what i did now

#

i ran a calculation for where my object is supposed to end up

#

put the timestep to one

#

and timescale to 1

#

i got a perfect result

#

then i increased timescale to 2

#

result got bad

#

reset the timescale to 1

#

and put the timestep to 0.2 and got bad results

#

why is that?

viral ginkgo
#

If you lower timeScale it is recommended to also lower Time.fixedDeltaTime by the same amount.

#

I think you want to do the opposite

late stratus
#

but why

#

how does it work

#

why doesnt unity just interpolate purely based of fixed time step?

#

ok but when i lower my timescale the game slows down

viral ginkgo
#

Let me explain how it works from what i understand and you can decide what to do:

Timescale is basicly your fixedupdate framerate
timeScale / fixedDeltaTime = physics frame rate
and you want to maintain your framerate at 50
@late stratus

#

timeScale * 2
and
fixedDeltaTime * 2
so this is the proper way to make time faster

late stratus
#

and what if you want to run fixed delta time maybe like 100 timer per second

#

but not slow down the entire game

viral ginkgo
#

this will do

#

timeScale x 100
and fixedDeltaTime x 100

#

i think, never tried but should be fine

#

i think fixedDeltaTime is readonly though, dont remember where you can change that

late stratus
#

you can change it in the settings

#

but i want my fixeddelta time to be something like 0.02

viral ginkgo
#

yeah, you should access that field in the settings with code.

#

if you wanna do all this timespeed changing stuff in runtime

#

@late stratus why

late stratus
#

im running a simulation for a drone

#

with some changing aerodynamic factors

#

so i want fixed update to refresh as fast as possible

viral ginkgo
#

you want more framerate then

late stratus
#

to take these changing factors in to account the best i can

#

yes

#

way more

viral ginkgo
#

fast time more framerate

late stratus
#

i need a lot of framerate

#

without slowing the game down

viral ginkgo
#

does it take user input?

late stratus
#

fixed time step needs to be lower

#

no it doesnt

viral ginkgo
#

great

#

here's what you might like:

#

disable physics autoupdate

#

update it in your code

#

update as fast as you can

#

in a coroutine

#

you can measure time passed

#

and see how many frames it can do etc

#

you have full control

late stratus
#

essentially a controlled for loop

viral ginkgo
#

a while loop

#

in a coroutine

late stratus
#

so i would need to write my own physics interpolation

viral ginkgo
#

what? no

#

interpolation?

late stratus
#

i cant just go rigidbody.addforce then right

viral ginkgo
#

what do you mean physics interpolation

late stratus
#

well i need to know how far my object traveles

#

so take in to account what the time difference is between the two fixed steps

#

and interpolate based on the current force and how long that force is active

viral ginkgo
#

Move all your fixedupdate code to your MyFixedUpdate(float myDeltaTime, etc) methods
do the same logic there

#

You run physics, and you run MyFixedUpdates in the while loop body

#

And thats where all your logic is

#

If you have logic in Update, you should move them to MyFixedUpdate

#

@late stratus You should also not have that myDeltaTime,
or keep it same 0.02

late stratus
#

but how will unity determine what the acceleration is on the body then

viral ginkgo
#

@late stratus Physics.UpdateScene method takes in a deltaTime

#

which you will pass 0.02 every frame

late stratus
#

so what is the difference then between this and fixedupdate?

viral ginkgo
#

@late stratus you are the one calls the FixedUpdate and Physics update

#

instead of unity

#

and you can make it run as fast as your pc can

#

without messing determinism up

#

@late stratus It was PhysicsScene.Simulate btw

late stratus
#

ah thanks

#

i will try that

viral ginkgo
#

you use this, and you define your custom update method like MyFixedUpdate()

#

call them at the same time in your loop

#

and thats it

late stratus
#

fixedupdate seems to be working a bit weird

viral ginkgo
#

fixed update is not fixed

#

not deterministic

#

its like update
but its deltatime is usually fixed, whereas update is never fixed
thats what it is

late stratus
#

ah oke

#

and how does unity determine the acceleration on a body

#

does it use the speciefied time step that you basically pass in as a suggestion

#

or does it always determine it on what it is now

viral ginkgo
#

delta velocity / delta time

#

deltaTime

#

i'd think

late stratus
#

it cant be velocity/dt

#

because you cant add acceleration that way

viral ginkgo
#

i said delta velocity

#

you wanna measure it or change it?

late stratus
#

measure it

#

but that measurement is before the change happened

viral ginkgo
#

(velocityNow - velocityPrev) / deltaTime

late stratus
#

but to know velocityNow you would need acceleration

#

for the timestep where your checking

viral ginkgo
#

thats like the velocity in last executed physics update

#

now, your physics engine stored all the addforces and stuff
theres still more to store until your fixedupdate logic ends

when your fixedupdate logic ends, physics engine will take all the applied forces and in the next frame, velocities will be affected

#

@late stratus

late stratus
#

do you know the site where that image comes from, I would like to see it a big bigger

viral ginkgo
#

click on it, open original

#

@late stratus

late stratus
#

ty

#

unity physics are so weird tf

viral ginkgo
#

in physics subsection, you can see where the fixedupdate is
internal physics is the physcis engine, which can be called manually with PhysicsScene.Simulate i think

OnCollider and on Triggers are also seen here, they are worth to pay attention as well
@late stratus

late stratus
#

i think the Simulate is a good entrypoint for me

viral ginkgo
#

@late stratus

#

Here is what you might wanna care about

late stratus
#

yes

#

this is from the unity docs?

viral ginkgo
#

i cut that image

late stratus
#

i will look into that

#

ty very much

stuck bay
#

Isn't handling character basic movement (walking, running, etc.) through root motion a poor way of doing it?

#

As opposed to handling the movement through code and having the animation on a loop?

viral ginkgo
#

@stuck bay i'd think root motion is for things like melee takedown animations and stuff
or getting in and out of vehicles

#

you character logic should be one object and animation/visual stuff should be its child

#

.
I think if you follow this you'll have it easier:
Make it so that your character can function perfectly even if you completely remove the animator, and its model
I mean, dont make your logic dependent on animator and model

stuck bay
#

Thats what I was thinking BARGOS. I was a bit thrown off because their sample project seems to use root motion for everything but jumping which I found to be quite odd

#

It does look great but I always thought this was improper for various reasons

neat oxide
#

hi, when searching for physics with preview packages enabled, only havok shows up. where did unity physics go?

foggy rapids
#

already in project

abstract coral
#

i have a feeling its something to do with the animator but im not sure

ionic pewter
#

hey guys, i'm making a 2-D platformer but my platform isnt acting as a rigidbody and the character is passing through the platform, any help? any script i'm missing?

slate sorrel
#

add a collider, of type box, polygon, circle/elipse. or whatever type is required

#

@ionic pewter forgot to @ u so... do that ^^

ionic pewter
#

lol i see

#

alright thanks

slate sorrel
#

yeah, colliders are default on 3d shapes. made the same mistake

ionic pewter
#

yea, thats why

#

no wonder

#

thanks for the help 🙂

slate sorrel
#

ur welc :)

mighty sluice
#

@novel summit I got my vector field multi-threaded. turns out that it's actually really super cheap being so small. with around 500 rigidbodies, the vector field and the aerodynamics calculations take less than 0.5 ms

#

even with about 1500 addForceAtPosition()'s each fixed update, still under .5 ms

novel summit
#

Impressive!

#

So you're sampling 3 points for each object at different positions on their bounds?

mighty sluice
#

thanks! I'd be happy to throw the code at you whenever you're ready

#

depending on the object, the samples come from hypothetical drag planes

#

each rigidbody might have more than one drag surface on it,

#

for sphere's it's a hypothetical box the size of its bounds

#

each surface will do drag additions if it is moving in that direction, or wind is blowing on it

#

it's a bit more in depth than just using bounds

novel summit
#

I'd definitely be interested if you're open to sharing the code. I wouldn't be checking it out right away, so I don't need it now. Is this something you want to open-source?

mighty sluice
#

here is teh drag script

#

yea i dont mind sharing it

#

making it open will allow me to actually improve it. it all works, but it's primitive lol

#

let me know whenever and ill toss it all at you!

novel summit
#

If I decide to use it, it would be in a commercial project. I'd love to see this developed into a nice little package and I wouldn't mind contributing to it myself.

#

@mighty sluice Do you think this system could also be used to define temporary wind effects, like an explosion force?

#

I tried doing that with my compute shader approach, but there's always some delay in getting data back from the GPU, so it wasn't great.

#

I assume there's no latency in this

mighty sluice
#

yea there's at most one tick of latency getting forces back out, but the way i have it rigged there should be no delay at all

#

interestingly, classic vector field fomulas could be added on-top of the grid system as extra wind with almost no extra cost (this could be used to define a vortex or tornado, for instance)

#

adding pressure into the system generates wind, so there's quite a lot of opportunity

#

@novel summit I'll probably be using this system for a ton of projects. it's going to take care of heat and odor exchanges between objects and the grid system as well (it's main purpose is actually a smell system for ml-agents xD), but yea, I would be happy to develop it into a package

#

having a modular system would be broadly useful i think (most people probably wont want to include smell in the sim, for example), so lets do it!

#

im also going to ham-fist water into the system

#

im uncertain how that will go lol

#

@novel summit regarding temporary wind effects, the "dragPoint" script can operate independently of the grid system, so doing a marching sphere cast that checks for dragPoints in the things it touches would be one easy way of making custom wind stuff

#

or for an explosion wind, a static sphere collider could be used as a trigger, and the relative positions of the drag points would determine the direction and magnitude of the wind that is applied to objects

mighty sluice
#

I am also interested in extending it to include different kinds of gasses, precipitation, as well as combustion

#

but that's more of a way down the road sort of ambition

mighty sluice
#

here's a few random breaks with about 1k rigid bodies

#

with the extra rb's, the cpu time is about 0.7 - 1 ms with no rendering

#

in order to address the performance of more RB's i would need to use ECS physics

novel summit
#

@mighty sluice On what CPU?

mighty sluice
#

my cpu isn't even being stressed lol, not in the slightest: ryzen 3900x

#

it's a beefy cpu

#

it goes as high as 16 ish percent, including all sorts of background processes from other apps

novel summit
#

Trying to get an idea of what performance to expect on mobile

lapis plaza
#

@mighty sluice I wouldn't count on DOTS physics to be any faster

mighty sluice
#

what aspect of performance are you concerned about, the grid system or the getting forces and acting on rigidbodies part?

#

oh @lapis plaza ?

novel summit
#

@mighty sluice More thinking about the base performance of the simulation rather than reading and applying it on rigidbodies

lapis plaza
#

it could be in some cases of course but I've only tested larger (more common) game scope levels with it and there the perf was way worse than with built-in physx

mighty sluice
#

@novel summit since i am updating the dynamic vector field every tick, it's sort of expensive. things can be batched with a longer tick rate, sacrificing accuracy but vastly improving performance. Ontop of that, if you chunk the grid dimensions correctly, it can fit within the RAM constraints you need to deal with

lapis plaza
#

I haven't done any proper benchmarks though but it does kinda make sense that physics engine with cache does get advantage on broadphase etc

#

I was actually about to evaluate (dots) unity physics package perf again but since Unity is likely to release new round of DOTS packages next week, I'll just wait for them to get out before trying anything

mighty sluice
#

interesting

#

I had assumed that if i can integrate the drag force application as a low level physics operation, i could get performance that way

#

still not totally learned about DOTS

lapis plaza
#

anyway, on the perf it probably boils down really on what kind of functionality you need from it. Unity itself claims dots physics should be quite performant on queries (raycasts etc)

#

actual physics integration, like movement and basic physics math is also super light, that's not the heavy part of the physics engine at all, it's all the rest

mighty sluice
#

right now the biggest visible bottle neck is that fact that i need to do thousands of rb.AddForceAtPosition() each fixed update

#

and i cannot multi thread that

#

(thought the calculations for it are threaded)

lapis plaza
#

anyway, when I tested the perf, I couldn't even make the dots physics run as high update rate than physx

#

(without it choking up)

mighty sluice
#

will be interesting to see if the new packages change things

#

the promise of thousands and thousands of joints and rigidbodies is what i'm after

lapis plaza
#

DOTS also doesn't currently scale well to 3900x

#

I actually get higher fps and less cpu load if I just limit all unity worker threads to 4-6 (instead of the stock 23 workers it would assign by default on 3900x)

#

it's still quite far from performance by default

#

basically this all boils down on having to pay so much extra for the scheduling overhead that it would be just more beneficial to run the thing in fewer threads

#

I'm sure they'll address this eventually but it is an issue today

mighty sluice
#

ill have to do some testing with the worker threads to see what my results are

#

still getting initiated into the ECS side of things

#

@lapis plaza any reccomendations for performance improvements on my AddForce() issue? Will I just have t accept the cost of 1500 or so such calls in a mono somewhere?

lapis plaza
#

other than not doing it on every physics step? 😄

#

there isn't any way to batch that on physx, you can batch stuff like raycasts, shape casts and transform updates to run in multiple threads but I don't think Unity API lets you do anything with the forces for that

#

of course if you have multiple addforces for same rigidbody for each physics step, you could sum those up yourself and only send one final force

mighty sluice
#

hmmm

#

@lapis plaza I need to add 3 unique forces at 3 unique points per rigidbody (at the minimum)

#

im not sure if i can even combine them in such a way

#

I would need to separate the torques and the linear forces that would result, recombine them, and then apply... i think...

lapis plaza
#

you can combine add force at positions

#

it's pretty simple

#

out of my head, you sum the actual forces and get the torques by doing crossproduct for each, then sum the torques, you end up with one addforce and one addtorque (or only one addforce at position I suppose)

#

@mighty sluice this is somewhat how I did add force at pos once:

void AddForceAtPosition(Vector3 Force, Vector3 Position, bool LocalPosition)
{
  PendingForceToApply += Force;
  if (!LocalPosition) 
  {
    Position = Transform.InverseTransformPosition(Position);
  }
  PendingTorqueToApply += Vector3::CrossProduct((Position - CenterOfMassOffset), Force);
}```
#

(it was for unreal)

#

that's not Unity code

#

but you get the point

mighty sluice
#

interesting, thanks! I'll give it a shot

lapis plaza
#

since you can do this math in threads, you could do the reverse for final force and torque to get it passed as single api call

#

basically pass just one force at position where you compute the position from torque

mighty sluice
#

ill have to spend some time wrapping my head around it lol

lapis plaza
#

you can easily verify the results too, just run the alternative code path for some mirrored rigidbody and you'll see the results will match

#

there can be some digit differences on the final result due to floating point accuracy (math being done in different order / with different optimizations) but overall result is the same

mighty sluice
#

what happens to the pending force?

#

PendingForceToApply

#

is that unreal syntax?

lapis plaza
#

I've just integrated it myself into angular velocity and then used that to drive the rotation

#

but basically if you just do AddTorque for that rigidbody with that value (and same with AddForce without position for the pending force), it will have same result as with AddForce with position offset

#

basically that snippet was from my physics movement component where I ran a simple physics solver to compute the movement. it's basically a copy of their similar logic on their character controller, it just didn't do anything but basic forces (had no concept of torque)

mighty sluice
#

if it works i'm gonna love it!

lapis plaza
#

it does

mighty sluice
#

😄 i believe you lol

#

perhaps i should say if i can get it working

#

the whole add force thing is one of the most repeated and expensive operations i want to overcome

#

and since nearly everything has aerodynamic drag that requires multiple addforceAtPosition()s, it will be a big saviour

lapis plaza
#

well, do let me know if it saved you any cost if you combine them

#

on c++, combining this yourself wouldn't really save you much time since physx does it anyway internally

#

but with Unity you do pay for interop overhead for these

#

so that way, you could actually save a bit of time (but like mentioned, would be curious on your results)

#

basically you could benchmark the difference just by omitting all but one addforce at position per RB as that would tell you immediately if you could be getting some gains with this

mighty sluice
#

ill try that now

#

looks like it shaves off about .2 of a millesecond

lapis plaza
#

total? 😄

#

well, that's not a big win

mighty sluice
#

not huge, but that's only with 500 or so rbs

#

if and when i can scale that up, it might make a bigger difference

clever loom
#

Hello. I'm making a bowling game and my sphere when I shoot it when its collider hits the plane collider, it shakes and does not roll. (Its fraction is low and it has rigidbody. Idk why, but it gets stuck like in the plane and shakes madly)

foggy rapids
#

set collision detection between the ball and plane to continuous

#

reduce angular damp to get more mass converted to torque

charred onyx
#

I am currently following "Simple Car Controller in Unity Tutorial" and my car asset keeps falling through plane. Plane is under my asset, and I have same settings as him. I also tried with cube , with box collider but still same result

charred onyx
#

Fixed, I added riggid body to a subfolder and its only needed at the main one

mighty sluice
#

each rb conducts with the atmosphere in its local grid, so everything will eventually equalize with everything else if if it a closed system

#

I should probably vizualize the atmopshere grid temps too

clear belfry
#

Quick question, I've got a few gameObjects that are purely there to catch some physics.raycasts. Is this the proper way to make it so these colliders don't so anything except catch rays that are specifically cast on that layer?

#

The three layers in the top row are the ones I'm talking about (bottom 3 on the left row)

graceful meadow
#

it's decent but you could also use static trigger colliders for receiving raycasts

#

depends a lot on your project though

clear belfry
#

The colliders I want to click are children of gameobjects driven by physics, can a child of a non-static be static?

graceful meadow
#

yep, it will move based on how the parent moves

#

if you've already got the layers working theres no need to switch implementations tho

clear belfry
#

That's true. I've been abusing the layer system plentily I guess, might as well keep going. One more question though, just so I understand, can I still change the transform of a static child or will it just 'freeze' at its local transform?

#

Or does static only affect physics

graceful meadow
#

yep it will

#

static just means it wont apply forces when it moves

#

any colliders without a rigidbody are parented to a hidden static one at world origin if it helps

clear belfry
#

It's not doing what I expected... I'm asking for the name of the hit result from a raycast that was set to a specific layer. Somehow it grabbed an object from another layer (passing right through the layer I wanted)

#

layer 17 is the second to last layer in the left column in my previous picture of my physics layers

foggy rapids
#

you need to do it both ways

#

you've only disabled default -> 17
also gotta disable 17 -> default

lapis plaza
mighty sluice
#

I might have a use for that! Making stabbing physics is tricky due to the way contacts persist; I was looking for a way of nullifying the actual effect of certain collisions while preserving the event itself

#

(for example, if i make a joint on contact between a blade and a stabbable collider, even setting the configurable joint to disallow collisions between the newly connected bodies will not affect the already extant collision. I am having to update the layer or tag or collision detection settings of either of the rb's to get the collision gone)

#

@lapis plaza are you aware of anything i could do to address that problem without swapping editors? xD

#

i wrote some predictive stabbing stuff which works, more or less, but it's a god awful mess that fails under certain edge cases

#

the sad thing is that by the time get the OnCollision event, forces have already been integrated to the RB

#

Ideally i could just check the normal and the force of the collision between two objects in OnCollisionEnter() to determine if a penetration should occur (creating a configurable joint to handle it), but alas...

lapis plaza
#

@mighty sluice you could just conf those two objects to not collide and have extra trigger for detecting them penetrate

mighty sluice
#

conf?

lapis plaza
#

or.. if you only have few items you need to check for, you could do some collision check manually between them while they are near eachother

#

configure

mighty sluice
#

ideally they do collide under certain conditions (like hitting with the broad side of the knife)

#

there's also the force calculation that i want to use to determine penetration conditions, but i suppose i could calculate those on trigger entry

#

I would like most things to have a stabbing threshold, so a really modular and general purpose solution is what i need, and so at all times i basically need to run checks for all awake rigidbodies which have stabbing components

mighty sluice
#

one solution that i liked was storing previous velocities so that i could essentially move the transform to where it ought to be, even after it has been stopped for a single tick (which also required flip flopping the collision detection method)

royal walrus
#

Is it wrong to @ admins?

#

I'm asking because I'm wondering if it is possible to parent a Rigidbody to another one

lapis plaza
#

yes

royal walrus
#

Namely, if the parent rotates 1 radian on the Y axis (global), the child will do the same

lapis plaza
#

(it's wrong)

royal walrus
#

A'aight.

lapis plaza
#

@royal walrus check #📖┃code-of-conduct: ```We ask that you do not:

  • Direct message any Discord Admin or Moderator asking for help with any technical matters. Private messages should only be for moderation issues.```
#

oh that was DM

royal walrus
#

Technically it's not a DM, it's a mention, but sure. Sorry

lapis plaza
#

- Send unsolicited private messages to anyone. Use common sense and do not @ people not in the conversation.

#

this includes admins

#

@royal walrus to your actual question, you mean like you want to merge two rigidbodies together so they move as one?

royal walrus
#

Not entirely

lapis plaza
#

not sure if I even understood your question

royal walrus
#

I still want both objects to be able to move independently

#

Well

#

Alright

#

I want the following:

lapis plaza
#

parent of rigidbody doesn't matter then

royal walrus
#

Object A is on top of Object B

lapis plaza
#

it will simulate itself separately from it's parent

royal walrus
#

If Object B moves, since Object A's collider has a physics material, it will move with friction

#

If Object B rotates, Object A ought to as well

lapis plaza
#

what

royal walrus
#

The problem is, the position moving is working but not the rotation.

solar bronze
#

he wanted to make them move same rotation and undo that with like a key or something

royal walrus
#

No, not that

he wanted to make them move same rotation and undo that with like a key or something
@solar bronze

#

Imagine you're in a submarine

lapis plaza
#

yeah I don't really understand this at all

royal walrus
#

If the submarine moves, you move along with it

#

Right?

lapis plaza
#

so we are talking about moving platform now

solar bronze
#

but you want to exit the submarine too

royal walrus
#

so we are talking about moving platform now
@lapis plaza Yes, I'd guess so

lapis plaza
#

hierarchy doesn't really do anything in this context but if your rigidbodies have friction, it would work as is to some extent

royal walrus
#

I'm working in 3D space, btw

lapis plaza
#

in general though, this is a wrong solution 9 times out of 10

royal walrus
#

hierarchy doesn't really do anything in this context but if your rigidbodies have friction, it would work as is to some extent
@lapis plaza Yeah, I noticed that parenting does nothing if Rigidbodies are involved

lapis plaza
#

usually you'd want to run a local simulation inside the vehicle and not have it affected by the actual vehicle movement

royal walrus
#

I've tried that but I think that's a rather shoddy solution (no offence)

lapis plaza
#

it really isn't, it's most stable solution for this type of a problem

#

game physics is always hacks

solar bronze
#

true

royal walrus
#

I know

#

But still...

lapis plaza
#

if you have special requirements for objects moving inside the vehicle, then that's another thing

#

also, if your rigidbody inside the vehicle is character controller, that's usually wrong approach as well if you need something stable

#

you'd be better of with some kinematic type char controller instead, unless you really need it to act like a physics body

shut wind
#

Hi, I have a vehicle with arms that are attached with hinge joints in the front and back. I've given them quite a bit of force on the motor attached to the joint and told it not to freely spin, however when I move the vehicle it causes the joint in the opposite direction of movement to slowly move downwards, any ideas?

brazen cedar
#

Is there any replacement for Physics2D.RaycastNonAlloc() using PhysicsScene2D?

low phoenix
#

hi
I'm very confused on how to configure this asset can someone help me out?
its a third person controller and the sensitivity is high, I turn it down and its not changing
I don't know if I'm changing the wrong value
(Not really new to unity, but I don't use it at all)

viral ginkgo
#

@low phoenix I assume this is a public value
Perhaps like so:
public float sensivity;

and you change in code am i correct?

#

If so, you have to change it in inspector view

low phoenix
#

well its a setting in the prefab

#

I keep changing it and it's sensitivity is still fast

real cloud
#

Anyone has a idea why my player starts to fly in an tilted angle when it collides with a wall? Its supposed to fly in straight line, only thing i can think the COM gets offset.

frigid pier
#

Don't mix move methods physics and non-physics ones. You are overriding movement but doing nothing to negate actual rotational momentum of the rigidbody.

real cloud
#

oh, yeah, well i will try to fix it, thank you.

whole marten
#

k

#

im new asf to unity

#

and i wanna make a physics based game like human fall flat

#

how do i get that ragdoll game feel

viral ginkgo
#

@whole marten That kind of ragdoll is called an "active ragdoll"

#

You add forces or forces and torque on a ragdoll to animate it

#

You can have a copy of the same character with animator and no physics, they you can read this characters limb rotations or positions to animate the ragdoll one with forces

opaque vine
#

Is there any direct downside of using rigidbody.AddForce in Update instead of FixedUpdate? Or is it just bad practice?

foggy rapids
#

try it and see

eternal crypt
#

im trying to get a random quaternion to get bullets that shoot out in 360 degrees from a source. right now it only shoots out in a half sphere. any ideas why this might be? heres the code: Quaternion dir = Quaternion.Euler(Random.Range(0, 360.0f), Random.Range(0, 360.0f), Random.Range(0, 360.0f));

neat thicket
#

@eternal crypt What's the range of angles of the half sphere ?

foggy rapids
#

eulers are from -180 to 180

#

thats why it's a half sphere

eternal crypt
hollow echo
#

Random.rotation is a thing

#

Also, not sure why the original code would not work. I am fairly certain it would

eternal crypt
#

i get the same result with Random.rotation xl

hollow echo
#

Then you must be confused

#

Or doing something else to modify it

royal walrus
#

What is the correct way for adding colliders to an inverted mesh?

#

I have a mesh of a submarine interior and was wondering how to go about this.

lapis plaza
#

either bunch of individual colliders (compound) or mesh collider if it's static

royal walrus
#

Yes but should I add primitive colliders in unity one by one or in my modelling program, split all meshes into tetrahedrons and add convex mesh colliders to each one in unity?

lapis plaza
#

whatever works for you

#

I mean, it's just a 3D space, same rules apply as with larger rooms

#

don't try to treat it as "inverted mesh"

foggy rapids
#

i've always wonderd if slicing the mesh in half and exporting each half as a convex collision mesh would fix that

eternal crypt
#

@hollow echo i have tried many things but im definitely not confused. the code i used last time should work for 360 degrees on 3 axes no? im not modifying it elsewhere. im simply creating the random rotation and then adding forward force

#

here's an interesting screenshot though that might help. you can see the bullet i've selected has a 'forward' that should be making it travel beyond this plane but it does not. all of the other transforms that are not along the plane have correct forward transforms in the direction of their travel.

viral ginkgo
#

you can also use Random.onUnitSphere for velocity direction @eternal crypt

eternal crypt
#

Ill try it. Im using that elsewhere but i wouldve though that the way i was doing it woulda worked xD

chrome hound
#

hey guys do you know why when im walking around an object looking directly at it it jitters?

#

using first person character controller

#

doesnt matter if its a rigidbody or not its always the same

fallen frigate
graceful grove
#

Hi all
Why If I have platform (non-moving) object on this balancing right (object have rigidbody) but If platform moving then object sliding on ground? The balance is done through the change of centerOfMass
https://ctrlv.tv/5kUV

rancid lance
viral ginkgo
#

@fallen frigate You wanna do that dani robot?
You probably wanna do the feet ik related video posted just above
And treat the robot body as a floating cube, make it move with force so it also gets affected by external "disturbations"

#

Feet can also be defined as rigidbodies, (not upperleg/lowerleg, they are controlled by IK)

fallen frigate
#

any advice on how to use it with bones on my model for the legs?

#

like a rigged peice

#

im also re-rigging and weight painting the model

#

also changing the legs and head so i can atleast get fast ik down

viral ginkgo
#

Fast IK the asset?
@fallen frigate

#

If you are using that asset, just put the script on the lowerleg or foot
and set ik chain to 2
then place your ik poles

#

Example scene has examples

old fiber
#

just realized ForceMode doesn't default to Impulse. No wonder my force-based movement has been so sloppy lmaooo 😅

stoic moat
#

So, I'm making a top-down spaceship shooter, 3D, locked to 2D, and am making the ship and everything else move using physics. So far, so good, my question is, how would I go about making the level boundaries? If I use colliders, the ships bumps against them and the camera moves past them. Any suggestions on ways I can approach this? I'm still learning both Unity and C#.

brisk dock
#

Hello guys, this has probably been asked a million times, but I find the documentation confusing. I have a simple prefab. It has a RigidBody2D which is marked as Kinematic. It also has a sphere collider. I don't want this prefab to collide with anything, but I need its collider because I'm using Physics2D.OverlapCircleAll to detect it.
Currently I'm moving the rigid body by using its transform in Update? Is this wrong considering the needs I described above? Should I use FixedUpdate and RigidBody2D.MovePosition instead?

eternal crypt
#

@stoic moat you could make the camera object a child of the player object and when the collision occurs the camera will no longer go past the bounds

stoic moat
#

@eternal crypt I've tried that, but the player reaches the bounds before the camera... Maybe colliding the camera instead of the player? I'll try that, thx!

eternal crypt
#

uhh well dont collide things that arent what you want to collide. you really want your player colliding with whatever it should, then the camera follows the player

#

lets see your scene setup or some code?

stoic moat
#

Only code I have is for moving the player

public void Move()
    {
        var _mov = _controls.Player.Movement.ReadValue<Vector2>();
        var _movement = new Vector3
        {
            y = (_mov.y > 0) ? _mov.y * speedForward : (_mov.y < 0) ? _mov.y * speedBack : 0
        };

        // Moves the player ship forwards or backwards
        rb.AddRelativeForce(_movement, ForceMode.Force);

        // Rotates the player ship along the Y axis
        if (_mov.x > 0)
            rb.AddTorque(0, 0, rotationSpeed, ForceMode.Impulse);
        else if (_mov.x < 0)
            rb.AddRelativeTorque(0, 0, -rotationSpeed, ForceMode.Impulse);

        if ( rb.velocity.magnitude > 3 )
        {
            // Play Engines VFX
            _enginesVFX.SendEvent("OnPlay");
        }
        else if (rb.velocity.magnitude < 3 )
        {
            _enginesVFX.SendEvent("OnStop");
        }
    }
#

The player collides properly with the boundaries, it's just that the boundary gets all the way to the middle of the screen

chrome hound
#

how do i make my character slide less when it stops walking?

slim olive
#

Friction maybe

tepid wyvern
#

I have a marble game, with some animated spinning blocks to knock the marble off the platform...
... but the marble is passing through the spinning collider.
I tried continuous dynamic and other modes, I cant seem to get the spinning block to knock the ball around without clipping through it

#

How do I keep the marble/player from passing through the other moving colliders?

#

@chrome hound mess with the Drag and increase your speed

chrome hound
#

@tepid wyvern its not a rigidbody

tepid wyvern
#

but it's sliding??

chrome hound
#

yes

#

its may be code fault

tepid wyvern
#

This spinning cube is supposed to knock the rigidbody Ball off the platform.... but the ball clips through it

#

I can't figure out how to make it work so that the cube knocks the ball off

#

Static objects are no problem, but moving/spinning objects seem to be an issue

#

sphere/player collider rigid is set to Continuous. & spinning cube is continuous dynamic.

Any ideas on how to fix this?

#

do I need to code an OnColliderEnter() AddRelativeForce()?

fringe laurel
#

anyone finialliar with Aabb?

teal valley
#

Why do my character change the size when I try to walk with D or A? I have no errors in any script and everything is correctly coded, I think the problem is that the area is large when I select the player with the rect tool. How do I scale down the area with the rect tool without making my character smaller? @ me if you answer Thanks 🙂

hexed horizon
#

At what distance/floating point precision does unity physics (physx 4.1) begin to misbehave, say at 50,000 units from origin (5 milimeter accuracy)? HDRP deals with the camera issues, but I am curious at what distance does physics start falling down and where will the issues first show themselves?

lofty nimbus
#

where exactly does unity apply a force? 🤔 From center, behind mesh, uses a pull, does it depend and how so?

viral ginkgo
#

@lofty nimbus from whereever 0,0,0 is in local coordinates
its often the center of your shape

#

you can apply force at different positions via AddForceAtPosition

lofty nimbus
#

ah, so it acts as a vector from the world origin. That makes sense.

lapis plaza
#

@lofty nimbus it is applied to the center of mass of the object

#

COM is approximated by physics engine, on simple objects like cubes and balls it is always in the middle. If your rigidbody has convex collider or compound collider (multiple colliders) it is harder for you to estimate the exact COM location but I think physics debugger could show it

lofty nimbus
#

k, thanks

lapis plaza
#

Other way to think of this is that add force just pushes object in linear fashion if there are no external forces like friction on some side etc

#

If you add force in some position instead, it will introduce additional torque to the rigidbody

viral ginkgo
#

@lofty nimbus local coordinate means in shape's coordinate space
0,0,0 is center of mass in cubes and spheres for example

sacred iris
#

Quick question, what is the direction component of Physics2D.CircleCast?

graceful meadow
#

it drags a circle across the scene, so the direction tells it which direction to perform the drag

#

circlecast is just a thicc raycast

sacred iris
#

ohhhhh

#

it all makes sense now

#

my third eye has been opened

hexed horizon
#

any thoughts on this? At what distance/floating point precision does unity physics (physx 4.1) begin to misbehave, say at 50,000 units from origin (5 milimeter accuracy)? HDRP deals with the camera issues, but I am curious at what distance does physics start falling down and where will the issues first show themselves?

glacial notch
#

If I may ask, is it true that the Wheel Collider component as part of the Unity's PhysX engine requires the wheels (and likewise the vehicle model) to face the +Z direction?

#

So if your vehicle model faces a different direction, the Wheel Collider will misbehave?

foggy rapids
#

@hexed horizon I'd guess the same distance as when unity warns you in the inspector (100,000) since physX will end up using the same type anyways (Vector3)

hexed horizon
#

my understanding is you runto physics precision issues WAY before 100,000?

foggy rapids
#

I'd recommend devising an experiment to test

hexed horizon
#

ya I will, I figured this would be common knowledge tho 🙂

lapis plaza
#

@hexed horizon it's impossible to estimate what would work for your use case

#

it totally depends on your game needs, for some games small inaccuracies are tolerable where on some other games it could fully break the game logic

#

physics simulation needs differ a lot

#

for example some games don't even need rigidbody sim but only queries (raycasts, sweeps etc), physics can work in totally different scales and your game could have totally different camera angles where some (top down etc) could hide the artifacts better

#

only way for you to know is to just test it on your use case yourself

hexed horizon
#

my physics simulation will be at human scale and walk/run speeds for example.

lapis plaza
#

again, it's super simple for you to test

#

this could fail in totally different ways depending on your char controller even

hexed horizon
#

I would have thought camera issues would be related to render not physics tho?

lapis plaza
#

these are two separate things that both have issues when you go further from origin

hexed horizon
#

I am using HDRP with a relative-camera

#

my main concern is with rigidbody collisions and my in-game building/construction system.

lapis plaza
#

what I try to say... you have your setup there, just slap something further from world origin and just see where it starts to break for you

#

it's like thousand times simpler for you to test than us to estimate what could happen on your specific systems

hexed horizon
#

I am still mostly in the planning stages. Just trying to get a sense for what kinds of issues to look and at what scales those issues arise. But I hear you, ill plan to test.

young igloo
#

hello! anyone there?

#

aight so i added a capsule to do my newly made project, below it is a cube with box collider
i added rigidbody and a camera that follows the capsule
i hit play
and the x and z values go crazy
they're supposed to be 0
but they're just constantly changing to something like 4.923533e-09
there's no movement script
just a capsule with rigidbody
anyone know why is this happening?
i tried adding a physics material with friction like 20, still have the same results

chilly hemlock
#

can you send the pic of the rigidbody's inspector

young igloo
#

sure

#

the x and z values are supposed to be zero

chilly hemlock
#

have you modified these values somewhere in a script

young igloo
#

nopr

#

nope*

#

there's no movement script attached to it

#

its just a rigidbody, with a camera that follows it

chilly hemlock
#

try to disable the rb during play and see if it still moves or disable the collider to see if it still moves

young igloo
#

hmmm i will try that

#

nope it doesnt move

chilly hemlock
#

in which case

young igloo
#

when i disabled the rigidbody

chilly hemlock
#

when you disabled the collider and the rb was still enabled was it moving?

young igloo
#

yep

#

the x and z values were a perfect 0 when i did that

#

went right through the ground

chilly hemlock
#

so it was not moving when you disabled the collider

young igloo
#

it was

#

rigidbody caused it to fall

chilly hemlock
#

but when you enable the collider it moves on the X and Z right?

young igloo
#

ok lemme put it in a sentence, if i have the rigidbody on and collider off, the capsule falls right through the ground (with no change in x and z values) and when i have the rigidbody off and collider on, it stays in one place with zero movement

chilly hemlock
#

make sure that the collider isn't too small, because if it is then rb's tend to "dance"

young igloo
#

its the exact same size of the capsule, scale 1x1.5x1

chilly hemlock
#

hmm, i don't know what might be causing it then. Sorry maybe someone else can be of more help

young igloo
#

yeah np, ty for ur time @chilly hemlock

inland snow
#

Ragdoll goes crazy on high velocities (pics ahead):

#

any ideas?

stuck bay
#

weather you are using HDRP or not has nothing to do with physics.

#

@lapis plaza

lapis plaza
#

these are two separate things that both have issues when you go further from origin
@stuck bay

#

(so yes, that's what I was trying to tell as well

peak flame
#

Hey guys, can someone help me? Im working on a 2D Platformer jump and run, for a reason my character beginns to crouch everytime he walks against a Collider if its on Trigger. What could be the reason?

mighty sluice
#

i want this

gusty crater
#

Hi there, friendos and friendoreens!

I've got a problem with my jumping algorithm... Can someone help me?

quasi wren
#

I hope this is the right area to post about Unity Joints but if not please redirect me. My question is in regards to the way joints like the configurable joint, hinge joint and likely others will break off of the root when spinning. I have limits in place and lock motion in set axis. items are anchored connected bodies and so on but when spinning around the joint In one project the item brakes away from its pivot until I let go? Any idea why that happens?

#

Note I have two projects and in one the joint breaks but the other its fine? As far as I can see the only difference is that one is networked?

quasi wren
#

Well... with no response I will try elsewhere and check back again in a few hours.

buoyant aurora
#

How would one make tank tracks, without each tread link being separate and the gears and wheels still having physics?

#

Battlefield style!

quasi wren
#

Maybe use cloth dynamics on the tread?

buoyant aurora
#

Ok, how would the tracks move along the gears?

viral ginkgo
#

@buoyant aurora In gamedev, you dont try to simulate things as they are
You come up with cheeky ways to fake it when it's not practical to simulate something just for eye candy

buoyant aurora
#

@viral ginkgo Thats a surprisingly good answer... thanks man, I will come up with an "illusion" for tank tracks!

viral ginkgo
#

You might wanna thing about zero friction boxes attached to eachother with hinge joints
boxes for track parts

#

But even thats overkill

#

I'd just make wheels with suspension and draw the treads precedurally (You could also move a texture on the thread)

#

Wheels could be rotating wheels or zero friction cubes (if its cubes you handle friction and movement forces)

#

@buoyant aurora

buoyant aurora
#

Thanks man!

pale sinew
#

I'm trying to create a tractor-trailer setup with more arcadey physics. I currently have the front of the truck as a sphere controlled by the player and a trailer attached with a hinge joint tailing behind it. Works fine so, far BUT I want to create physics so that the trailer carries a lot of momentum and when you stop the truck the weight of the trailer should keep moving and sliding around. How would I setup this?

pale sinew
#

Like I need to transform the momentum of the trailer swinging behind the truck into some sort of .addForce() applied to the the truck

pine warren
#

My physics is weak. If I have a object moving at a known velocity, and I want to apply friction. To counter the velocity. How to I compute the force to apply to the moving object? All I know is the velocity and mass of the object in question. Most examples I find online only consider scenarios where you start to move a stationary object and figure out the force necessary to start sliding. But in my case, the object is in a vacuum and suddenly starts sliding.

#

For various reasons I'm not using rigid bodies and built in friction models, as I'm doing a kind of hover-craft-thingie.

gusty crater
#

Hello acquaintances!
I got a problem with basic physics calculations. 🙃
I want to write some custom gravity code and to let an object jump.
I calculate the parable like this: p(t):=-9.81*t²+4
If want to let the object start at (t_0=-0.63855|h=0) and let it travel along the parable.
My idea is to provide the object with an initial velocity-vector v = (1|12.53) (which should be a tangent to p at t_0).
The gravitational pull should do the rest: In each update, I subtract 9.91 * Time.deltaTime from v and reapply the velocity-vector to the object's position.
Somehow, my object travels in a parable, but it's twice as tall. (It reaches (0|8) instead of only (0|4).)

If v was (1|8.86), my object would meet (0|4). But why? I cannot figure out where this number comes from.
I could just use the found scaling-factor, but I don't know whether that's only a fix/hack for my computer, while I want this game to run on others, too.

Any idea?

viral ginkgo
#

yPosition at t = p(t):=-9.81*t² * (0.5f) +initialYVelocity * t + initialYPosition
@gusty crater
Thats how you should be calculating yPosition

#

i think you just missed "1/2" in formula: "(1/2) * a * t^2"

quasi wren
#

What's the best place to get help with Unity joints? Its not really programing but I didn't get any dialogue when I asked here?

foggy rapids
#

joints are voodoo

#

joints and vehicle physics.

quasi wren
#

Any Voodoo masters around who can help with a spell then?

#

I have one scene where joints work perfectly. I'm using a configurable joint in two areas and hinge joints in other areas. The item has an Animation set to cull Update transform and to move the object I generate a hinge joint on contact and pivot the item around an axis. This all worked fine with limits and locked motion and what not but when I duplicated the process in another project everything broke and the item breaks away from its axis when rotated?

#

I think part of the objects problem is it spins around its center axis instead of the pivot point or joint axis.

gusty crater
#

Thank you, @viral ginkgo , I was 100% certain my formula was correct, but obviously it wasn't. Thank you very much! I still got the wrong values, but as I was re-explaining my problem in this message, I found my error! 😊

viral ginkgo
#

@gusty crater You will never get the absolute correct value though

#

Because unity simulation will never be as accurate as your analytical solution

#

According to unity, your projectile moves in line segments
Makes 50 line segments per second if you know what i mean

#

You'd have to run simulation infinite times per second with closing to 0 time interval for unity result to meet your equation

peak crypt
#

does anyone know of a formula that i can use to reduce a velocity in a certain abstract direction?

#

this is the best way to explain it

#

the "direction to reduce in" vector will be unknown in terms of its x y z, but i want to know a formula that would let me reduce a velocity or vector to 0 (or whatever value) in that direction

#

i believe this might have something to do with vector projection?

lapis plaza
#

of course overriding velocity for physics sim can have bunch of undesired effects

#

like, you could actually force your objects to sink into walls etc

peak crypt
#

ive seen a forum post where someone used Project and grabbed an objects forward, right and up velocity and then reduced their forward velocity, and then added all 3 vectors back together.

#

but i dont know how id do something like that for an abstract direction

gusty crater
#

@viral ginkgo Yeah I both know about that problem and tried it out earlier. I got several different values when sampling in a small test-environment... But let's just call these variations "realistic noise". 😆

viral ginkgo
#

@gusty crater Thats not like noise tho, it will always be off with same offset (if your deltatimes are same)

#

You wont be able predict trajectories or anything like that unless you are fine with that much of error
It probably can be somewhat compansated though

glacial jolt
#

@peak crypt projection would be the function to get what you want in your diagram. For your second question might need another diagram, or a use case. If you want to take in a forward and right vector and get the corresponding up, cross product is what you're looking for: https://docs.unity3d.com/ScriptReference/Vector3.Cross.html

pale sinew
#

🤔 I guess let me go simpler: How would you code a component so that it would be influence by multiple forces?

i.e. imagine a deep-sea diving game with an old diving bell setup. One player controls the diver, but another would control a crane connected to the diver that would also influence it's movement

buoyant aurora
#

What is wrong with Unitys Wheel Colliders?? Jesus Christ

#

Got a Tank with a RigidBody, mass is 31 tonns. There are wheelcolliders in the children, with default settings and the tank freaks out as soon as I hit play

#

Changing the wheelcollider's settings doesnt do a thing either...

kind obsidian
#

How do I get a collider 2D that has a "ExampleName" component with the highest Z-index, and I want to ignore all other colliders that don't have the "ExampleName" component, this is cause i want to have a different terrain sound depending on the ground the player is walking on

#

nvm i can just loop through the colliders

kind obsidian
#

In my 2D game, I use raycasting to get the current 2D terrain that the player is walking on (so i can adjust the footstep sound effect depending on the terrain e.g. wood, carpet, water), but it's not working.

Player class:

    void RaycastTerrain() {
        RaycastHit hit;
        var terrainHit = Physics.Raycast(
            transform.position,
            Vector3.forward,
            out hit,
            20,
            1 << LayerMask.NameToLayer("Terrain"));
        if (terrainHit) {
            Debug.Log("Hit");
            currentTerrain = hit.collider.gameObject.GetComponent<TerrainInstance>().Terrain;
        }
    }

My terrains have layer "Terrain" and my Debug.Log within terrainHit do not fire.

Player Z coordinate = 0, terrain Z coordinate = 5.

#

oh i see why, it's probably cause i'm using 3D raycast and my terraain has a 2D collider?

#

ok I made it work, yay

    void RaycastTerrain() {
        var hit = Physics2D.GetRayIntersection(new Ray(transform.position, Vector3.forward), 20, 1 << LayerMask.NameToLayer("Terrain"));
        if (hit.collider != null) {
            currentTerrain = hit.collider.gameObject.GetComponent<TerrainInstance>().Terrain;
        } else {
            currentTerrain = defaultTerrain;
        }
    }
north egret
#

can some 1 help me pls

#

im working with 2d joints

#

im trying to make suspension

#

im using a sping joint

strange raven
#

well doesn't that make sense? The joints are connected at the exact center of the rigidbodies (im assuming) @north egret

#

the joints would need to be connected closer to one of the sides for the effect that you want

north egret
#

i dont understand

#

the rigidbodies rotate around the anchor points

#

u mean ill have to move the anchor point closer to the sides?

strange raven
#

which isn't how real life joints are connected

#

this is how you would need it to be for the effect that you want

north egret
#

i know

#

i want it like dat

#

it just seems to rotate

#

im pretty new to it

#

i havent worked with joints in a while

strange raven
#

then I would move your anchor points around

north egret
#

like where?

#

to the right side? left?

strange raven
#

anything but (0,0,0)

north egret
#

oh ok

#

imma try it

#

later

#

if i say move it like in ur drawing wouldnt it just rotate around that point?

strange raven
#

yes

#

that is how real life joints work,

north egret
#

oh ok den

#

im trying to make suspension

strange raven
#

if you have two cubes connected by a string, they will rotate around the strings connection point

north egret
#

but i dont want them to rotate

#

i want them to stay stuck

#

like suspension is

strange raven
#

oh now I see what you want...

north egret
#

like suspension

strange raven
#

are there not tutorials on 2D car-like suspension ?

north egret
#

i could use the wheel joint

#

but i dont wanna

#

i want it to be put anywhere

#

ok imma do some research

peak crypt
#

does anyone know what im doing wrong with adding torque? this is my code

Rigidbody.AddTorque(transform.up * Input.GetAxis("Horizontal") * 8f, ForceMode.Force);
#

the rigidbody will start turning in the direction i input, but itll be slow and then suddenly be too fast

#

the rigidbody has a mass of 1 and angular drag of 2

buoyant aurora
#

Multiply by Time.deltaTime

#

@peak crypt

peak crypt
#

the rotation still is behaving weird

buoyant aurora
#

Please explain in detail.

peak crypt
#

sorry. yeah so, im trying to replicate a car turning left and right without using wheel colliders. so far, adding force to move forward/backward works fine, but rotating is behaving weirdly. when im not multiplying it by Time.deltaTime and hold left to rotate, it will initially rotate very slowly then suddenly jump up in speed and rotate too fast, and im unable to rotate it the other way when holding right.

buoyant aurora
#

Are you calling that function in Update?

#

Or line of code

peak crypt
#

yes, but in FixedUpdate none of my inputs are picked up

#

should i get inputs in Update and commit calculations in fixed?

buoyant aurora
#

That is unnecessary, keep them all in Update

#

I made a car too a while back with wheel colliders, called everything in Update and it worked fine.

peak crypt
#

could it have something to do with angular drag?

#

i tried it with angular drag of 0 and it would turn fine, but it would continue turning even after letting go

peak crypt
#

another development, my AddTorque() does nothing unless my vehicle is moving. is this normal?

#

by 'moving', its velocity is greater than 0.

buoyant aurora
#

@baito sorry for late answer :D, but you do know AddTorque() is for rotation?

#

Im in school atm, so answering is a little hard

ocean pivot
#

How does AddForce even work? Where does it add the force, where can I read it, where can I remove it?

slim olive
#

vector 3

ocean pivot
#

Yeah, but like

#

Theres no GetForce to get the currently applied force, so where is it stored and how would one change it?

buoyant aurora
#

Its in the RigidBody velocity I think.

#

yea, its in velocity

#

you can assign the velocity to a Vector3

#

and then read from that Vector3

#

@ocean pivot

formal egret
#

you will need to calculate manually to get the right results because force will change depending on the mass of the object and acceleration.
the equation . is this F(net force) = m • a

buoyant aurora
#

Yea what he said!

ocean pivot
#

@buoyant aurora But it's continually applied

#

How would it be in velocity then, since that slows down

buoyant aurora
#

youre right my bad

ocean pivot
#

@formal egret What does AddForce do exactly? It seems to imply it keeps adding that force, but gives no info about where to read the currently added force or how to modify it.

formal egret
#

A force can cause an object with mass to change its velocity to accelerate. Force can also be described intuitively as a push or a pull. and from this definition you will understand that it changes the velocity depending on the mass as the question i sent above you will understand that you will need to calculate the objects force to get the right applied force on it.
also the physics engine in unity can calculate the velocity but with any mass applied the example of that is when you set a rigidbody to kinematic you are still able to move the object but if you did a small a calculation you will find that force applied is not what the velocity is giving you

ocean pivot
#

Sure

#

I just mean like... if I use AddForce(new Vector3(1,0,0))

#

It notes "Force is applied continuously along the direction of the force vector."

#

So it can't just be setting velocity when I call AddForce, because then that wouldn't be continuously applying the force, it would apply it once

#

It can' tbe setting acceleration either, because thats what ForceMode.Acceleration is for

#

So what is it setting

formal egret
#

when you use the ForceModeAcceleration you ignore the mass of the (Add a continuous acceleration to the rigidbody, ignoring its mass.) object you it just add a calculation like when you convert from radians to degrees

ocean pivot
#

Seems it actually just sets velocity, so the description is supremely confusing 😄

#

I guess it's not technically untrue, but it could be explicit in thats what it's doing

#

Thanks

old estuary
#

hi guys, im developing a game for my final project at school, but i cant fix this problem, in the editor everything is alright, but when i hit play the charecter is floating, i would be gratefull if anybody could help me

buoyant aurora
#

Character Controller settings`?

old estuary
buoyant aurora
#

How big is character controller in your scene?

#

does it go below your character's feet?

old estuary
#

yeah i got some help already, it was that

#

but ty

north egret
#

can some1 help me is der a way to make fixed joints stronger pls

#

if not is der a way to make an actualy spring cuz unitys spring joint is a joint which rotates and i dont want dat i only want a spring no rotation

viral ginkgo
#

@north egret What are you making?

north egret
#

i want to make like suspension(not using wheel collider or wheeljoint)

viral ginkgo
#

@north egret You could check out configurable joints

#

You can lock rotation, x,z movement and control y axis movement only

north egret
#

how would i do that?

viral ginkgo
#

you should be able to set rotation axices and linear axices free, limited locked @north egret

#

You'd wanna lock everything and make linear y limited

north egret
#

in the configurable joints?

viral ginkgo
#

Yea

north egret
#

ok imma try it

viral ginkgo
#

And then set dampen and spring bigger numbers for linear y
I don't exactly know where though, i am not very good with conf. joints
You just gotta see and adjust the variables and try it until it works

sweet flicker
#

Hi guys,

I can drive an omni wheel as if it were a normal wheel, but an omni wheel consists of several rubber parts that can rotate and thus provide the omnidirectional effect.
I tried to give these rubber parts a wheel collider too, so then I have several small wheel colliders in a larger wheel collider. Unfortunately, this should not work, because the positions of the smaller wheel colliders do not move when the larger wheel collider turns. These also cannot be adjusted by transformations.

I also tried to assign slip values to the wheels, so that it looks like the rubber parts are working, but unfortunately this does not work either. Maybe I don't understand the values properly.

Can someone support me with this or is this impossible in Unity?

viral ginkgo
#

@sweet flicker You made little wheels on your wheel for this?

#

You should just have one wheel collider and disable sideways friction

#

Dont create new wheel colliders for the "sideslipping rubber parts"

#

Puspose of them to eliminate sideways friction, so you do that in main wheel instead

sweet flicker
#

@viral ginkgo by disabling you mean setting every sideways value to 0?

viral ginkgo
#

I never used the wheel collider
but i think that would work
@sweet flicker

#

Do that on all 4 wheels if you have 4

#

And dont have any small whells on the circumference of you wheels

lapis plaza
#

I've done omniwheels in past but I didn't use existing vehicle stuff for it

#

used just simple raycast suspension and applied custom forces

#

there are few math problems you have to solve to get raycast setup to match with omniwheels visuals but it's not absurdly hard

#

I can imagine one could use wheelcolliders for this purpose too but you'd end up getting rid of half of the things it makes for you so I don't really see much of a point, you'd be inheriting the hardcoded features you have to fight against and getting only few things in return

#

I'd always just make custom setup instead

#

@sweet flicker

sweet flicker
#

@viral ginkgo That will not work, it's causing unexpected physics effects. I am using 3 wheels in these positions:

#

@lapis plaza Visuals aint important, I just need to get the physics to work. How difficult would it be to make a custom setup?

viral ginkgo
#

Then wheel colliders probably dont work as i thought

sweet flicker
#

Unfortunately 😦

lapis plaza
#

you could hack wheelcolliders to work for this but you couldn't use their friction at all

#

for this type of thing, you'd always want to calculate your own forces

#

as for the implementation, it depends on the fidelity you need from it

#

if you need a better sim, just implement forces per wheel but you also need to come up some control scheme for the player so it can actually drive those prorperly

#

this isn't all that different from regular raycast wheel setup in general, but complexity can explode if you need really detailed sim for this

sweet flicker
#

In my case it is very detailed. I am making a Digital Twin in Unity. Basically a simulation of a physical robot. So the physics really have to be right. Thank you, I will look into regular raycasting 🙂

#

I dont know that much about Unity so it's going to be really difficult I think

sweet flicker
#

@viral ginkgo sorry, your trick seems to work. One of my colliders is just positioned strange which causes different behaviour.

lapis plaza
#

well, if you need to replicate all related physics, you are in a for a trip

#

reserve few years of your life for the research 🙂

#

game physics is all about approximations and faking stuff you won't notice

sweet flicker
#

Yeah that's the thing. This is my graduation assignment. It's basically a real time copy of a physical robot. If that one moves, this one should too

#

So they want the exact same measurements and stuff

lapis plaza
#

it's incredibly hard to make it match that kind of thing

sweet flicker
#

And if I have to implement my own physics, it's gonna take me another 4 years to graduate like you said

lapis plaza
#

if it were up to me, I'd start approaching that by measuring the data from the actual device and trying to make a model that moves the thing in Unity using that data

#

if you try to just simulate everything from scratch, it's incredibly complicated task

#

it's hard even for regular wheeled vehicles (people spend decades on making their sims feel right) but now we are talking about many times more complicated sim on the omniwheel structure

viral ginkgo
#

@sweet flicker If you wanna simulate a robot, gazebo and ROS seems to be the correct way

sweet flicker
#

That's the point, they want to see what happens if they apply this much 'power' to a motor

#

Yes, they already have a Gazebo one

viral ginkgo
#

Why not do it in gazebo?

sweet flicker
#

So it's a research based project. There is this new hype called Digital Twins, which are basically simulations

#

There is a plugin made in Unity for these Digital Twins, called Prespective

#

They want to see if that is any better than Gazebo. In order to do that, I will have to make one in Prespective

#

So after my project, they can decide if they want to switch to Unity or stay in Gazebo

viral ginkgo
#

Unless "they" know what they are doing, they should stay in gazebo i'd think, afterall thats what gazebo is built for

sweet flicker
#

Yeah after spending a month in Unity, I can tell you that I share the same opinion

#

But I still have to defend myself, so I have to try to make one

viral ginkgo
#

I see

sweet flicker
#

The fact that I do embedded software engineering and have to do a simulation in a game engine is also strange

#

I think I will suggest them to do what @lapis plaza said. Move the object itself using data.

#

Thank you very much guys!

peak crypt
#

how would i apply different friction values for each axis?

#

i want to have more friction on an objects local x axis whilst having more on its local z axis

viral ginkgo
#

@peak crypt Whatever the object is, you can make it zero friction add do your custom friction code in CollisionStay

#

WheelCollider does have this as an option btw, if you want drifting cars or something

#

@peak crypt Here is a better option:
collision.frictionForceSum
This should get you the total friction applied on the object
You can see what the friction force was that frame, and cancel it out in local x or z axis doing an addforce in OnCollisionStay

stuck bay
#

Need help I made a simple world and I made trees scatter over my terrain but my player can go through the trees even though I selected a setting (tree collider) that should've stopped it from being able to go through

graceful meadow
#
  • player needs a collider too
  • use scene view + gizmos to make sure the player collides with the trees
  • check the layer collision matrix under physics settings to make sure the colliders can interact
  • colliders all need to be 3d and not triggers
#

oh and player movement should be done with either chara controller or rigidbody physics

stuck bay
#
  • player needs a collider too
  • use scene view + gizmos to make sure the player collides with the trees
  • check the layer collision matrix under physics settings to make sure the colliders can interact
  • colliders all need to be 3d and not triggers
    @graceful meadow You lost be at the second thing
graceful meadow
#

with gizmos on, you can see collider outlines of selected objects in scene view

#

that way, you can make sure all the tree colliders are spawning properly and that the player is hitting them

stuck bay
#

👀

heady echo
#

So, I have a 2D tilemap with a Tilemap Collider 2D that I've given the tag "Level". I would like to make it so when a patrolling NPC collides with a wall, they turn around, so I made it detect collisions with the "Level" tag. My issue now is that the event fires, since the floor is the same collider with the Level tag. How can I differentiate floor from wall without having to create separate colliders?

light jasper
#

Curious how can I make the physics revolve around the player, like if I add a constant force, it moves objects away, not the player

#

for context, its a effort to avoid floating point issues

light jasper
#

?

#

Or rather, I see the floating point orgin thingy on the unity wiki, but idk how that will apply to a moving object, with multiple objects around it

stuck bay
#

WE LOVE PHYSICS

stuck bay
#

@light jasper you will need to implement your own origin shift

light jasper
#

hrmm

stuck bay
#

it also shouldnt matter weather objects are moving. you have one script to monitor when to shift (on the camera maybe). Everything else just needs to listen to the event and apply the offset when it is needed. If scripts have a vector destination, then you can simply offset the destination as well.

light jasper
#

true, thx!

vivid smelt
#

Quick question, how fast is too fast when it comes to particles with collision enabled? As in, how fast can they go while still reliably colliding with stuff?

sweet flicker
#

The wheel collider on the left and the wheel collider on the right go the opposite directions when I give them the same motorTorque value. How is that possible and how can I fix that? The rotation of the left one is good, but the right one goes backwards. Like is there another way than just giving the right motorTorque -(value) ?

sweet flicker
#

For the question above, I will just use the negative value and let it go the opposite direction in the code. But, my 'car' doesn't seem to move at all. I did the exact same thing as in a YouTube tutorial. But it seems like the wheels don't do anything. When they rotate, the colliders are also rotating but they have no effect on the rigidbody in the parent object. As you can see in the picture, the wheels are partly in the ground (don't know if that's because of raycasting?)

sweet flicker
#

Anyone with a clue? The wheels dont seem to have any collision with anything. Untill I make the radius way bigger, then the robot just flies everywhere

EDIT:
Solved by just copy and paste to a new project.

errant marsh
#

Hello, I want a physics to move the car or something similar to edy or Rcc or NWH, and I do not want this because it is not attractive to me

gilded sparrow
#

Hi, kinda basic question..
My Melee swing uses collider (NOT trigger), with kinematic RB
It's not detecting collision with terrain collider

I have selected the option in the pic, which i assume would make this work, but it doesnt.
Only changing the melee's RB to non kinematic made it work

#

And while we're at it, Enable All Contact Pair is ok in terms of performance?

#

I'm moving the Melee via animation, already set to Animate Physics. I assume this already handles moving it with Rigidbody.Move instead of transform moves

gilded sparrow
#

Actually nevermind

The melee swing collider is just not detecting collision, but it does detect collision with the player itself

The melee object was trigger before and it detects terrains. But now i want it to be collider instead, and it just doesnt work

gilded sparrow
#

What's the recommended way for fast melee swing kinematic collider to never miss a collision detection?

viral ginkgo
#

@gilded sparrow most common thing is probably multiple raycasts for multiple frames

#

in a coroutine perhaps

gilded sparrow
#

Yeah i probbaly will have to do that..

#

Might also need to do shape cast for "bigger" weapons

viral ginkgo
#

But i'd instead spherecast for one frame
Check if theres anything between hit enemy and player
If not deal the damage

That would be better if you dont want shapes

#

Ahh, bossfights and dodges huh

gilded sparrow
#

Im just figuring out my needs. I already decided the game's not gonna be too fast paced. Maybe fastest attack is 0.3s long, with only 20% of the frame to be the "hit" frame

#

But maybe need to up that fastest hit to be 0.5, is one thing

#

And this is also a multiplayer. Around 20-50 players

viral ginkgo
#

attack animation (0.2s) -> damage frame -> attack animation continued(0.1s)
attack animation (0.3s) -> damage frame -> attack animation continued(0.2s)

This could be an option

gilded sparrow
#

Was pretty ok with just using collider de/activate, but kinematic with continous speculative still "misses"..

viral ginkgo
#

You could animate collider and weapon differently
And make the hit collider longer in swing direction

gilded sparrow
#

If there's a way to make collider based wont miss, that'd be preferred i guess.. i assume it'd be cheaper than raycasts?

simple grove
#

Just do a broader cylinder overlap, and compute the timer/angle manually based on where the contact point currently it

#

is

#

much much cheaper

#

That would never miss

#

You make the shape overlap cover the whole area of the animation, and do a clean custom code to see if the contacted shape is within the CURRENT sweep for this frame

#

a shape-cast normally does not take moving rotation, but could be an option for a nicer approximation (of a sword movement of one tick/frame)

#

And at least would not miss

gilded sparrow
#

Sorry im about to sleep so brain is slow..

if the contacted shape is within the CURRENT sweep for this frame
Can u elaborate more on this?

#

Cylinder sweep cast is probably what i'll go for, yep

simple grove
#

I did not say a cylinder CAST

#

Assuming a sword swipe, I said a cylinder overlap (center is character center), the cylinder height would be thin, to represent the sword thickness or so (assuming it is swiping in a rotation movement from right to left, for example).

#

Then for each contact you check:

  • the angle of your contact point relative to your "forward"
  • check that against the time/angle the sword should be at
#

This is a super COMMON technique

#

that can be used in any physics engine, and that is super fast

#

it never misses a contact... but it's your code that computes whereas the contact is in the angular "range" of the sweep for this FRAME

#

that's

#

it

#

The shape cast is ANOTHER technique

gilded sparrow
#

Alrite i get that it's cylinder overlap
But not sure yet what's the orientation the cylinder is

U also mentioned

center is character center
Can it be centered in the chara's hand? I'm looking for an animation based

#

the cylinder height would be thin, to represent the sword thickness
My understanding is this should be the cylinder's radius..
If it's cylinder height, yeah not sure what's the orientation then

#

Do u have an article or a vid about this?

simple grove
#

if it's in handm, you are thinking in terms of a CAST

#

Do u have an article or a vid about this?
Have not searched

#

Just know it's common from discussions with other colleagues from the industry

dark arch
#

So OnTriggerEnter isn't working. My object is in the picture and it is colliding with another object, the object has all the requirements that is needed n the code: private void OnTriggerEnter(Collider other) { if(other.transform.gameObject.layer == layer) { if (other.transform.tag == "Ammo") { if (this.transform.childCount == 1) { o = other; other.transform.parent = this.gameObject.transform; other.transform.position = pos.position; name = other.name; hasMag = true; } } } } But nothing is happening... How should I fix this?

gilded sparrow
#

Try debug before all the ifs

dark arch
#

I have tried

#

nothing

gilded sparrow
#

Added rigidbody?

dark arch
#

yeah

gilded sparrow
#

On 1 of them, still doesnt work? Maybe on both?

#

How bout layer in project settings?

dark arch
#

hmmm

#

Well I did some more debugging and it is not getting trough the layermask thingy

gilded sparrow
#

The layer collision matrix in project settings

#

@simple grove

Then for each contact you check:

  • the angle of your contact point relative to your "forward"
    Im also not sure what u mean by contact point. From some collision

But... without fully understanding ur technique, it does remind me of another optimization

I dont wanna give myself a headache making perfect animation to be "straight" and on point to hit if the target's right in front of me, on the same elevation

Everything's already working and network synced, including the up/down angle. There's also directional override, so the swing direction matters for parrying angle purpose.. But really, anim based is already a burden for the server, even if im only enabling animator from start/finish on the server

So when u said "center is character center", maybe i should actually not make it anim based (positioning wise), and make the "arc" generic, by way of shape overlaps done for as long as the "hit frame" of the animation

iron hemlock
#

So I put on Rigidbody for gravity and my camera falls instead of my cube.... any ideas?

#

Also, how can I make a cube slide and jump?

graceful meadow
#
  • rigidbody should be on the cube's gameobject instead of the cam
  • lock the cube rotations and use rb.addforce or velocity sets
velvet verge
#

I'm not sure if this is right place to post this, but I have a Box Collider that isn't being rotated when I rotate the transform, and I can't figure out why.

loud moon
#

Anyone have success doing a LookRotation with the configurable joint targetRotation?

unreal blade
#

quick question, is it possible to perform "boolean operations" (like in blender) during runtime on 3d meshes?

viral ginkgo
unreal blade
#

wait how do I install that as a package? Can't I only install unitypackage files?

viral ginkgo
#

@unreal blade It explains in readme section

unreal blade
#

all it says is "To install, simply check out this repository in the My Project/Packages directory."

#

idk what that means

viral ginkgo
#

download it as a zip

#

and extract there

#

in your project

#

make a folder named Packages, if it doesnt exist

#

and extract the project contents in there

unreal blade
#

ohhh ok

#

also apparently I can install by git url?

viral ginkgo
#

you can go do cmd

#

cd to your project

#

cd to Packages

#

and git clone

#

its the same

unreal blade
#

I'll just do zip

viral ginkgo
#

yea do zip

#

and then read that example usage

#

very easy interface

unreal blade
#

ok looks like its in the package folder now 👍

wispy jewel
#

Idk if this is really physics based, but here goes

#

I'm trying to make an animation for when the player dies, the player shrinks down into nothing, but whenever I do the animation the collider shrinks too. What makes this a problem is I have a rigidbody on it too.

#

Advice anyone?

viral ginkgo
#

@wispy jewel you can always make the visual mesh into a child object and scale that instead

wispy jewel
#

Ahhh ty

pastel shale
#

yo guys

#

I have a problem

#

neither OverlapCircle nor RayCast2D are finding a collision with a certain layer

#

they return null :(

#

😦 😦 😦

pastel shale
#

NVM FIXED

unreal basin
#

I want to make a ragdoll that is controlled by the Player but im new to C# and Unity

mighty geyser
#

When are rotations applied? Can I rely on this code to only apply the final rotation or is there a chance that it will snap between the barrelTransform.LookAt and the final stepped rotation?

    private void StepRotationTowardsCurrentTarget()
    {
        // Store our starting rotation so we can use it to step ttowards the desired rotation
        Quaternion currentTurretRotation = turretTransform.rotation;
        Quaternion currentBarrelRotation = barrelTransform.rotation;
        // We want to calculate this rotation from the barrel so we only have to do it once.
        // This gives us the up and down for the barrel AND the left and right for the turret.
        barrelTransform.LookAt(currentTarget.transform);
        // LookAt just snaps the rotation to the target so we want to store where we should be aiming
        Quaternion desiredRotation = barrelTransform.rotation;
        // reset the rotations so we don't actually snap to the target
        // (These rotations don't get applied until we exit so this seems safe)
        turretTransform.rotation = currentTurretRotation;
        barrelTransform.rotation = currentBarrelRotation;
        Quaternion steppedTurretRotation = Quaternion.RotateTowards(currentTurretRotation, desiredRotation, rotationSpeedDegrees * Time.deltaTime);
        Quaternion steppedBarrelRotation = Quaternion.RotateTowards(currentBarrelRotation, desiredRotation, rotationSpeedDegrees * Time.deltaTime);
        // We only ever want the turret to rotate about the y-axis(vertical axis)
        turretTransform.rotation = Quaternion.Euler(0, steppedTurretRotation.eulerAngles.y, 0);
        // We let the barrel rotate about all axes with the turret, except the x-axis which lets us point up and down to the target.
        barrelTransform.rotation = Quaternion.Euler(steppedBarrelRotation.eulerAngles.x, barrelTransform.rotation.eulerAngles.y, barrelTransform.rotation.eulerAngles.z);
    }
flat pendant
#

Why did Unity remove Interactive Cloth? Is there any way to get the current Cloth component to interact with a Wind Zone?

torn otter
#

Hi everyone. I’m making a car game where you can ride on walls and stuff. Problem is I’m using wheel colliders and a rigidbody because it feels way better to drive. How could I counter act the gravity depending on the cars speed/angle. I might be approaching this completely wrong. Any help would be appreciated

mighty geyser
#

Add a force along the transform.up axis that is proportional to your current speed? The faster you go the harder your car will be pushed against whatever is "below" your car even if you are upside down.

near trellis
#

I'm struggling to make my character stay on slopes without sliding. Any help? Unity 2d

#

And to make my menu buttons be the focus

torn otter
#

Add a force along the transform.up axis that is proportional to your current speed? The faster you go the harder your car will be pushed against whatever is "below" your car even if you are upside down.
@mighty geyser I’ve tried something similar but my car ended up being launched into oblivion, which means I wasn’t scaling the force to the cars speed correctly. Thanks I’ll give it another go.

twin cloud
#

I want to make physically based sword combat, does anyone have an hint to where I should start looking?

loud moon
#

What config joint settings closely mimic a fxied joint ?

pale stratus
#

can somebody help me out with Raycast

#

I did Debug.DrawRay and I could clearly see it hit the other sphere collider but my Physics.Raycast still returns false

#

does anybody know why that happened

slim olive
#

post code

#

🙄

#

how tf are we supposed to know why

stuck bay
#

drawing a ray does not mean it will hit

simple creek
supple sparrow
#

@pale stratus check layers ?

near trellis
#

I'm doing a 2d platformer and the character slides when on a slope

shrewd shoal
#
Vector3 rayStart = playerCamera.transform.position;
        float rayLenght = playerCamera.transform.position.y;
        bool hasHit = Physics.SphereCast(rayStart, 1f, Vector3.down, out RaycastHit hitInfo, rayLenght, 8);
        Debug.DrawRay(rayStart, Vector3.down, Color.yellow);
        Debug.Log(hasHit);

Anyone understand why this doesn't work, it just constantly returns false no matter what. yes the layer mask is set to my ground. and the ray 100% collides with the floor. Have tried to move the cast start pos a meter away from my character with no fix. Have also messed around with the other values and nothing can get it to work

ocean pivot
#

@shrewd shoal Does it start out already colliding?

#

SphereCast will not detect colliders for which the sphere overlaps the collider.

queen marsh
#

I'm having an issue with glitchy joints, but I noticed that updating any property from the editor (i.e toggling preprocessing, adding 0.00001 to anchor, etc) "refreshes" the joint and makes it work properly
Is there any way to call this "refresh" function via script?

simple grove
#

@near trellis

I'm doing a 2d platformer and the character slides when on a slope
This is because you are using a ridigbody... You should implement a character controller instead. There are many many ways to do this in 2D...
If you insist in doing it with RB, you need to project the physics Gravity over the Tangent surface of the slope, and apply an opposite force to the character, so he will roughly stay in place...

arctic marsh
#

Or just do not make the slope slippery but add a force if he is on the slope @near trellis

velvet verge
#

Is there a limit to how many time 2 colliders will collide with eachother?

#

I have a BoxCollider2D and a CircleCollider2D passing though each other and I'm not sure why

scenic thistle
#

Why doesn't my brick with a Kinematic Rigidbody collide with walls and such?

velvet verge
#

@scenic thistle Did you check the Use Full Kinematic Collision box?

#

Are your walls static, kinematic or dynamic?

scenic thistle
#

@scenic thistle Did you check the Use Full Kinematic Collision box?
@velvet verge Where do I check that?
Are your walls static, kinematic or dynamic?
The walls don't have a Rigidbody

velvet verge
#

It should be on your rigidbody

#

Kinematic rigidbodys only collide with dynamic rigidbodys by default

#

you have to manually tell it that it should collide with the other types

scenic thistle
#

Oh

velvet verge
scenic thistle
#

oof

#

weird

velvet verge
#

I have 2 Colliders that are passing through each other without calling OnCollisionEnter sometimes, and I can't tell why

#

Even though the colliders are very clearly touching, no collision is detected

arctic marsh
#

are you moving them by script?

#

@velvet verge

velvet verge
#

I am moving the circle collider by calling MovePosition on the attached rigidbody

#

The other one doesn't move

shut timber
#

Guys, the floor has physic material with 0.5 bounciness, giving the object a 0 bounciness didn't work (though i think it should work, mybe unity bug). How do i make an object not to bounce when hitting that floor ?

karmic yoke
#

Any tricks to grabbing player velocity from a ridgedbody? it seems to be changing so much that the animator does nothing.

graceful meadow
viral ginkgo
#

@serene jolt i think you just want to do custom gravity

#

@serene jolt gravity with changing direction
and it will depend on accelorometer

#

i cant

#

you just wanna use addforce thats it

silk peak
#

how do you change the direction of gravity?

viral ginkgo
#

and disable gravity

silk peak
#

oh

simple grove
#

you get the accelerometer Vector, multiply by 10, add as force to the dynamic body

#

you might want to smooth the vector though... Because it jitters a lot

viral ginkgo
#

Erick fakos?

simple grove
#

Erick fakos?
Did not understand

viral ginkgo
#

ah wait sorry, i didnt see your profile pic at first, thoughtyou were an imposter

simple grove
#

🙂

silk peak
#

who’s erick fakos?

simple grove
#

I mean, you got the thing right, I only add that you should maybe smooth/interpolate the vector readout of the accelerometer