#⚛️┃physics
1 messages · Page 6 of 1
@timid dove Hey, so it's not working...
Physics.Raycast(transform.position, transform.forward + (Quaternion.Euler(0, dir * 45, 0) * transform.forward))
dir is an iterative function, starting from 1 and going to 3
The debug ray is making it go UP, and not the way I want it
First why are you adding transform.forward at the start
Second you'd need to also show the debug line
Third what direction is transform.forward pointing in originally
And also, it's trying to find an angle in the direction of it's forward vector and an angle to the left or right of 45 degrees
Towards the wall
I don't really know what I'm supposed to be looking at in that screenshot
What are you trying to do exactly
What object is the script attached to
Etc
The script is attached to NPC_Listener
What I'm trying to do is find an angle to go to if an obstacle is detected
Basically, if it finds a wall, face towards the wall, then find an angle on either the left or right of the NPC to go towards, until it can move in the direction it was originally going in again
I posted the full script in #🤖┃ai-navigation because it wasn't working, but then I realized the raycast was STILL wrong, for some reason
Hello?>
Is someone there
- For jumping at a given height, i can apply an impulse that's equal to
mass * sqrt(-2 * gravity * jump height). However, this is the case for one-time impulse gaining and not when i apply an input over a period of time. So knowing a duration of the period and a desired jump height, how do i calculate a force/impulse that i need to apply over this time? I assume that the object's vertical velocity is 0 at both beginning of a countdown, as well as by its end, and gravity is default0 -9.81value. In case this matters, i'm talking about 2d physics
Is Queries Hit Backfaces the equivalent of queries start in colliders for 3d? I have it checked but spherecasts are still going through close objects
nvm. It doesn't check starting colliders by design
guys pls help i have a third person template in unity and i set my character to be a duck, (it has no animations yet i will add that later) but whenever i jump, it never lands it just keeps rising in air can anyone help? it happened when i inserted my duck character as a skeleton, (also i didnt get the duck from asset store i made it myself) 🥺
Try increasing it's mass
where is mass? also ik im gonna be pretty stupid this is my first ever game, im trying to learn how to use unity
Oh you're using character controller, i thought it was rigidbody cuz this is in #⚛️┃physics
Try to make the gravity larger then
all it does is it rises slower
it worked fine when i didnt replace the character model with my duck
Does it eventually stop in the air?
It says it's grounded here
i put it from 1.2 to 0.1 its still rising infinitely but slower
I think you have a bug with detecting whether the player is grounded or not
It thinks the player is on the ground even though he's airborne
Can you show the code for it?
k wait
the whole code
for the character controller
oh wait is the problem that it doesn't have animations?
No
ah
You need to put the player on a different layer
This is what's going on
The script creates an invisible sphere at the feet of your player
It then checks whether there's anything colliding with that sphere
If there is, the script thinks you're touching the floor
The problem is that the sphere is picking up your player's legs
So you need to put it on a layer that is ignored by the sphere
Currently, it checks Ground and Default
So I recommend creating something like a "Player" layer and making sure that the player and all of it's colliders are on the player layer
how do i create a layer?
Click on your player object in the hierarchy
On the top right in the inspector, there will be a layer property and it will probably be set to Default. Click it
Then there will be a create a new layer option, select it
Now just write "Player" in one of the empty slots that are available
Now go back to your player object and change the Layer parameter to Player
Do make sure that the Third Person Controller's Ground layers parameter never includes Player
lmk if that fixes everything
i created a player layer and the duck is standing on it, however if i jump it still keeps rising
Is every child of the player also on the Player layer?
Hey guys, I've been testing around for quite a while with wheel colliders but I just don't seem to get it right? Anyone has any suggestions for wheel colliders values? I know they highly depend on the rigid body they're attached to but any guidance would be helpful
Hi, I need some help. I've got a door, and when its closed i cant go through it (which is the right thing) but when i open it i can go through the open door but i cant go through the frame. Any help is apreciated
Im inside of it
looks like you're using a trigger collider
trigger colliders are not solid
they're just for detecting overlap to call code
Hey, I've got a rigidbody on both my coin and plane, I'd like them to collide with one another but the coin just falls trhough the plane. Any help!
Do both have a collider?
Yes, Box colider on the plane, rigidbody on the coin
does the coin have a collider tho?
The coin has a mesh collider
Does convex have anything to do with it?
it does!
enabling convex fixed it
huh interesting 👍
Could also put the collision detection in the rb to continuous so it collides better
What would be the best way to create a BoxCollider2D that follows the camera and represents the area visible to the camera?
Effectively creating a 2D loading zone that follows the camera and lets me see when an object goes on-screen and goes off-screen
Just have it be a child of the camera?
does triggerexit not trigger if the collider is destroyed?
Doesn't solve the size problem.
But that's okay because I did some funky hacky math to do it instead
Hello. What is the best joint in unity2d to simulate chains or spider web? I want to make a 2d game where the player can choose 2 positions on the scene, and then I want a chain to hang between the positions, like shown in the image. What's the best way to simulate this? Thanks!
So, my character controller is doing funny things w/ the gravity
When you walk, it floats, and when you stop, rb. makes it fall
some help?
apologies if this has been asked already:
the fixed timestep options in Project Settings > Time seem to have (recently?) changed. The value is now set by 'Count' an 'Rate' values, with rate given as a fraction. The default values in a new project are pictured here, and I don't know how to interpret them. The docs are also not showing this change (I'm seeing this in 2023.1 alpha). Any guidance is appreciated.
what's this error and how can I fix it? Because of it the collision aren't working
It seems pretty self explanatory I think
Basically your mesh geometry is kinda messy and possibly not physically coherent
My collider is only working when colliding from the side. When hitting head on, characters just pass through eachother
Hello there!
The friction in my build seems to be quite different from the friction in the in-game editor. Because in my build i can't move left and right without setting the speed to like 200 (normally it's 2) , whilst 200 in the editor would make me fly out of view. The reason i think it has something to do with the friction is, with a speed of 2, i can move in the air if i jump (yeah jumping works completely fine in the build) though the movement in air is still slowed.
My code: https://hatebin.com/awynhmhgso
Video of movement in the editor: https://i.gyazo.com/62558dc1da16ed3bb4b36d7fc3848155.mp4
Video of movement in build: https://i.gyazo.com/b3397df45f9be7465d5d15659c3f3a85.mp4
You're applying forces in Update which is wrong.
Forces should only be applied I'm FixedUpdate
You should also not generally multiply the time scale by the force
Oh yeah i know that was just debug code i left there
Okay cheers, but when i put the update code in fixed update it doesn't work because well. Fixed update doesn't happen often enough to register keystrokes
Oh NVM i know how to fix it
Thank you
Right, input handling should only be done in Update
Yeah i just woke up
I just used a bool ofc
That updates in update and then my code checks if the bool is true in updatefixed
Hello, I recently had my gravity scale on my player set to 4. But when i changed it to something like 16, i click play and the gravity scale changes back to 4, but when i exit the game it automatically switches the 16 again
anyone know why?
your code probably changing it.
Question
So I have created a FPS controller with a RigidBody. The way I fixed that the character does not get stuck in a wall when it jumps at a wall is by having 2 capsule colliders on my Player. One capsule collider has a PhysicsMaterial with 0 friction. This collider has a bit bigger radius then the normal one and to avoid that it is sliding over the floor I have moved the capsule collider a small bit up. This seemed to work but my player get stuck on when I try to jump on platforms.
What is the right way to do this? How do you all do this?
If I have a navmesh agent, am I able to still update the position of its Transform manually? I have a drone "character" and its a navmeshagent and I had some code I built that made it slightly hover up and down like a drone should but for some reason it stopped working and im trying to figure out why, am not sure if maybe its because its a navmesh agent?
// Calculate the bobbing motion using a sinusoidal wave function
float y = amplitude * Mathf.Sin(0.2f * Mathf.PI * frequency * Time.time + offset);
// Update the drone's position
transform.position += new Vector3(0, y, 0);```
Here is the code, its weird because it was working fine for a few days then it randomly stopped working. Its in the beginning of an update function. The only change I can think of that I did was add an audiosource to the drone, but that should not effect that. And even removing the audiosource didnt fix it anyways but I assumed it was not that.
I would just put this "bouncing" code on a child object just for graphics
the navmesh agent itself should not bob up and down
Does a Physics2D.OverlapCircleNonAlloc store each found collider in order of how close it is to the circle's position?
Trying to cut out a LINQ OrderBy call that's being run every frame
nope
there is no order
ah
Is there a way to affect an object with gravity but to also make the object not collide with anything?
Give it a Rigidbody with no collider.
Or make sure all of its colliders are marked as triggers
I don’t think having a rigodbody and no collider is possible
of course it is
Oh my bad
Oh wait yeah I forgot I accidentally did that one time and the GameObject kept falling through the map
I removed box collider to prevent collision but now the blocks don’t move 🤔
Is gravity enabled, is the rigidbody kinematic, and does the rigidbody have any constrained?
What are you doing to make them move?
show the object's inspector
I’m outside so I wont be able to send pics unfortunately, but I have a rocket that has two blocks under it that are connected through a hinge
Acc when I get back home I can send pics and it’ll make everything easier haha
so basically as i said i have a rocket with a tether that i want to move with
when i land on the plane with the tether, the rocket starts moving weirdly cause they all got collisions
then don't have colliders on the blocks?
these are the main components for what i'm needing
i also have the hinge joint but i don't think that helps with this problem
Just disable collision between the tether and the ground using layer base dcollisions
or disable collisions between rocket and tether with layer based collisions
That's the layer collision matrix, yes
from what i've looked up i'd have to make a layer for the tether and a layer for the plane
and then uncheck the box that links to the two?
if you want to remove collision between tether and plane, yes (as well as putting those objects on the appropriate layers)
i see, tysm!
How to move 4 hinge joints with physics?
I tried AddTorque but it moved them poorly and only a little bit
However AddForceAtPosition actually moves them enough, but I'd have to do it at least 4 times for each joint
Im wondering which way is the best
Your question is way too vague.
Explain the configuration of the bodies and the joints and what kind of movement you're trying to achieve
Hey! I'm fairly new to using joints. I want a button that is physically pressable that moves as a spring between point A and B. Closest I've got is using configurable joint with setup in image. Is there a way to make sure the spring is only allowed to move in one direction (down), aka doesn't bounce up above its starting position?
Hey, I have a "floating capsule collider" physics-based character controller, and since my capsule doesn't collide with the ground, I don't have the friction necessary to stop player when the input stops. What is the right way to simulate friction with ground on your own?
friction is just a force in the opposite direction of motion, proportional to the force pushing the object into the surface times the surface area of the contact patch
in a practical sense, you should just add a force opposite the direction of any motion parallel to the surface when you're grounded
- In physics2d, there's a gap between any colliders. I don't want to remove it nor complain why it's here, just how to calculate its value? I suppose it's not fixed, then max possible value maybe?
- For more context, i want to resize colliders automatically so that there's no gap between visual elements of the game, but also for inner logic that would take ages to explain
Default contact offset in the settings
- Lmao, so simple again. I can acess it in scripts as well, right?
- Yep, i see. Excellent, thank you!
so i have assymetrical obj hierarchy with rigidbody on top but gravity keeps pushing the thing in the direction where the weight is heavier.
what can i do here? pivot point is on the center.
i guess rb is somehow distributing the rigidbody weight between its children and more children + bigger mess size on some side of the object will result in more graviy being applied in that direction
Rigidbodies normally calculate their centers of mass automatically from their shapes
But you can manually set the center of mass in code to whatever you want
How can i make this CharacterController height only increase upwards not both ways. You can see it's stuttering and increasing both ways, is there any anchor point property or any way i can fix this
I am working on a FPS Controller. It's a RigidBody setup. Everything works as it should except for the Jumping on objects part. In the video you can see what is happening. To fix this I can put a physics material on the crate with 0 friction. But when I run against the Crate it will slide of the floor like it is on ice. The same for when the player stand on top of the crate it will slowly slide of it.
So I am stuck on what to do now.. I think this is a physics things
make the box mass higher so it moves less?
thanks but then I still have the effect that the player slides up on it when I move forward as in the video
Guys, who knows how to make a circle, not a ball?
Use mesh collider, unity doesnt support cylinder colliders (neither does it support 3d circle colliders)
lets say 2 cars collide, how to make it so the impact of collision (or the force of collision) is smaller or nonexistent on one of the cars?
(other than increasing weight, and locking rb rot/pos, and drag/angulardrag, and iskinematic)
Hello I was wondering if someone would be able to help me with this. I'm struggling to figure out how to simulate better physics on the balls where they will roll off each other and be more realistic like marbles or something. Right now they are just stacking on top of each other. I have rigidbody component added with a physics 2D material where there is 0 friction and 0.5 bounciness. I'm also having an issue with my object pooling but I can ask that in the scripting channel if it's not allowed here
They're just perfectly aligned it looks like so they aren't rolling in either direction
I'm guessing I should just make the platform uneven so they don't align?
Or should I spawn them with a rotation?
Ok, okay.
Slightly offset or with slight rotation or sideways velocity
Will try that, thank you!
Hello, I have a question regarding physics, as seen in the video, why is the rigidbody not taking the object with it?
oh I fixed it turns out its because the object is static
Does anybody know why this would happen?
Where the cube overpenetrates?
Changing the Collision Detection and Interpolate parameters on the Rigidbody changes nothing
Speculative CCD makes it a little better but it has some downsides that would not be suitable for my game
but for some reason, every object overpenetrates then bounces back up to where they're supposed to be
Are you using Extrapolate?
Also are you moving these objects with your code, or allowing the physics engine/gravity to move them freely?
All three settings for interpolation don't make a change
No it's just free-falling
should be fine with Interpolate: Interpolate and Collision Detection: Continuous
nope lol doesn't change anything
In this video it's set to Interpolate and Continuous Dynamic
you sure it's overpenetrating and not just bouncing?
well if it was bouncing then it would come back down again, right?
in this instance, the cube accelerates into the ground, and then comes to a rest at the surface
as opposed to hitting the ground, bouncing back up, then coming back down
I also created a physics material and set bounciness to 0 and minimum
it is doing that
I wouldn't say so
I mean it physically cannot bounce because the physics material is stopping it
so it can't be that
Here it is in slow mo
goddamn quicktime player
it was supposed to save that in slow motion 🤣
anybody have an idea?
This is the original question
Has anyone figured out a physics solution to manipulating a bucket in VR? specifically the collision setup and the hinge settings for the handle? no matter how I set mine up, the handle swings through the bucket lol
I want to make a something similar to a hinge joint with the configurable joint but it always rotates around the center of the object but I want it to rotate around the anchor or pivot. Does anyone know how to get a configurable joint to rotate around the pivot or anchor?
doesn't it rotate around the Anchor or Connected Anchor position?
forget which one
That's what I want to happen but it just rotates around the center of the object instead
Make sure to enable collisions between your bucket and handle rigidbodies in your configurable joint
so i am making a dropper and my character does not take fall damage how do i handle kill blocks (colliders that player can not land on)?
should i apply the "death" function to every obstacle or just the player (onCollidertrigger) and tag compare and then run death function or anything else?
I'd make a script you can attach to the kill blocks which kills the player
The thing is imagine I have like 100 objects 100 objects with 100 script vs 3 lines in fixed update to player
no
100 objects with 1 script
why would you need 100 scripts?
Yes but I have to add that 1 script to 100 objects
so?
That takes 1 second
besides it'd be a prefab
you add it once to the prefab
and it's done
Ye but won't it hurt performace
no
I am confused isnt it better just to add tag check on collision to the player?
don't prematurely optimize
doesn't seem like something the player script should be handling
seems like a separation of concerns issue
each script should do one thing
a kill block kills players that touches it
a player just jumps around
It's much cleaner architecture
otherwise you're going to find that your player script is 4000 lines long and doing 80 different things
I can only offer my opinion, I can't force you to make any particular decision 🤷♂️
Seems like I have to try it out
I will ping u if you don't mind
Btw it is a mobile game casual
I have questions about patterns where should I ask
Like game managers and handling levels and player spawn , etc
Wondering if anyone can help me with this. I have a basic rigidbody and a capsule collider. I need it to start between two points and end between two different points. Both sets of points are known before hand so i just need to physics to move it between the two sets. I can get this to work with the position and velocity but i cant get rotation and angular velocity to work right. any thoughts on how to get this to work?
a lot of unsanswered questions about this:
- When you say "Between" what do you mean? The midpoint between the two?
- When you say start and end, what is the nature of the motion exactly? Are you wanting a real simulated physics motion? What kind of acceleration/deceleration are you looking for? What happens if some external force interrupts the motion? etc..
maybe show how you're doing it for position
but based on just having "two points" I don't see how you are determining what the desired final rotation is (or what the starting rotation should be, for that matter)
basically step 1 is defining the problem better
Sorry im not the best at explaining. Im doing rope physics. the rope is made up of a series of points. i think thats the standard way. The collider is positioned so that each end is at a two adjacent points. Then put a collider between each set of points and that would be the collision for the full rope.
The motion for the rope ive already done and that works perfectly. So i know where the colliders should move to, to match the motion of the rope
Bump cuz i am still looking for help on this
How do I freeze both the X and Y rotations. If I run this code it just freezes the Y rotation.
if (view2D)
{
rb.constraints = RigidbodyConstraints.FreezeRotationX;
rb.constraints = RigidbodyConstraints.FreezeRotationY;
}
else
rb.constraints = RigidbodyConstraints.None;
}
Constraints is a bitmap. See the documentation for examples: https://docs.unity3d.com/ScriptReference/RigidbodyConstraints.html
rb.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY;
idk if this is the right channel for this but im making a game and i wanna have like a cloth "door" type thing but how would i make the player able to walk throught the cloth
Find out more about cloth physics and learn more about Unity on the official learn site: http://ole.unity.com/unitylearnmore
Hi, was wondering why my character is falling super insanely slowly, could it be due to animations?
Could be the rigidbody
Check the mass
yo the tutorial im following shows how to fix it later but thanks anyways
Np
hello
for natural movement, is there an agreed upon mass/drag ratio for a humanoid character?
I guess it would depend on stuff like velocity
What do the joints components do?
Add joint?
can someone please explain this to me
why tf is the joint teleporting when I toggle isKinematic
Edit: Solved, it was an issue with the joint settings, but I have come across one more issue - it turns to a weird position by itself (that is actually outside of the bounds I had set for it)
this is my joint settings - could someone give me a bit of advice here please?
Hey guys
I recently came across this weird thing
Seems like theres a priority for fixed joints or something
I dont understand why one wing wiggles and the other one doesnt
And after swapping them the other one does that
I didnt find anything about it on the internet
hello
so i have this issue where my car flies off if the wheel colliders are enabled
Why are you using joints to begin with? Seems like that should be just one rigid body so parenting should be enough?
Need to addforce from different possitions
So i can get netforce that controls flight
Otherwise i would have to use addtorque or something but i want it to be done using forces
Rigidbody.AddForceAtPosition is made for that
I dont understand either but id not try to struggle with that if theres not any reason to use multiple bodies with joints
Well i would have easier control over all variables for each surface
Also it is supposed to be something like kerbal space program
That i can connect and disconnect other wings
guys
i need help
so I added a wheel collider to my truck so I can drive it but its rotated sideways, I can't fix by rotating the gameobject and solutions?
??
Is there a proper way to do a Golf Swing?
Mainly the travel of the golf ball mid air? Trying to replicate Mario Golf or Wii Golf.
Currently am just using Unity and just basic force in a direction.
This game is networked, so the Golf Ball should ideally be visible to all three clients. Ideally also from the shot to the landing point in less than a second. I tried doing some basic add force to the golf ball and it felt a bit floaty. So then I just adjusted mass in editor but I don't think that is the right way to do it?
So mainly: I am trying to create a golf ball flying in mid-air that has a travel time of less than 1 second.
(Networked real-time, not turn based golf.)
(Also, how might someone do a slice or hook in golf without a timing based power gauge or an accelerometer in a remote?)
I've seen this glitch before, usually I'd just copy over the ridged one to replace the broken one but if you're trying to make an airplane building game you should ask vitsum
Bumping, since it seems to have gotten lost, does anybody know a solution to this?
What variables? You could still do the logic inside the same scripts but instead of rb.AddForce(force), you would use rootRb.AddForceAtPosition(force, transform.position)
AddForceAtPosition also gives more control over the forces, now the force doesnt necessarily need to be added to the center of the plane parts
Is there a way to make colliders visible? im used to ue4 which has a setting for that and i need to see what my colliders are doing
Window > Analysis > Physics Debugger
Then check the Collision Geometry checkbox in the scene view
cool thanks
I have a problem. When I jump the object reaches its max height almost instantly then falls extremely slowly. The objects scale is 1 for each axis and I have to scale the gravity to 9.81x33 for it to feel similar to earth gravity. Can anybody help me?
is it a rigidbody or character controller?
This is usually due to a combination of:
- resetting your y velocity to 0 each frame in your code
- using an extremely high jump force/velocity
stop doing those things and it'll work normally 😉
Rigid body
you might need to post the code, it seems like you could be resetting the velocity as PraetorBlue said
definitely resetting velocity. the "super slow falling" thing is the classic sign of that
Anyone know if you can use CCD ik for a rigidbody with Joints?
Hey guys! quick question that I wanted to prod the community about haha.
I've noticed when working with multiple Unity physics scenes (for 2d) OnEnable is fired again when a gameobject is moved to a new physics scene.
Is this intended, or is this a bug within Unity?
sounds like a bug
If you can reproduce it I'd submit a bug report.
Are you sure you're not disabling it at any point?
As far as I can tell. I can boil it down a bit more though just to be sure
Will get back to you haha
[UnityTest]
public IEnumerator OnEnableDoesNotExecuteAgainOnMoveToNewScene() => UniTask.ToCoroutine(async () =>
{
// Arrange
var onEnableCount = 0;
// Act
SceneManager.CreateScene("Basic Level Helper", new CreateSceneParameters());
var onEnableTestGo = new GameObject("On Enable Test Go");
onEnableTestGo.OnEnableAsObservable().Subscribe(x => onEnableCount++);
SceneManager.CreateScene("Basic Level", new CreateSceneParameters());
await UniTask.WaitUntil(() => SceneManager.SetActiveScene(SceneManager.GetSceneByName("Basic Level")));
SceneManager.MoveGameObjectToScene(onEnableTestGo.gameObject, SceneManager.GetSceneByName("Basic Level"));
// Assert
Assert.Zero(onEnableCount);
});
[UnityTest]
public IEnumerator OnEnableExecutesAgainOnMoveToNewPhysicsScene() => UniTask.ToCoroutine(async () =>
{
// Arrange
var onEnableCount = 0;
// Act
SceneManager.CreateScene("Basic Level Helper", new CreateSceneParameters());
var onEnableTestGo = new GameObject("On Enable Test Go");
onEnableTestGo.OnEnableAsObservable().Subscribe(x => onEnableCount++);
SceneManager.CreateScene("Basic Level", new CreateSceneParameters(LocalPhysicsMode.Physics2D));
await UniTask.WaitUntil(() => SceneManager.SetActiveScene(SceneManager.GetSceneByName("Basic Level")));
SceneManager.MoveGameObjectToScene(onEnableTestGo.gameObject, SceneManager.GetSceneByName("Basic Level"));
// Assert
Assert.AreEqual(1, onEnableCount);
});
Any rigidbody Ik solutions?
Hey, there.
How to reduce slip in wheel colliders?
I have been modifying Sideways Frictions values and Forward Friction values, but can't figure it out.
My wheels are constantly turning left or right uncontrollably.
Good afternoon, I have a question about a movement I'm doing, currently I have a vehicle that moves by physics and I would like to make this could not hit the walls and slide down these, does anyone know any way to do it, if with raycasts or some mathematical formula similar to PID?
make this could not hit the walls and slide down these
Can you clarify this phrase? It is confusing.
Hi, so im trying to create something like "Learn To Fly" in unity but cant really get the gliding.
So i have this box with rigidbody and i want to make it glide depending on the angle of attack.
can anybody help?
i just shoot it towards the ball
Does anyone know if theres a specific amount of mass difference between jointed objects that wont dramatically affect the performance of the joint?
hi, how can I turn the wheel collider to correspond with the real wheel ?
you have your ideas backwards
the wheel collider is always aligned with the object's +z axis (forward axis)
It's your 3D model that is misaligned
The blue arrow is forward
your model seems to be facing -X
so I found this answer on unity answers but...
Is it possible that two colliders that are set to ignore each other could still affect each other? I have a series of colliders that slightly overlap and seem to be interfering with each other but if i set them to triggers they behave as i expect.
how did you "set them to ignore each other"?
Physics.IgnoreCollision(collider1, collider2);
Where are you getting those references from?
And when is that code running
the reference is from adding the colliders in a script. a .AddComponent<CapsuleCollider>() and then the IgnoreCollision is done. it all originates from the start function.
also checking GetIgnoreCollision between the colliders during the fixedUpdate returns true so they should be ignoring each other
show the code?
theres of unrelated code but this would be the relevant part
rigs = new ColliderGroup[segments];
for (int i = 0; i < rigs.Length; i++)
{
GameObject g = new GameObject();
Rigidbody r = g.AddComponent<Rigidbody>();
r.mass = 0.6f;
r.drag = 0f;
r.angularDrag = 0f;
r.useGravity = false;
r.isKinematic = false;
r.constraints = RigidbodyConstraints.None;
CapsuleCollider cap = g.AddComponent<CapsuleCollider>();
cap.isTrigger = false;
cap.radius = 0.01f;
cap.height = 0f;
cap.direction = 2;
cap.material = pm;
rigs[i] = new ColliderGroup(g, r, cap);
}
for (int i = 0; i < rigs.Length; i++)
{
for (int j = i + 1; j < rigs.Length; j++)
{
Physics.IgnoreCollision(rigs[i].c, rigs[j].c);
}
}
thats all called from the start function and the ColliderGroup is just a class to hold a reference for the gameobject, rigidbody and collider. it doesnt do anything else
and like i said, if i set the istrigger to true everything works perfectly, apart from collision obviously
Show ColliderGroup code?
Also for sharing code here:
!code
📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
public class ColliderGroup {
public GameObject obj;
public Rigidbody rb;
public CapsuleCollider c;
public ColliderGroup(GameObject obj, Rigidbody rb, CapsuleCollider c)
{
this.obj = obj;
this.rb = rb;
this.c = c;
}
}
like i said it does nothing. just holds references
I'm trying to create my own custom interaction toolkit for a VR game that I'm working on. So far I have a Interactor and a Interactable class which are applied to a player's hands and grabbable objects respectively. When a player grabs an object I create a InteractionInfo object which stores some useful information about the position and rotation of the grab https://pastebin.com/bVZx6tnC. Then during every FixedUpdate call inside the Interactable class I update the position and rotation accordingly https://pastebin.com/wb7D0qC8. My problem is that there is a pretty noticeable delay when the objects tries to track the Interactor's position and there is also a considerable amount of jitter whether the Interactor is moving or not and then finally when an Interactor grabs onto an object with a HingeJoint component like a door or a lever then the object freaks out and jitters between the Interactor's hand and rotation and the joint's position and rotation which I was told wouldn't happen if I use MovePosition and MoveRotation on the rigidbody. I've tried other things as well like ``` _rigidbody.velocity *= (-1 * _dampenFactor);
Vector3 velcoity = (targetPos - transform.position) / Time.deltaTime;
_ridigbody.velocity += (velocity * _scalingFactor);``` instead of `MovePosition` inside the FixedUpdate method however this just makes things worse but ends up giving me the same result as `MovePosition` if I put it inside the `Update` or `LateUpdate` method.
seems like either the answer was wrong or you did something wrong yourself
I have a quite specific and unique question but are there any sources that list all the major changes to physics engines in various versions of unity?
Unity hasn't had a major change to the physics engine in probably 15 years
Well, "major" in quotation marks
Like moving to a different version of physX
Also, I can't really find any information about 2D Physics engine outside of the fact that it at some point was using Box2D
But does it still use it?
Or what was before it?
I can't find anything
It is using Box2D yes
always has in living memory afaik
I think this is the last major update unity did https://docs.unity3d.com/Manual/UpgradeGuide5-Physics.html, update to physx4 didnt bring many changes to the game developing process, it was mostly just under the hood stuffs: https://blog.unity.com/technology/physics-updates-in-unity-2019-3
The more recent changes to physX I was able to find
In that particular subject I'm more interested in period between Unity 1 and Unity 5
Ok, I've managed to find that Box2D was introduced in Unity 4.3 version
Just to make sure
Before it there wasn't any official 2d physics engine in unity?
And it is used since then up until now?
seems like they only had the 3d engine before that yeah:
https://x-team.com/blog/unity3d-v4-3-2d-vs-3d-physics/
The last question is asked to make sure because I'm a little confused due to the fact that the name "Box2D" isn't mentioned anywhere in manual where PhysX is
Same for this page:
https://unity.com/solutions/programming-physics#built-physics-2d-games
could be a licensing/trademark/legal issue
¯_(ツ)_/¯
Or just an oversight, or who knows
One more question just to be sure
Currently used version of PhysX in lates versions of unity is PhysX 4.1, right?
Hello guys, I am trying to redo the antenna from hillclimb racing: Basically when your car moves, the antenna behaves like it has some mass, so i need to implement some kind of inertia. I was playing around with all kinds of joints, but I cannot figure out what to use.
What I already did is, I connected five short rectangle rigidbodies to another with FixedJoint2D, but it is stiff. Can someone help me with this?
you mean the bending of the antena?
yes!
I do not really know any of unity's joints, I can give you an alternative option tho
that would be awesome 🙂
you can do it inside the vertex shader, with some math, kind of like grass swaying in the wind but velocity dependent, if you do not know how to write shaders ¯_(ツ)_/¯
I can have a look at that, but it seems way too advanced for me, I just started doing unity like a week ago
how can i completely disable a 3d rigidbody?
setting it to IsKinematic = true and enableCollisions = false still syncs the RB transform
and its super slow
setting kinematic to true is the way
"super slow" would be down to your code, as a kinematic RB only moves exactly as the code tells it to
unless you mean slow computationally
In that case, destroy the RB.
with "iskinematic" enabled, unity is still syncing the rigidbody position with the transform position
it takes a significant chunk of frametime
i have 100 zombies, and i have them animated as well as with a ragdoll state
in ragdoll, physics should be enabled
in animated, there should be no RB syncing at all
^
thats the other issue
i cant just destroy the rb, the character joint relies on it
destroy the joint too
and i really dont want to add 2 components to every joint on the body every time one is killed
or rather, create these things at the moment you wish to become a ragdoll
there has to be a better way
make two prefabs
it seems so slow like that
thats my fallback idea
the animated one, and the ragdoll one
im just wondering why u cant just disable the rb when inactive
its so annoying
might be a dumb question but can't you just disable those components when you don't need them?
that was the whole point of the conversation - Rigidbody cannot be disabled
What was the original question, did not follow 😄 you trying to do a ragdoll?
Is there a way to make a bridge work with wheel joint with a motor? I can't have my car to accelerate on a physics bridge
ive got a ragdoll that doubles as a hitbox while the zombie is alive. despite being kinematic, the rigidbodys are still syncing with the transforms, and doing physics calcs. this is killing performance at the scale i am using
i have a workaround tho. i duplicate the colliders and update their positions manually
i already have a ragdoll lol thats not the issue
Ohh okay, thought the setup of your ragdoll is the issue
the issue is performance while the ragdoll isnt active
Did you set it up yourself or with the ragdoll thing from unity?
ragdoll wizard
doing this is faster than keeping the rigidbody objects enabled, even without jobs/burst (which im gonna be using for it soon)
like, over 3x faster
went from 90 avg to 250 avg fps
Does anyone know any common gotchas with things not bouncing off meshes that have bouncy physics materials applied? I’m making a pool table and the balls just stop dead on the cushions.
https://discordapp.com/channels/489222168727519232/497874196274348032/1066066704377057322
I know I have asked already, but I am still stuck on this problem, could someone give me some insight into whats happening please?
hello, Visual studio picks the wrong overload for raycast, and its driving me insane.
RaycastHit hit;
Ray ray = new Ray(transform.position, transform.TransformDirection(Vector3.forward));
bool doesHit = Physics.Raycast(ray, hit ); //error cant convert ray to vector3
//wanted overload -> public static bool Raycast(Ray ray, out RaycastHit hitInfo);
//used overload -> public static bool Raycast(Vector3 origin, Vector3 direction, [Internal.DefaultValue("Mathf.Infinity")] float maxDistance, [Internal.DefaultValue("DefaultRaycastLayers")] int layerMask, [Internal.DefaultValue("QueryTriggerInteraction.UseGlobal")] QueryTriggerInteraction queryTriggerInteraction);
Fill in the additional parameters for the overload you want?
C# doesn't allow ambiguous cases with overloads afaik.
yeah well its refusing to pick the correct one.
the only overload that works is just "Raycast(Ray)"
its not ambigous tho, since everything is clearly typed. i dont know how it can even pick the wrong one to begin with
You are missing 2 parameters in the code you posted
yeah sry, the overload should have been this one.
public static bool Raycast(Ray ray, out RaycastHit hitInfo);
regardless, the 4 param one also doesnt work
as soon as its more than 1 parameter, it defaults to some vector overload, and then throws an error
You are missing the out keyword
anyone know of a tutorial for unity physics hinged objects? I setup the hinge joint and it's limits but it seems to want to chaotically vibrate all over the place and when the parent object moves it doesn't take the hinged element with it...
how are you moving the parent object
it's a scene prop so I'd like it to react to explosions nearby. parent object has a rigid body and a box collider.
any suggestions appreciated, I have to run to pick up the kids, thanks all!
wdym parent object has a Rigidbody and BoxCollider?
if you want this object to react independently via physics, it needs its own Rigidbody and its own collider
I think I found a bug:
These two screenshots illustrate the issue, if the trigger is bellow a certain height compared to a plain old 2m capsule character controller, it will not trigger OnTriggerEnter()/Exit() events, if it is moved slightly higher, it will trigger.
Yellow box is a BoxCollider with "Trigger" setting turned on.
I am so confused on this. Why is the player colliding with the wall..?
I lowered the player's collider height and that seems to fix the problem but as you can see, there is clearly a lot of room for the player to fit through so..
Lowering the height by 0.03 fixes it...
Why might this be happening?
Are you using CharacterController? It has a "skin width"
Oh?
The width skin is only 0.08 though
I don't think from the top of the player to the top of the doorframe is 0.08
Also if it would be the case, then it would also be an issue with the width of the player which it is not
is that a 964? 😄
If the drag formula is
dragApplied = Mathf.Clamp01(1f - drag * Time.fixedDeltaTime)
How can I determine what force to apply to a rigidbody to observe a relatively similar impact regardless of the rb's drag value?
Use case is a creature with physics based movement. When grounded, drag is set to a relatively high value to make the controller feel more rigid, whereas when the creature is no longer grounded, only g is applied and drag is set to 0.
Controller feels good, I'd like to keep it that way. Bullets hitting the creature are a problem since bullets carry direction/force data but do not account for the rb's drag.
Use this formula to calculate the velocity change then add that force with ForceMode.VelocityChange
Yeah 😍
Beautiful. Do you have more?
hey, i have this tilemap collider on my tilemap and my player is getting stuck on corners, i saw that u need to use composite collider and a rigidbody to make it one single collider and not one collider for each tile, and it worked, my player wasn't getting stuck on corners but now, when my player moves horizontally, he change's his "y velocity", just like he was jumping, i really can't find any solution
rigidbody in tilemap collider is set to static, and tilemap collider have used by composite checked
my player settings:
omfg, all i had to was to change composite collider geometry type to polygons
oh, wait, no, it didn't fix
i changed geometry type to polygons and it worked for one debug, and then it didn't
i found this https://forum.unity.com/threads/2d-movement-velocity-y-mysteriously-changes.712142/ and its like my problem, but instead of small numbers, its like -7 or 7, not 0.7
So does anyone know what's happening?
i'm trying to simulate a kind of chain with each chain segment connected to the last with a hinge joint. However when the hook where they are all connected at the top moves too fast the segments at the end lag behind quite a lot and it looks unatural. From my research this is kinda what the joints are meant to do, but it just doesn't seem right. Does anyone know of an alternative that keeps each segment perminantly a fix distance from the last, but alloying rotation?
Are articulated bodies more stable/accurate than joints? e.g. is a ConfigurableJoint set up as a hinge inferior to a Revolute Joint in an articulation? I ask because I ported a rope I made out of Revolute Joints in Box2d, which was quite stable and "felt" good to Unity, set up via ConfigurableJoints that are set to also act like a hinge), and it's ... not great. It's "bouncier" (???), seems to dampen poorly or have some kind of feedback ("shivering"), goes crazy under extreme gravity (box2d rope could handle 100x gravity while staying stable) ... would I have better luck using an articulated body for this? Is there just a better way to make a rope in Unity?
depends what your requirements are for the rope
Can someone help with this?
Stability -no runaway and no "vibrating" and other artifacts, and preferably tunable to my "gamefeel", which is a rope that's highly flexible, without feeling "springy"
I find the Configurable Joints definitely seem to stretch beyond their linear limit on the regular. Maybe I'm doing something wrong there?
"inelastic, low tension" maybe to put it in physics terms
I'm talking much higher level than this
what is the rope for
is it visual only
is the player swinging from it
are there requirements to the swing, like it needs to always reach a same platform or something
it's hung from a fixed position and the player induces forces on the end of it to make it swing
btw, it only moves in xy dimensions, but i think that's just a detail. the overall scene is still 3d
If some games have done it already then obviously it's possible
https://i.imgur.com/Ie3D7re.png
any idea why this would be happening?
the small enemy on the right has sort of a buffer between its collider2D and the composite collider terrain... my player and other entities dont have this issue though
actually my player does have that buffer too, I was looking at the wrong box for their physical collider
What happens if you play with the Y Offset of the box collider on your screenshot ? Also did you try messing with the sprite pivot ?
I'm trying to make a motorcycle with the build in wheel colliders. What approach would you use to keep the motorcycle upright? Apply angular momentum every time it starts to fall to one side?? Or are there other solutions?
I could solve the issue of the smaller green guy on the right by moving the sprite pivot up.... or by doing what I did which was to move the collider up
either way though the initial issue still exists that my colliders are not sitting flush with the composite collider
there is a small gap about 0.04 wide between thm
im a bit confused about torque.
i have a small astronaut (2m) and a bigger ship (20m).
they get the same rotational force compared to their mass.
(its 1f * rigidbody.mass), and yet the astronaut spins like crazy, the ship is suuuper slow to rotate.
rb.AddRelativeTorque(localAxis * value * rcsForce); //idk why it needs more force
i was under the impression that:
equal mass
equal torque
=> equal rotational velocity?
well, it seem that when i use the same sized collider, the rotation is equal.
mass is not the relevant measure
the relevant thing is the inertia tensor
which changes with different shapes
Think about a long stick. You need more torque to rotate it around the long axis than the short one.
yes thanks. chatGPT told me something similar lol
i see that the interia tensor is a matrix, stating the interia for each axis
While using a rigidbody, I notice that the player( in this case, a cube) will rotate or be spun by the collision of other objects. How do I lock the rotation so that the cube does not rotate at all?
Rigidbody has constraints you can set in the inspector
simply constrain the rotation as you wish
hey guys, i have problems with a little rocket simulator i am making. I am trying to rotate the rocket based on input, and it works fine when rotating counter-clockwise but not when rotating clockwise. it is as if the rocket tries to smoothly clamp on 90 degrees. also when rotating counter clockwise, it rotates faster at the 90 degrees point
Code:
void FixedUpdate()
{
rb = currentRocket.transform.GetComponent<Rigidbody2D>();
rb.mass = currentRocket.getTotalMassOfRocket();
CenterOfMass.transform.localPosition = currentRocket.getCenterOfMass();
if (canControllRocket())
{
rb.AddForceAtPosition(currentRocket.totalAccelerationForce * Throttle, CenterOfMass.transform.position);
rb.AddTorque(-rotF * currentRocket.totalRawAccelerationForce * Throttle * 0.005f, ForceMode2D.Impulse);
}
}
Input is dealt here (is called in Update() );
if (Input.GetKey(KeyCode.LeftShift))
Throttle = Mathf.Min(Throttle + 0.005f, 1);
if (Input.GetKey(KeyCode.LeftControl))
Throttle = Mathf.Max(Throttle - 0.005f, 0);
float RotL = 0;
float RotR = 0;
rotF = 0;
if(Input.GetKey(KeyCode.A)) RotL = -1;
if(Input.GetKey(KeyCode.D)) RotR = 1;
rotF = RotL + RotR;
are you sure your AddForceAtPosition isn't just.. off?
maybe your center of mass is off kilter
resulting in a torque from that call
what happens if you just use normal AddForce
i checked, its at the right position
lemme try
THAT WORKS?
yes, it does, now i am even more confused. how will i take center of mass into account now?
why do you have your own center of mass object anyway
you know Rigidbody2D has its own centerOfMass property, yes?
rocket consists of many parts, i dont know how i would handle that
manny parts with changing mass yk?
why don't you just add the force at the position of the engine?
performance
Are you trying to make Kerbal Space Program? What's the goal here?
when having multiple engines, like 100 or so, i would add force on each individual one, but if i instead at force at the center of mass, no problems
yea my goal is a 2d rocket game with procedural generated outer planets
yep this is how Kerbal Space Program does it, force at each engine
it does?
If you just want to add force at the center of mass, that's what the normal AddForce call does
no need to do AddForceAtPosition
I think that's how rockets work, so they try to imitate that
should i?
it depends how you want your game to work
but shouldnt it have the same effect?
if you want rockets to always work fine, add force at center of mass.
If you want it to be more "realistic" and allow the player to screw things up, add force at the engines
I think you will have to take the localposition of the engine when using AddForceAtPosition
yea
If the engine is a child of your rocket of course
it is
My bad
so iterate through each engine and do AddForceAtPosition at its localposition on the rocket rb?
The position is in world coordinate
So you just have to take the position of your engine (engine.transform.position)
AddForceAtPosition uses world space positions
yes
Yep I double checked after that, I wasn't sure
You can either iterate over all your engines from the rocket script which I assume would be attach to the rocket game Object, or you can create an engine script, that will take the rigidbody of your rocket and add a force at the engine position to it
Probably better for you to have an engine script, that way, if you want to modify the force added to the rocket, it's easier
?
look at the video
Nah I saw that, but what do you use for the rotation?
Consider the engine system we talked about will probably counter that, and make the physics more realistic for your game...
I suspect your rigidbody's center of mass is just in a weird place.
Yeah add torque is a way to rotate the rigidbody... Using the system for the engines we talked about earlier, you just have to create two engines at the base of your rocket and active one or the other depending on the input
oh no i may have found the error
if you apply that system you end up with something like this :
i have found the error, everything is fixed, unless...
when gravity pulls down on the rocket, shouldnt it fly in the direction its flying with the center of mass pointing forward?
like this
because for me, it isnt, and the rb's center of mass is properly set up
what's the value of your angular drag in your RB?
1, it confuses me anyway
put it at 0
Isn’t that hella unrealistic?
"Drag is the tendency of an object to slow down due to friction with the air or water that surrounds it. The angular drag applies to rotational movement and is set up separately from the linear drag that affects positional movement. A higher value of angular drag will cause an object's rotation to come to rest more quickly following a collision or torque."
I mean you can tweak the value to get the result you want but for now just put it at zero just to ensure it is what causes your rocket to slow its rotation when falling down
I will try that shortly, I am still struggling with setting mass, engine force and everything else up, everything would be a lot easier if floating point precision wouldn’t exist
I mean in games like ksp or sfs you can just fly out the distance you want and you won’t get any fpp issues
fpp?
doesnt work, angular velocity doesnt change
if fpp is an issue for you you can just round it to a decimal? Mathf.Round(yourValue * 10f) /10f with that formula, you get your value rounded to the first number after the point
then maybe the center of mass of your rocket isn't set right?
no i mean when flying out huge distances, say you want to fly to 3 * 10E9. you will get huge fpp isues because the higher the position is, the less precise decimal points you get
it is
i double checked
oh, yeah if we are talking about world coordinate, it's a problem
i still have that com object, and its local position is alligned to the rb's center of mass
can you do a Gizmos DrawSphere and show me where your sphere is located relative to your rocket?
how can i focus on something in scene view?
so that the scenes 'camera' follows an object
honestly, don't know, just pause the game and go to your rocket location,
there it is, the gray sphere
maybe i should put gravity scale to zero and apply force at the COM pointing down manually?
if you really want your rocket to go back to its original position afterward, I'd do a Vector3.dot between the transform.up of my rocket and Vector3.Up, it will return 1 if both vectors are facing the same direction, -1 if they point in opposite direction, and 0 if they are perpendicular, then I would clamp that value between 0 and 1, and do 1f - yourValue, that way if your rocket is already upright, your value is at 0, otherwise if perpendicular or pointing down, it give you 1, then using Quaternion.Lerp, I would Lerp between the rotation of my rocket, and Quaternion.LookAt(Vector3.Up), and for the time parameter, I'd take the value I calculated and multiply it by DeltaTime, and an additional value, which would be the max speed at which I want my rocket to rotate
Something Like that
what do you mean?
when you select your rocket, which arrow point upward? blue green or red?
green
doesnt seem to work
i am falling straight down but rocket is pointed to a different direction
Do that instead ? : rocket.transform.eulerAngles = Vector2.Lerp(rocket.transform.eulerAngles, Vector2.zero, rotationSpeedLerp);
now i cant rotate one bit
elaborate
rotation is very little and hard
you obviously want this function to be called when no input is pressed
like i can only rotate the rocket to +- 4,875 degrees
I mean, if you call it everytime in the update method, it will obviously always try to lerp the euler angles up right...
it just snaps to the old position when no input is pressed
it changes the position of your rocket?
rotation* sorry
can I send you a private message?
yes
Been a while since I used the physics engine in unity - I'm doing some ML research using ml agents
I get some clipping issues as you can see above, any idea what is wrong with my settings?
Ball rigidbody is
Platform cubes are all set to
Setting the platform to be kinematic with a high mass seems to have helped
Problem I think is you are moving with the gizmo. That has no physics checks, and would be the same as setting the rotation. Rotate them with an actual FixedUpdate rigidbody call.
sadly it's a little more complex - I'm using ML so can't do that
public override void Heuristic(in ActionBuffers actionsOut)
{
ActionSegment<float> continuousActionsOut = actionsOut.ContinuousActions;
continuousActionsOut[0] = -Mouse.current.delta.x.ReadValue();
continuousActionsOut[1] = Mouse.current.delta.y.ReadValue();
}```
```csharp
public override void OnActionReceived(ActionBuffers actions)
{
const float angleThreshold = 0.25f;
const float fallFailureReward = -1f;
const float successReward = 2f;
float zAngle = 2f * Mathf.Clamp(actions.ContinuousActions[0], -1f, 1f);
float xAngle = 2f * Mathf.Clamp(actions.ContinuousActions[1], -1f, 1f);
AddReward(-0.001f);
// Reduce the reward if the platform has over rotated
if ( (platform.transform.rotation.z < angleThreshold && zAngle > 0f) ||
(platform.transform.rotation.z > -angleThreshold && zAngle < 0f))
{
platform.gameObject.transform.Rotate(new Vector3(0, 0, 1), zAngle);
}
if ( (platform.transform.rotation.x < angleThreshold && xAngle > 0f) ||
(platform.transform.rotation.x > -angleThreshold && xAngle < 0f))
{
platform.gameObject.transform.Rotate(new Vector3(1, 0, 0), xAngle);
}
// Calculate Rewards
if (ball.transform.position.y < ballFallenThreshold)
{
SetReward(fallFailureReward);
EndEpisode();
}
if (goalReached)
{
SetReward(successReward);
EndEpisode();
}
}```
I guess I should use Rigidbody.rotation instead?
The trouble is, I have a load of different cube objects all parented under one object
which is what I'm rotated
That parent object doesn't have any colliders or rigidbodies of it's own
So you have a compound collider. A parent with a RigidBody and multiple child without one, just collision boxes.
https://docs.unity3d.com/Manual/CollidersOverview.html
Then rotate the parent rigidbody with MoveRotation. That would be a valid setup for your scene, in my opinion.
Yeah that makes sense to me, cheers
Will let this kinda janky model finish training then see how that works
Seems like a fun project, good luck 
Thanks! Would definitely recommend, it' super cool
pretty easy to set up a model that teaches an ai to solve a simple maze, like in this video
For some reason, now even tiny movements catapult the ball around - any idea?
Increase the mass? 😛
It seems like a 100g ball getting moved by a 100kg box field thing
changing the mass from 1 to 1000 doesn't have a noticeable difference
the mass of the platform is 1 now
This is using the MoveRotation?
yup
Hmm. Ball and platform are both dynamic?
- Not valid anymore but just out of curiosity: how do i move a kinematic 2d body with respect to other colliders in the scene? I tried both velocity and move position approaches, but in either option the body just clips through things. Am i supposed to react to collisions manually?
What about the interpolation settings? Can you set the both to Interpolate?
Continous dynamic, yeah
No obvious change setting them both to interpolated
Strange, it looks like the ball clips into the platform.
Or maybe that's just the GIF.
I think that is just the gif
Can you show the full setup of the rigidbodies of both with a screenshot?
Hmm, why is the platform kinematic?
I'm just searching here btw, I always find this stuff rather obscure. If you want to wait for someone who knows more that's fine with me.
Okay, can you freeze the whole thing. It should still listen to the MoveRotation then.
Also, everything from the object is a child of the platform right? You followed the compound collider text?
I appreciate your help, don't worry
Everything is a child of the platform, yup
Kinematic off and with everything frozen fixes it breaking apart (I didn't realise that freezing stuff would still allow the rotation)
it does however stop collisions altogether
Okay, yeah, that's all hidden in the thousands of pages of the docs 😛
lol
Grr...
I find this is the problem with unity physics stuff, it's a bit finnicky
I've ran into similar issues before, it's usually a matter of the right combo of settings in the colliders and rigidbodies
Exactly, it can work, just figuring out how is a pain.
In case anyone else takes a look, I'll summarise the current setup:
Ball with a rigidbody like this is not colliding properly with the platform
Platform is being moved using rigidbody.MoveRotation() and is setup like so
It has a number of child objects that have cube or mesh colliders
this gif is what happens at the moment
I don't know then. 
But this is worse then it was previously at the start of this.
https://catlikecoding.com/unity/tutorials/movement/rolling/
3.4 Rolling on Moving Surfaces
3.5 Rotating Along With Surfaces
Is the closest I would find online.
Especially that part.
But that kills the fact that you roll off it. I don't know why that is, maybe it's the physics material that does that. Then maybe you can use that.
That seems to be more about implementing player controls for moving the ball rather than collisions
Setting the platform to be kinematic brings me back to the collisions working but the ball being super "bouncy"
Yeah, but the fact that his rigidbody doesn't completly jank on rotating/movement is maybe something you could look at. I don't know how he set that part up.
His plane and ball should probably have them setup so that doesn't happen.
Also, last thing I thought of, setting your Physics Material to 0 Bounciness.
Done already I'm afraid
Your Sphere collider here has no material?
yup
So you already tried it with a ball with a physics material then? I'm confused.
I've never had a physics material set
And I'm asking you to set one, because the default physics material has bounciness, and set the bounciness to 0.
If you give the platform it too, and set Bounce Combine to minimum it should help a bit more I think
thanks
Hello everyone, Im having a bit of trouble with my VR game,
Im trying to make the ball in video A be like Video B but in video A its super janky and i have absolutely no idea why
VIDEO A
VIDEO B
The ball in video A doesnt seem to carry over any momentum from my arm in the hand collission
please @ me if you decide to help me :)
because you're not moving the hand object in a physics friendly way
you're just letting the XR rig move it
which is not physics
typically you would do something like have an invisible kinematic Rigidbody version of the hand which follows the XR hand in FixedUpdate with MovePosition and MoveRotation
heres what i have setup, Theres 1 sphere attached to each ___Hand Controller
i was thinking id have to apply the motion by code, if you look at video B
Theres 2 different ways to hit the ball- With and Without a glove. a glove amplifies the strength of the hit by a large amount
yes like I said in my answer above, you need to create a "follower" object for the hand that moves via physics
that is the object that will actually collide with the ball and apply realistic physical effects to it
how would i do that
Im not sure if what you are suggesting is what im looking for. Have you checked the 2nd video, the way it feels its as if as soon as the object is hit. an instant force is applied to the ball. it doesnt nessesarily feel natural
all of that is doable
with the setup I explained
if you want to apply extra forces etc you can use OnCollisionEnter on the hand follower
does this seem right?
https://youtu.be/VG8hLKyTiJQ
In this video I'll show you how you can setup hand presence with realistic physics behaviour in a step by step tutorial for Unity.
▶ SUBSCRIBE : http://www.youtube.com/channel/UC-BligqNSwG0krJDfaPhytw?sub_confirmation=1
▶ PATREON : https://www.patreon.com/ValemVR
▶ DISCORD: https://discord.gg/5uhRegs
▶ MAIN CHANNEL : http://www.youtube.com/Vale...
idk, don't have time to watch it atm
👍
or just by the title?
wait @timid dove i just noticed in the player script for my rig i imported i noticed this
does this have anything to do with it
what about it
the hand followers
I have no idea
oh
I don't know why but for some reason enemy ragdolls always fly backwards no matter where they are shot
void Fire() //fire weapons
{
for (int i = 0; i < weapdata.bulletpershot; i++) //determines amount of bullets fired per shot
{
float x_sp = Random.Range(-weapdata.spread, weapdata.spread); //horizontal spread
float y_sp = Random.Range(-weapdata.spread, weapdata.spread); //vertical spread
//calculate direction with spread
Vector3 direction = shootpoint.transform.forward + new Vector3(x_sp, y_sp, 0);
//hitscan
RaycastHit rhit;
if (Physics.Raycast(shootpoint.transform.position, direction, out rhit, weapdata.range, bulletcoll))
{
if (rhit.collider.TryGetComponent(out EnemyBPHitbox ehp))
{
ehp.DamageTaken(weapdata.damage);
Instantiate(ehp.hiteffect, rhit.point, Quaternion.LookRotation(rhit.normal));
Debug.Log(ehp.name);
}
if (rhit.collider.TryGetComponent(out Rigidbody rbod))
{
rbod.AddForce(rhit.normal,ForceMode.Impulse);
}
}
Debug.DrawRay(shootpoint.transform.position, direction, Color.red, 2, false);
}
firespeed = weapdata.firerate;
}```
and in my enemy ragdoll script
{
anim.enabled = false;
foreach (Rigidbody rigid in ragdollrigbod)
{
rigid.isKinematic = false;
rigid.velocity = Vector3.zero;
}
}```
not sure if this is a programming thing or a physics thing
Hey, I have a spaceship that travels from point A to point B. It can accelerate with a known speed, and use brakes to stop. My goal is to make an algorithm that will tell the ship when to accelerate, and when to use breaks so that it would arrive to a destination with a zero velocity. Any ideas?
Hi, is there anyone who has experience with integrating SPH algorithm into unity? I'm mainly interested in the interaction of the partitions with the colliders. Thank you! 🙂
I've got a player object with a rigidbody and the player's hands are connected via configurable joint. I get a lot of nice behaviour from the configurable joints however at moment the when the hands move they pull the player rigidbody along with it. I'd like to keep what I've got but add some kind of limit to the hands to say that if they try to pull away from the player then just stop moving the hand and don't pull the player along. All the settings I've looked at for the configurable joint don't seem to do this
hello! any developer using the Realistic Car Controller? https://assetstore.unity.com/packages/tools/physics/realistic-car-controller-16296
Hello could i have some help. What steps would i go about recreating these physics
Can someone help please
I have a situation where I have a chain of jointed rigidbodies, and for some reason at lower masses they perform awkwardly, but I don't want to make the object behave like its tremendously heavy, is there any way to artificially add mass?
hey everyone , did any one experiment with collisions events on articulation bodies ?
I'm having this weird error where the object Doesn't Trigger the OnCollsion Enter function if its a child or an articulation body , move the object from it's parent to makes the event trigger normally , any thoughts on this ?
I can see a similar issue here but it says it's Resolved (I'm Using 2020.3.43f)
does the child have its own Rigidbody/Articulation Body?
yeah
Then that's expected behavior
each RB/AB forms a separate physics object. Collision messages only propagate within a single physics object
one of them isKienmatic
regardless
so I should remove one's RB ?
If the child is kinematic you may as well remove its RB
if the parent is kinematic and the child is dynamic then there's no reason to have a parent/child relationship in the first place
I might be missing something , but I have been trying to simulate the behavior of a simple suction sensor and it keeps giving weird behavior
Even ditched the whole OnCollsionEnter and used raycasting but the object still behaves oddly
Ok, I'm running into a problem trying to calculate fall damage.
I'm trying to measure fallspeed (which works), and when it changes enough cause fall damage (which... kind of works).
I want damage to be based on fallspeed squared. (so falling twice as fast quadruples damage).
This works fine up to a certain speed, because the player speed goes to 0 immediately. (Say, from speed 8 to speed 0, for 64 damage)
However, when falling fast enough, the deceleration seems to take place over 2 (or more) frames. (Say, from Speed 9 to 3 in frame 1 (for 36 damage) and 3 to 0 in frame 2 (for another 9 damage), for a total of 45 damage).
Player physics material is default zeroFriction; changing the physics material of the impacted surface changes the exact numbers but not the general behavior. The Code is being run in FixedUpdate.
Is there a way to make deceleration a single frame, or to somehow keep a tally of the deceleration and tell when it's done or something? (to apply the damage using the sum of 'recent' deceleration)
I can't simply use OnCollisionEnter to get relative velocities, or (for instance), touching the wall of the inside of a cube would prevent damage when you hit the bottom.
Hello guys, im having a bit of a problem with my code. I posted it before in different channels, but then i found this channel. I deleted my messages before.
So now my problem is that i want to create a 2D game where you can grab stuff and play with them. I already tried a couple of solutions, but none really worked like i wanted it to work. In the video bellow you can see that it shouldnt behave like that, how can i fix it?
- make them out of multiple "primitive" colliders (boxes, capsules, spheres)
- make a separate mesh for the collider only and use MeshCollider
just make GameObjects and attach the collider components to them
BoxCollider, SphereCollider, etc
as thick as you can
yeah bad idea
make it as thick as you can get away with
if it's like an external wall of the world with nothing on the other side, might as well make it 1m thick or larger
Hi everyone....
Why my glider collider cross inside the box collider..
the mass of rigid body in glider weapon is 100 and is trigger is off..
other box collider side I use nav mesh agent to move to my charater destination
presumably you are not moving your object in a physics-aware way
no i am move the charater through charater controller
Alr, i found a solution. The MouseFollower wasnt set to dynamic. It was Kinematic.
I am using a polygon collider in order to make the walls of the room solid. I want to be able to track what room my player is in using colliders. However when i add a box collider (that should detect if the player is in the room), unity thinks that the box collider is a wall and i cannot move. How could i remedy this?
make the box collider a trigger
Hi everyone....
Why my glider collider cross inside the box collider..
the mass of rigid body in glider weapon is 100 and is trigger is off..
other box collider side I use nav mesh agent to move to my charater destination
What method do you use to move the glider?
Any tips for making clothing physics and moving platforms work together?
I can't get moving platforms to carry the player well when using rigidbody movement (Best I can manage is adding the platform's velocity to the player, but that doesn't account for rotating platforms, nor does it work well on ascending/descending platforms) but moving them through transform manipulation (unsurprisingly) makes the clothing components badly misbehave.
Hello can somebody help me please, its been weeks of asking support but nobody will seem to help me
I helped you a few days ago 🤔
sorry, help me as in to get a solution
i dont think we ever got there
yessir
but as i showed you
the Spheres
dont they move via code since they arent parented with the controllers
or via physics you said i think
The whole "Gorilla Rig" is a public resource, i didnt make it
and i think what you were helping me with was getting me to realistic physics which isnt exactly how i wanted it
?
welp
this is a animation bro
Im pretty sure animation doesnt collide? I dont know tho. Havent done much with animation.
This maybe covers your topic: https://forum.unity.com/threads/collision-dont-work-when-object-is-moving-by-animation.534914/
yes the animation is colliding but the collider go inside from the other collider
ok thankx
I'll ask again, more simply this time:
Is there a way to get moving platforms to work with the Unity cloth component on a character riding the platforms?
The best I've managed so far is adding the platform's velocity (or getting it's deltaposition, then combining with Time.deltatime to get a velocity) to add to the player's. But that still causing the platforms to jitter and a lot of other behavior (especially with rotating platforms.)
question for colliders. If the parent object has a collider and it has a child that also has a collider, will functions like OnCollisionEnter on a script on the parent object also be called from the child collider ?
The question is does the parent object have a Rigidbody
Rigidbodies form the "unit" of a physical entity
if there's a Rigidbody, all colliders under it are part of that body and the object with the RB will receive messages for all of them
So would i be right in saying cloth does not work in builds..
https://forum.unity.com/threads/cannot-initialise-cloth-all-scale-components-must-be-non-zero-happens-only-in-build.1346033/
Having this issue in 2022.2.1f1
got it. yeah the parent has a rigidbody
but i call ontrigger from one of the children that has a box collider but not a rigidbody
you don't call OnTrigger, Unity does
so still part of the physical entity you said
right my bad misuse of terminology
i meant declare ontrigger on the code
yes you can put OnTriggerXX on either:
- the object that has the collider directly
- the object with the Rigidbody (if it's a parent of the collider)
got it thanks
is there good looking fur in unity?
why does my physics button only work sometimes
it behaves weirdly with the character controller
should I use rigid body instead
and how would I limit the y maximum
the button sometimes comes off the base
you're just sliding a static collider into it.
If you want physics to work you have to work with the physics engine
that means Rigidbodies and moving via Rigidbody methods
so stuff like character controllers wont work when colliding with them
I have a question. I want to manually program some simple rigidbody physics instead of using the rigidbody system. Because I need to update it at around 2000hz which I can't seem to do using the built in physics engine.
Now, the main thing I need to achieve is how to properly simulate an offset force impulse and what the ratio of linear velocity and angular velocity should be based on the distance from center of mass.
From what I found so far, people claim that the linear result is the same in an offset impulse as a centered impulse. And that the angular velocity is then added on top. For example described here: https://www.gamedev.net/forums/topic/548752-physics-how-do-you-calculate-the-result-of-an-offset-force/
is this really accurate though? Wouldn't this add more resulting energy than you put in?
The only things that are automatically physically simulated in the physics engine are Rigidbodies
Have you tried simply setting fixed delta time to 0.0005 ?
and using the physics engine as normal
i have not been successful in getting a high physics update frequency
what have you tried
i tried changing some setting in the project settings (if i remember correctly) let me check what it was
but with that said, i would still like to program myself as I want bits of the physics such as collision detection to have a slower frequency
what does "collision detection having slower frequency" even mean 🤔
ok and what happened when you did that?
it means that i will run a for loop reiterating the physics for certain things like spring physics, and then run the collisions outside this loop
i didnt get an increase in stability as i was expecting
i didnt notice any difference tbh
then perhaps your issue has nothing to do with the simulation timestep
perhaps
and you're chasing a red herring
that could be true
what is the default value for the timestep?
it was a while ago i tried this (running the physics faster) and i just decided to try this other approach now. that's why my memory is a bit fuzzy on some things 😄
0.02
i have it set to 0.005. but i will try to setup some experiments to figure out if it works
and get back
thanks for your help btw
this is only 200Hz btw
yea sorry typo, i had it at 0.001, and idk if its 2000. but that's what i figured out i want now :)
thats only 1000hz
so i want it at 0.0005 then
Just out of curiosity: why?
stability
i need a very light object to control a heavy object
if you keep increasing the forces, a light object will be come unstable and spazz out
unless you have a high simulation frequency
Control in what way? Maybe there is a way to fake it
i dont want to fake it
i can say what im doing, im making a car driving simulation
the "fake" way to do it is to just raycast the ground
but it doesn't give as good results as if you simulate the whole thing properly with a high frequency
i basically want to have rigidbody wheel hubs which are constrained to the car body. the car body weighs over 1000kg, and the hubs weigh like 5kg
the hubs needs to be able to transfer forces in a very stiff manner
i have already looked at market examples of what I want to try my best to replicate as good as i can (for fun) and the good ones have one thing in common. 2000hz simulation speed
Heys guys, is there anyway to set up the the 3D Hinge Joint angles more than 180 degrees?
https://answers.unity.com/questions/1851528/joint-with-limit-more-than-180.html
Unity is the ultimate game development platform. Use Unity to build high-quality 3D and 2D games, deploy them across mobile, desktop, VR/AR, consoles or the Web, and connect with loyal and enthusiastic players and customers.
CALLING ALL PHYSICS ENGINE EXPERTS!
I have a surprisingly difficult challenge, trying to write an equation for calculating different results from the Unity physics engine.
Specifically I want to write an equation that calculates the distance travelled while decelerating from a start velocity, to a full stop.
The real life equation is this: DistanceTravelled = StartVelo^2 / (2*Deceleration)
But this equation does not directly apply to how Unity handles forces, velocity and distance.
An easy example to demonstrate the difference:
Imagine you have enough force to stop at next Unity FixedUpdate frame. Eventhough you had some velocity before the stop, Unity will register this frame as 0 distance travelled, since it first makes velocity 0, then calulates distance based on this new velocity. The real life physics equation would always give a value above 0 however.
I have made a public GSheet where you can try these results for your self. As you can see I'm comparing the actual results Unity will give (going through iterations), to different equations.
https://docs.google.com/spreadsheets/d/1QIqq0pHTVNwshf71KT73VzGMIIC4OI8t7LXyxx2-_OY/edit#gid=614627238
In certain cases none of my equations are 100% correct. Can anyone deduct the equation needed? Or at least answer if it is even possible?
(Attached image shows a screenshot from my GSheet)
Helpful tips will be rewarded! ❤️
PublicSheet
VALUES,UNITY RESULTS,CALULATIONS
StartVelo,100,ActualDist,45,Real world physics equation
Accel,100
FPS,10,Frame,Velo,D,BreakDistance, =,StartVelo²
DeltaTime,0.1,0,100,0,2 * acceleration
1,90,9
EVERYONE CAN ,2,80,8,50, =,10000
CHANGE ORANGE VALUES,3,70,7,200
4,60,6
5,50,5
6,40,4,Bette...
Hey! Is it a bad way to attach like 100 box colliders to one object?
100 colliders shouldnt be a problem for Unity, no
But it sounds like it could be solved more efficient nonetheless
Do colliders occlude like textures when not facing camera?
No, all colliders must update regardless of scene view, unless you create a way around it
As always, you should include your actual use case, so that people better can help you with your problem...
So I'm gonna paint procedural grass on a large area and that grass is used to hide player from enemy view.
So I'm currently placing collider in grass area so that when player gets inside collider, enemy won't be able to detect player.
Using this way I need to place multiple colliders.
I'm currently thinking of whether to use multiple objects (each object have collider to hide player) at each grass area or use a single object having all collider.
And will it be efficient?
I would just try to create 1 collider for the entire area
But having 100s colliders is no problem for Unity usually, if you can't manage to make only 1 for the entire area
I'm not sure if it will cause problems for Unity's/Physx's spatial partitioning algorithm if the colliders are attached to the same GameObject or not
I don't think it will be a problem... Unity can handle multiple colliders, even of the same type, on the same object
I have a problem with joint in unity. Can someone help me to solve this?
When the joint is broken, other chains are spinning and flying away
good luck
Gotcha! Tnx♡
Could be so many things. Start by reading this: https://docs.unity3d.com/Manual/RagdollStability.html
hey guys, everytime i hiy play my wheels move here and the car sinks in
you can use a rope asset from the asset store. i like Obi Rope
Hi so I'm having a little trouble with my rigidbody, I'm trying to get it to slow down or break but it just keeps going
How are you moving it
I press space bar to make it go and I tried ForceMode but its not exactly working out
Please show the code. It's not the input that matters, it's the way you're moving it
Im using AddForce and AddTorque
How about the inspector of the rigidbody?
And please just show the code in case there's missing context
The Angular drag is at 15, unless maybe its the mass? But I didn't change that
Also, no gravity
🤨 But I just told you Im using AddForce and AddTorque...It's not like you need to see my Text functions
Why are you making this difficult
I'm not, you are
I said it's in case there's missing context
<@&502884371011731486>
So much for not looking to argue
:/ I didn't do anything wrong, I gave you the information
Needed more information. I'm stepping away from this
Ok
If you're requesting help, then you need to show code. It's just that simple. Nobody is going to assume you're doing that part correctly, hence why it's been asked to share.
Also osteel, do let me know if this is an inappropriate reason to ping. They're not really breaking rules, but just not quite understanding how to get help
It's fine 👍
😅 But my code isn't having issues....I just need to ADD to it thats why Im here, Im asking how to add some sort of force to make it slow down. It has no problem otherwise
Its working fine, I just need to break
Im not having an error, I just want to add to it
Using add force usually allows things to slow down on their own. It's not in this case, hence why I want to see the code and inspector to look for something irregular..
Your initial post implied you had issues.
If you want to slow down outside of increasing the drag, then you need to add force in the opposite direction to slow it down.
My drag is at 15, You really suggest more?
Ill give it a try
Wait
Angular drag or normal Drag?
Normal
Is there a way to tie physics to the framerate?
Im making a vr game and nomatter what i set the physics timestep too there always ends up being a very noticable stutter every second
The game wont actually use that much physics other then basic "I hit wall so i should bounce off" So am i better off writing my own simple physics solution to keep the graphics perfectly in sync with the physics?
physics needs to use a fixed timestep for very good reasons
the simulation will become unstable otherwise
Typically if there's a stutter you're doing something else wrong though
first off, make sure you're using interpolation on your moving Rigidbodies
otherwise - you'll have to explain more about this "stutter" if we are to fix it
I am using interpolation
The best way is like a jump
[| ]
[ | ]
[ | ]
[ | ]
[ |]
Imagine this is the edge of a wall over time as my player is floating left
Its super smooth and just jumps
Im doing the most basic UnityXR Toolkit with the bare minimums
idk what this means really, you'd have to show the exact situation and code etc that is causing a stutter
Im not using any code
but what are you using
you're talking about VR. Is the player attached to a dynamic body or something?
you'd have to explain the setup
the hierarchy
the components involved
etc
Have you ruled out just a run-of-the-mill framerate hitch? Not necessarily physics related.
Its consistant in both editor and builds, and i can tell its not an actual frame drop in vr
^
Ive sinced closed unity but
Parent object with the XR Base stuff with the Rigid body
Sub object with XRCamera tracker
Thats it
And some small enviroment polys to actually see something
I can reopen it if needed
it's not typical to have an XR rig attached to a Rigidbody
that is quite an unusual setup
it also seems like... a recipe for motion sickness disaster 😵💫
Well its a zeroG game
All of the players in it are coming from a zeroG vr game so motion sickness isnt an issue
thank you
Hi guys! How would you make a creature like the ones in this video: https://gfycat.com/fatherlyshabbyeider ? Because I initially started doing some procedural animation with just IK, but adding physics to it just breaks the whole animation..
Some years ago I did a 2d project with a stickman that self balances, but as far as I can see there's no IK in my script, just a script that knows what the correct position of each bone should be like, and then tries to correct it each frame using a torque force on each joint (and to move it, I just move the body which has a joint to every limb of the stickman).. I don't know if I should go this route to make my new project, but their robot seems a lot harder to do than my stickman
Do you think the robot in the GIF is so physics-based that it would stand up if it fell over for example?
Yeah (or at least it would try)
That's epic.. I would not know how to do that xD
I don't know if the author has done something like this.. but he's the CEO of Landfall Games, he's famous for its physics based games
But please share if you find good answers
In a comment he said Yeah! Rigidbodies + IK for legs
Mmh.. but I don't understand how to combine IK with rigidbody
hey guys, ive recently started this new project for a simple racing game, ive tried so many vids from yt an litterally copy pasta everything cause i could never get it to work and still it didnt work, now does anyone have any idea why and what the hell this is happening? If you could explain it aswell that would be highly appriciated so i can learn! :)
try to make the vehicle work first without any 3d geometry
using just game objects, colliders and rigidbodies
you can also use edy's vehicle physics or vehicle physics community edition for rigged vehicles along with all the other stuff you need
i tried that already just with a cube and 4 wheel colliders, still nothing
okay i managed to make it work with normal cube, but the steering is kinda weird now lol
i fixed it :D
but now with the car it does that weird thing