#⚛️┃physics
1 messages · Page 72 of 1
No
That's also going to be true at a certain part of the jump
Found out the way, thank you!!
how could i use general relativity instead of newton's gravity formula?
script from brackeys btw
const float G = 6.674f;
public static List<Attractor> Attractors;
public Rigidbody rb;
void FixedUpdate()
{
foreach (Attractor attractor in Attractors)
{
if (attractor != this)
Attract(attractor);
}
}
void OnEnable()
{
if (Attractors == null)
Attractors = new List<Attractor>();
Attractors.Add(this);
}
void OnDisable()
{
Attractors.Remove(this);
}
void Attract(Attractor objToAttract)
{
Rigidbody rbToAttract = objToAttract.rb;
Vector3 direction = objToAttract.transform.position - transform.position;
float distance = direction.magnitude;
if (distance == 0f)
return;
float forceMagnitude = G * (rb.mass * rbToAttract.mass) / Mathf.Pow(distance, 2) * .9f;
Vector3 force = direction.normalized * -forceMagnitude;
rbToAttract.AddForce(force);
}
for gravity, taking in mind the perfomance ussage
I have several colliders on my Player. Each collider is in a different child game object. When one of these colliders collides with a collider on another object, I need to know which collider on my Player hit the other object.
Using: OnTriggerEnter2D(Collider2D collision)
collision.gameObject.name OR
collision.gameObject.tag
give the name and the tag on the other object the Player collided with.
Is there a similar way to get the collider, or tag, or gameObject name, of the collider on my Player that hit the other gameObject?
If I set an OnTriggerEnter2D method on an Object whose Collider isTrigger, it will only be executed when it "collides" with another isTrigger collider right?
@last stump If you go to the bottom of this Unity docs webpage, there is a Collision Action Matrix, that is supposed to answer all possible collision detections: https://docs.unity3d.com/Manual/CollidersOverview.html
Have a look at this and see if it answers your question.
Thank you so much
@last stump You're welcome. I found that table very useful last week.
Hi, how can I calculate the needed velocity for y? I have a constant x speed and have the point the target has to reach as the highest point.
i thought about this formula but it gives me the vector v_0 how do i get the y component of it?
The red lines are rays from ControllerColliderHit.point in the direction of ControllerColliderHit.normal. The player character is running and jumps along the wall at a shallow angle, touching the wall as he moves, from left to right.
At the top, there's a gap I'm not sure about? Perhaps it's late and I have a bug? Or is this expected behavior somehow, in that the hit.point is coming from a different point of collision since the player starts moving down instead of up?
this looks like a good tutorial: https://www.khanacademy.org/science/physics/one-dimensional-motion/kinematic-formulas/a/what-are-the-kinematic-formulas
there are those 4 kinematic equations (with constant acceleration) that are wiggled around for what you need, more than one way to solve them
I've figured out that objects with less friction bounce more from it. But i dont want objects to always have little friction, so is there any way to set an object's friction on impact?
Actually nvm it doesnt seem to change anything all too much
ugh
I'm extremely stumped on how to make it more bouncy
What's the physics material for the ball look like?
Well the ball isnt the only object that needs to be bounced by it but it has a friction of 0.4 and a bounciness of 1
Do you have bounce combine set to maximum? What objects is this material on, in reference to your video
I dont even know what bounce combine is and its only on that ball
It's a parameter that you'll find on the physics material
i dont see it i only see friction and bounciness
oo nvm, that's not on 2d physics 😅
then what should i do
ive tried modifying every aspect of the objects and the jelly and nothings been working
Again I used https://www.youtube.com/watch?v=3avaX00MhYc to make the jelly
If that helps to understand how to fix it
i set the frequency on the spring joints to neighbors to 10, and instead of setting them to opposing bones like the tutorial i made a center bone and made a third spring joint connecting to it with a frequency of 2
Hi there! Total beginner here. I could use a little help with collisions/rigidbodies. Should be really basic stuff I guess. Anyone up for a short 10 min call so I can describe the problem better?
I thought it'd be a little bit easier if I can show stuff but ok, I'll try:
You can share videos or screenshots
Basically, I've got a really really simple movement of a character that I really like and I want to keep the way it works, but lack of knowledge about the built-in physics makes it bork collisions.
Script is this one:
https://paste.ubuntu.com/p/Brw9FvyzCj/
Now what happens is I can sort of "squeeze" through walls.
I've researched a bit and apparently the best way is to just switch to RigidBody.MovePosition, which I explored as you can see in the script. But that just makes it worse, it still is able to go through walls and the movement becomes jagged. Surely there has to be an easy way to realize this movement?
this is the squeezing in question
It obviously recognizes the collider either way and tries to push out and I just translate too fast through it but how would I solve this
MovePosition shouldn't really be done in Update
since it's physics related it's be something you do in FixedUpdate
but really - you might have better luck with modifying the Rigidbody velocity instead
I know I got this far (which is why there is a FixedUpdate stub)
Hmm... Kinda sad, I was hoping I could keep this simple because that's really all I need for movement
I don't think setting velocity or doing MovePosition in FixedUpdate should be terribly complex
MovePosition in FixedUpdate I tried, as I said
It's the same behavior just more jagged.
did you remove the Translate call when you did that?
Yes, of course
can you show what you ended up with?
https://paste.ubuntu.com/p/NbpnVggFSS/
(I know input shouldn't be done there but I hardly believe this is the problem here since it's still going through the walls)
hmm that honestly shouldn't tunnel you through walls...
you have colliders on both objects right?
Yeah I do
Wait is your Rigidbody kinematic?
That's what has been confusing me for the past two hours
Nope
Player character is non-kinematic
🤔
See if this is any better?
https://paste.ubuntu.com/p/zZFHBNW36r/
Well the good news is, it doesn't go through walls now. However it controls a lot more awkwardly. Of course I can build around this and manipulate the velocity a bunch, I just had hoped that I might be able to avoid just that. :/ Anyways, thanks for the help!
Ok cool. Not sure why MovePosition wasn't working TBH
as for the "jagged"-ness try turning on Interpolation in the Rigidbody settings
Oh yeah, that fixed that problem! Nice!
@snow field id rather move here for this, could i get your settings for your wheel colliders?
im using them and have a serious sliding problem
I've got a similar problem to volatile_integer's, except my moving object isn't colliding with walls at all 🤔 I've tried just about every combination of the moving object and the wall being Kinematic or not & the different combinations of interpolater's and collision detectors. Heres my code for the moving object if anybody can help
https://gyazo.com/8536c704364071c89f2bf4222f9cd303
and here it is in practice if it helps:
https://gyazo.com/757bc7eaea8948b25104e1dfa8e41569
You can see the paddle that follows the ball collides w/ the wall so idk why the pong isn't doing the same
I thought it might be because my code is causing it to constantly gain forward force to overwrite any collision but its reached magnitude > 3 by the time it reaches the wall so I don't think that line is running by then
Nvm, I'm a stupid idiot and 'Is Trigger' removes collision or something I guess 🙂
I want to turn off physics for my game but, I would like to use colliders. Is that possible?
It's bouncing great now, but the softbody is too slippery and easily gets stuck in things. How should I fix this?
Yes just have colliders without rigidbodies
and the collisions will be detected by a ray
I dont see how that would require a rigidbody so in theory yes
@pliant fern ty
No problem :)
I'm looking to have a specific rigid-body collider only apply friction based forces, no position or torque acceleratoin.
apply them to what, some other body? itself? a little confused
well its a collider on a child object, don't want the collision to effect the rigid-body on the root. I just want to know what forces it would have applied due to friction.
you'd have to probably use something like this:
https://forum.unity.com/threads/experimental-contacts-modification-api.924809/
or use a trigger collider
and do your own calculations
I gave both these objects a collider and rigidbody but the guy keeps falling through the floor whats wrong?
Nvm
I, too have a sinking in the floor problem :D but mine is a bit more weird
i basically have two cubes and on one side everything is fine, but when my little cube goes to a certain spot on the big one, it just slowly sinks/bugs through it till it falls out of the world
i have no clue at all what unity thinks is different about this certain spot, because there is nothing
could be something in your movement script(s)
look at the collider it's tiny
the 2 little cubes have the same code for that (tho it is controlled by ML - as that was what i was trying to get the hang of with that :D) but it still only happens to the grey one. they are the same size too (both blender default cube xD) thats why im starting to run out of ideas
could be the machine learning stuff? IDK.
yeah maybe thanks for thinking with me :D i guess i will control it manually to the spot and see if it still happens
well.. at least i can do something else while waiting x)
fysics.
should i post my question about rigidbodies here or the #🖼️┃2d-tools channel?
here
~~Hi guys, I am having a very weird problem:
My gravity appears to be being wrong. The image attached shows a cube, dropped from a height, after 10 seconds of continuous falling. As shown in the highlighted boxes in the middle and right, the cube has:
gravity = -9.81
rigidbody drag= 0.
No other components are acting on this rigidbody (I literally just attached it to the cube to debug the same problem on my player character), so this is not a problem of my resetting the velocity every frame myself, at least, not on this object. Also, there is no physics material attached to the cube collider
On the left red box
velocity = -58.46 in the y direction.
time = 10.1 seconds.
These values are not correct, see below:
Using v = u + at
-> v = 0 - 9.81 * 10.1
-> v = -99.08
I have no idea what I've done wrong. My only thought is that the units could be messed up, but I can't find anything about that online. Anyone have any ideas?
Update:
I have tried disabling gravity, and adding a separate acceperation of -9.81 downwards, problem persists~~
Worked it out nevermind (physics only starting after a few seconds has passed). Sanity restored!
Hello everyone, i have a problem that i can't really think of a solution for.
I have a rigged character imported from blender into unity. i turned it into a ragdoll and so far everything's fine.
I'm working on a system where player can disable/enable ragdoll by clicking it. I checked it several times, the script is working properly.
the thing that detects player's raycasts is ragdoll's top parent which has a sphere collider (with "Is Trigger" enabled)
The problem is as ragdoll starts moving like normal, the sphere collider stays in the starting position forever and because of that, player has to click on ragdoll's starting position instead of ragdoll itself
As you can see in the picture, Ragdoll starts working but sphere collider, which is where player has to click, doesn't move (which is because it's attached to the parent)
another problem is if i remove sphere collider from parent and attach it to the ragdoll itself (armature) raycast won't detect it.
If you have dynamic rigidbodies as children of your parent object, they will move independently of the parent
you need the sphere collider to be at the same level or lower in the hierarchy as the primary dynamic rigidbody
"the thing that detects player's raycasts is ragdoll's top parent which has a sphere collider (with "Is Trigger" enabled)"
You cannot have the collider track the model if it is attached to a gameobject which is a parent of the object it is tracking, because moving it will also cause the model to move.
Attach the collider to a new game object which is a child of the model is the right solution. It's strange that this isn't working. I suspect that the armature of your object has the same origin even when the bones move. I'd make it a child of one of the bones instead
Basically - make the sphere collider a child of e.g. the chest bone or something
Any idea why this happens? It doesn't matter who is the host and who is the client, the one in the built version always has legs that drag behind. What about the build could have caused these procedural legs to lag behind in the built version?
Dunno if this is exactly physics-related, but I have questions regarding, uh.. stars..
I'm a virgo
How do I improve physics collision on my project
I can phase through walls if tried
I was working on a golf project and am facing a bug. Whenever the golf ball rolls from the fairway -> fringe -> green (3 different sections of the golf course with their own respective mesh colliders), I get unexpected jumps and bounces. I tried making the "Project Settings -> Physics -> Default Contact Offset" around 0.0001 as I had read on a few other threads that this might fix my issues, however, I had no such luck. I cannot restrict the ball's Y position as the golf course has some slopes and the ball, therefore, needs to be able to move along that axis. Can I have some help with this? (https://i.imgur.com/KPsR7tW.jpeg screenshot of the bug I'm facing)
Hi umm, why isn't this physic material applying to the box collider? Can anyone help?
Nevermind, found it!
I have a player object with a kinematic rb. It does collide with one enemy type, but not with the other, even though they are on the same Layer and their rb are exactly the same
A Kinematic Rigidbody 2D does not collide with other Kinematic Rigidbody 2Ds or with Static Rigidbody 2Ds; it only collides with Dynamic Rigidbody 2Ds.
from the doc
if that's not it then check your colliders
and your collision matrix
I know, thats why all of my enemys are dynamic
They are exactly the sam on each enemy group
They live on the same layer, and the layer they are living on is allowed to collide with the player
then either send screenshots of the 3 objects or simply build the other enemy from the working one.
Since it's 2D it should be not that hard to build one from the others and you'll probably find the issue that way
That was exactly my thought process. I replicated the melee prefab and just changed the attached movement script, as well as the color, and suddenly it the ranged enemy cant collide anymore. The movement script from the ranged enemy inherits from the melee script.
Is it possible, that constraints, such as freeze position, disable collisions?
How many units per seconds do things fall under normal gravity settings?
depends how long they've been falling
they accelerate at 9.81 meters per second each second
so after 1 second they will be moving 9.81 meters per second down, assuming they started from rest
oh cool
is there any code you can write to find out how long something will take before it touches the ground
You can calculate that using kinematic equations, yes.
take any of the equations where you know all the variables except for t and solve for t:
Alright I'll do some more research on those thanks!
Can anyone tell why this goes only right, even if I press A and D?
I can share the code if needed.
Obviously nobody is going to be able to answer that without seeing the code.
@sacred parcel Use a bin site for large code. #854851968446365696 for links.
I got this code from a YouTube tutorial.
It worked with the in built sprites like basic shapes, but didn't after I put in the new model.
You mean to share the code?
Okay...
@wide nebula Is this okay? :)
Yep.
Line 78, you're using the RightVector on your move left forces.
But it is multiplied by -0.5f.
Look at the pattern of your four function.
When you're moving right, you're applying the WalkRightVector, and vice versa when going left. Except on line 78, you used the opposite.
Ohh, now I see!
Thanks!
If that doesn't solve it, then just make sure your WalkLeftVector is actually pointing to the left in your inspector.
Sure thing!
Okay, just realised I did a 20 in both Left and Right Vectors.
Silly me!

I use rigidbody physics for my player, and am realizing that I have stutter due to using transform.rotation =. There probably is not an easy way to convert my rotations to angular forces, but maybe someone here has experience with it and can provide guidance?
Rigidbody.AddTorque, basically
torque is "angular force"
you can also do Rigidbody.MoveRotation (in FixedUpdate)
Right, Rigidbody.AddTorque is what I intend to use. The trick is figuring out how to convert my rotations that I was previously applying to the player into equivalent torque forces
MoveRotation will be simpler
but... yeah torque is torque. 1 unit of torque will accelerate the rotational velocity of an object with inertia tensor of 1 by I think... 1 radian per second^2?
any chance OnTriggerEnter2D doesn't trigger when enabling collider 2d, and colliders intersect already?
And if so, what can I do about it?
I've recently finished struggling with this, it can be a headache even with addTorque.
See here for some useful conversion functions between toque and rotations per second. https://gist.github.com/ditzel/1f207c838f0023fcbd34c5c67955fd25 (not mine, they came from https://www.youtube.com/watch?v=BNiAt0HnC5M). What you need to do is to decide what fraction of a full rotation you need to cover in a single fixed timestep t (eg, 2 degrees of rotation per frame), then plug that into the rotations per second (RPS) to torque calculator. If that rotation would take you past the desired rotation (ie, the rotation is complete on the next frame), subtract the remainder so that you end up exactly at the desired rotation. If it is a character rotating, it will also look better if it is nonlinear, eg, to have a low RPS at the start of the rotation, high in the middle, and low again at the end. You can use a sin wave for this. Find the time required for the full rotation to complete (call this T)- which should scaling linearly with the angle between current rotation and the desired rotation. Then use _RPSMultiplier = sin(PI * physicsTimestep/T). Multiply the RPS you use by 2 * _RPSMultiplier, this way your average RPS will be approximately the value of the original RPS value you set. You could also use an animation curves for more fine grain control than the fixed values a sin wave will offer
However, the problem may well be with your camera too. Make sure the rigidbody is set to "interpolate", and that the camera is not a child of the rigidBody gameObject, and should track the rigidbody in lateUpdate. You might still see some subtle stutter after doing this. God knows why - it's like rigidbody interpolation doesn't work 100%, which seems unlikely - but you can clean this up by separating the model from the rigidbody, and making the model track the rigidbody with aggressive lateUpdate lerping/damping (ie, small timestep so the model lagging behind the collider is not noticable)
Unity Physics can be hard. And it is even harder, if you do not know the basic principles. I will show you the core basics in rigidbodies, to give you a kickstart in this topic. In this tree part tutorial you will definitely understand things like .AddForce, .AddTorque and .CenterOfMass way better than through the unity manuals and offical tutor...
Thank you so much for this, I'll do some deep diving
Lots of useful info here
(I'm guessing this is where I would put this but) I'm wanting to have the falling speed be a set number so that this doesn't happen, but I don't want to affect the jump height/speed , does anyone know how to do this?
(so clipping like this doesn't happen)
be a set number so that this doesn't happen
What is "this" ?
but generally speaking you can:
- change the the gravity/mass dynamically, increasing it when the player is falling rather than jumping.
- calculate the initial gravity scale and jump force based on the desired falling speed and jump height/speed.
I already got it fixed, it ended up being a solution of changing it so when the velocity is going down, the gravity scale is changed, and then when jumping the gravity goes back to normal
option #1 then 🙂 cool
yeah
Learn how to make video games!
Top-quality game development tutorials on everything from Unity and programming to game design. If you want to become a developer this channel will help guide you through it!
Join us on Discord: https://discord.gg/brackeys
You will get everything you need on this channel
How can I make a Gameobject ignore the player ( and the player ignores it )
but still check if they collided?
if by ignore you mean not actually bump and stop each other, make one a trigger collider
look into Triggers Vs Colliders
ohh
THanks alot
how would one use a blender-made armature to implement ragdoll physics
see if you can't find a tutorial on youtube for that. I'd guess there are many.
When would I use a Rigidbody2D. Because if I create a 2D Objects -> Physics -> Static Sprite, it puts a rigidbody on it, but if these are removed it still works the same.
VR: I have kinematic rigidbody on hands with capsule colliders for fingers, and floating objects in scene with non-kinematic rigidbody. I can push the floaters with my hands, but no force is applied, meaning they stop instantly when I stop pushing, whereas if I push a floater into another, they bounce apart and float off. Do I have a setting to change to get the kinematic body to impart force/velocity on the non-kinematic body?
You use a Rigidbody if you want Unity to apply a realistic physics simulation to your sprite
thanks
You need to move the kinematic body with MovePosition
otherwise your kinematic body is basically teleporting around each frame and there's no actual force/velocity to impart
either that or detect the collision and apply forces of your own based on your own reckoning of the motion of the hands
hey im kinda retarded and i have a question, but i made a diagram
i want to turn a quat into a byte that just gives a quadrant level detail of rotationals
can someone tell me if i'm 1) retarded, 2) on the right track 3) can't make diagrams for shit, 4) there is already a built in unity for this or i guess to just f myself
the reason behind this is to not sully my beatiful netcode but avoid spinny boi gimble lock situation
which doesn't happen often at all, but can
Not really understanding what you are looking for with this diagram/explanation.
Also have no idea what you've tried already so no comment on the "on the right track" bit
i haven't tried much of anything, besides imaginging some bloated not very eloquent code to figure out the quadrant i'm in, so to speak
again i apologize for being this level tarded and also terrible with various forms of microsoft paint products
its like, in my beautiful netcode that took so long to make i lost sight of my game, i'm syncing 15 rigs in an active ragdoll game flat hierarcy no animations in 33 bbytes and 1 bit
your diagram is mostly consuing to me because the labels for sw nw ne se don't line up with what I'm expecting when you say "quadrant"
but i do occasionaly get a gimble lockish situation
ar ethey suppsoed to be 90 degree slices?
and the rest of the words in the diagram seem like nonsense to me. Hip? each flag w/nef togg 0000. is no lean?
?
top to bottom, like, south west bottom to north east top
etc
actually it hought about it, and i think 11 11 11 11 would be standing stright up
for my convention
huh
i'm gonna use [flags] on a byte
ok it's a bit field
so not going to evaluate it to a decimal, just as flags at each bit position
so i have access to my hip's full transform right
but i want to send it over the innerwebs, and my glorious netcode bein 33 bytes and a bit, i can't have anymore than another byte before it hurts my feelings and my pride
and i really don't need more than like, a very crude way to represnt which sort of, very general way the hip may be tiltted
if you just want to encode which quadrant you're in (4 possibilities) that's only 2 bits of data
unless I'm missing something
unlabaled are the bottom 4
becaus i could be inmverted
upside down
breakdancing, etc
I don't understand
on head
but if i want to lean forward
thats a north east positive, and a north west positive
thats why if i use a byte with [flags] i can get more than just the vertices
leaning backwards would be southeast positive and southwest positive
Maybe it would have made more sense if you explained from the start what you're trying to do
leaning left, rightside up would be northeast positive and southeast positive
You're trying to represent... the leaning of your character?
i'm tryin fam, lol
i really am
yea
everything is relative to hip, its an active ragdoll all rigs, no animations, flat hierachy
because you just kinda started with "how do I turn a quaternion into a quadrant of rotationals"
yea, i' am so like, dumb in this area, its hard for me to even phrase the question
which is why i wanted to apologize in advance for being tarded
but if you stick with me, i believe in my heart of hearts i can convey this crakced out idea
i have my transform, and access to all its transformy things, quat, eulers etc, and if i can figure out how to translate that as per bad diagram into a byte, i know how to use this byte on the receiving end
the level of detail here would be like, a D-pad with diaganols
but 2 of them, on top of each other
maybe i could just use 1 and then have a bit for if i'm upside down..
i donno, this is kinda hurtin because i still dont even think unity could possibly give me all thse frames with all those update loops
i have a programming background, not a graphic design one, if that is'nt painfully obvious
without flags, that would be 9 bits,
which is absolutely unacceptable
i need 8, there's gotta be a way to do this with flags
but more importantly, theres gotta be some kinda unity functionality to handle the majority of this mathfs
I think you may be approaching this wrong. If your game works in such a way that the player can only be... "arranged" in those 9 possible orientations (all 8 +/- quadrants and neutral), then you should model your data that way
use "Unity's transformy things" as the presentation layer
no no no, everythign works fine as is without any rotaional daata of this form
i occassionally get on rare occassions spinny boi gimble lock
then there's no need to convert from a quaternion into such a form
i figure i could sanity check on remote players side to correct this
and also you will be able to avoid gimbal lock things
you said there's no animations right?
code driven
it takes a byte
everything is done via forces applied to rigs
this is the entirity of my receiving end netcode for all 15 rigs
this.netRecPlayerRotationX = (float)stream.ReceiveNext();
this.netRecPlayerRotationY = (float)stream.ReceiveNext();
this.netRecPlayerPosition = (Vector3)stream.ReceiveNext();
this.netRecPlayerVector = (Vector3)stream.ReceiveNext();
this.netRecPlayerAnimationState = (MovementStates)stream.ReceiveNext();
this.netRecIsADS = (bool)stream.ReceiveNext();
33 bytes and a bit
movementstate is my flags thing i use to pick my code driven animation forces
its a byte tho
rotation x and y are camera/gun angle
playerposition vector3 is hip
playervector vector3 is the current inputs direction of travel so to speak
and then the others, yea, i could fit fkin ads into the animation state but i need it with that data
then to adjust each rig, its all relative to the hip + my animation state based stuff like this ```cs
Vector3 position = this.PlayerHip.position;
Vector3 vector = Vector3.Lerp(position, this.netRecPlayerPosition, Time.deltaTime * 1f);
Vector3 vector2 = Vector3.Lerp(position, this.netRecPlayerPosition, Time.deltaTime * 1f);
Vector3 deltaVector = new Vector3(vector.x, vector2.y, vector.z) - position;
foreach (Rigidbody riggy in rigidbodyHolder.rigs)
{
riggy.MovePosition(riggy.position + deltaVector);
}```
which is called from a fixed update loop after checking the player is not local and therefore neesd to be updated via the netcoders
it works really well, except sometimes, homey be spinnin a bit, and doesn't udnerstand concept of upside down, which can cause more spiny boi
so i i have that byte, i can kinda just invert some things to get him approximately oriented
ignore the redundant lerpin btw
since you (usually) walk but not always, y lerps dif than x/z
....normalized signed values of cross product of netRecPlayerPosition against netRecPlayerInputVector maybe?
i've got several, would you like networked or not networked
and by me, i mean, poached open sauce github repo's that i forked or at least starred
even got 3d networked among us , i hear that's what the cool kids are playing these days
programming is just a symptom of a failure to master good googling or lack of trying, i mean, as per rules of internet if you can think of it , it must exist
what
Ok so I know nothing about netcode, but as I understand it you are trying to encode rotation information into a single byte?
Your diagram is wrong. Eg, if SW = 00 and NE = 00, then:
If SE = XY and NW = XY, then you have no lean, for all of XY = 00, 01, 10, and 11, they cancel each other out and information is lost
If we have an origin at the centre of the cube:
Now draw a vector out to the midpoint of each edge, the centre of each face, and each corner of the cube. That is 26 possible directions the character could be leaning in. If we also care about the rotation of the character at each value of lean (ie, a character standing straight up should still be able toface in different directions), then we could also get away with having 8 rotation values at each point the character can lean towards, since 26 * 8 = 208 bits, which is less than the information is one byte = 256 bits. So for one byte, 0000 0000, I would use the first 5 elements to represent lean, the last 3 to represent rotation
I think you cannot represent lean by using angles, since you will need 2 rotation axes with 8 bits of information each to represent 8 possible values in each of the two axes, which would require 64 bits to represent lean, and 64 * 8 = 512, which is > the 256 available. The reason for the information loss is that, for example if we are using conventional Unity x and y euler angles, then at x = 000, or x = 100 (directly up or directly down) the y value is irrelevant.
I think the easiest option is actually just to use those 26 possible lean directions as possible values in an enum. So in the attached image, there are 6 possible intersections at the centre of each face, give each of these its own specific value of the enum. Do the same for all 8 directions pointing to each corner, and all 8 pointing to the middle of an edge (they should all be a part of the same 5 element bitfield). Then do a switch on the bitfield on the client side to find out which direction you are leaning
So in case thats not clear, diagonally upwards elements would continue from the previous values like so:
so say you had a bitfield 0010 1011.
Create a copy of this bitfield client side and zero out the last 3 bits in this copy, so you now have 0010 1000.
Now do a switch on this enum. You should find that your lean value = horizontally left, from the first image.
Now work out your rotation at that lean from the last 3 bits of the original bitfield
Im hoping someone could possibly help me with the set up of my chain for my lantern... you will see from the video i am getting rather strange results!!
sorry if posting a video isnt allowed (i will remove it if so!)
If anyone can spot what could be the problem, any help is appreciated
Is there a way to use RaycastAll and hit the same collider without having to store the hit.points and raycast all over again?
what do you mean by "hit the same collider"?
Hi, I've been looking at previous replies here and in the forums but Im unsure, is there a single working networked physics solution for Unity apart from quantum/photon (which is out of the question because of price)?
Not sure what your price constraints are, but you can also check out NormalVR
mirror is an option
thanks, my constraints are certainly enough that quantum isnt an option. Im going to check that
I use mirror in my games, does it actually network physics enabled rigidbodies?
thanks. weird, I've used mirror for a couple of years and never actually noticed that networked rigidbody component, is it recent? it shows up under experimental on git
damn. thanks for pointing it out. feel kinda dumb rn not gonna lie
shifty pete! thank you for looking into my hard for me at least to articulate question so thoroughly!!!!!!! This is extremely helpful, it's actually above and beyond my issue! I think you have thoroughly enough answered this that i can work on it, but to be clear, I do already send 2 floats worth of rotation (camera x/y), however, the point of my theoretical extra byte is basically simply to stop occassional, at least what i believe to be a form of gimble lock, where other players appear to spin, and additionally, if do to physics interactions in the level, and the player becomes somewhat or all the way inverted (updside down) they again either spin or glitch a bit beyond what makes it a fair fight, and this can be exploited. This is why i was looking for this kinda, lowest level of detail rotational system, just to perform a sanity check on remote clients so i can either course correct or proactively check somehow to avoid the gimble lock (if it even is that, i think it is, but i'm not an expert on the subject)
ok so i have some code to keep an object rotated towards an aimed at point, however it doesnt consistently work - it will work most of the time until it gets bumped massively in which it stops working
(blue is where im aiming / where it should point, red is where it is pointing)
ive tried variants using vectors / quaternions, with changes and they all seem to have the same issue
for the video linked, currently using a vector method (below) and it doesnt work
Vector3 dir = (pos - transform.position).normalized;
float aimPct = force * stats["aimStrength"] * selfWJ.moveResist * Time.fixedDeltaTime;
transform.forward = Vector3.Lerp(transform.forward, dir, aimPct);
ive also tried this
Vector3 dir = (pos - selfWJ.rb.position).normalized;
Quaternion dirRot = Quaternion.LookRotation(dir, Vector3.up);
float aimPct = force * stats["aimStrength"] * selfWJ.moveResist * Time.fixedDeltaTime;
selfWJ.rb.rotation = Quaternion.Lerp(selfWJ.rb.rotation, dirRot, aimPct);
and this
Vector3 dir = (pos - transform.position).normalized;
Vector3 dirRight = Vector3.Cross(Vector3.up, dir);
Vector3 dirUp = Vector3.Cross(dirRight, dir) * -1;
Quaternion dirRot = Quaternion.LookRotation(dir, dirUp);
float aimPct = force * stats["aimStrength"] * selfWJ.moveResist * Time.fixedDeltaTime;
transform.rotation = Quaternion.Lerp(transform.rotation, dirRot, aimPct);
to no avail
however, if i directly set the rotation rather than lerp it works
this also happens if i use RotateTowards rather than lerp
what is the purpose of having the lerp function use aimPct as the third parameter
what do you mean thats what lerp is used for, for going smoothly between 2 vectors by an amount
im just using some extra stat variables along with time.deltaTime
@torn creekas long as dirRot is the correct rotation, there is really only 1 option
unless....
you're using a non-kinematic rigidbody?
isKinematic is set to false
when i set it to true i believe it was working temporarily but havent managed to get that to work again since
I think the rigidbody and the lerp are conflicting
but obviously i want it to be non kinematic as i want physics on it
thats what i thought, however i am using the rigidbody.transform / rotation
i did wonder if it was that tho
increasing?
oh that actually worked
so is it because the transform and the rigidbody rotation are going against each other?
well
so angular momentum stops the rigidbody somewhat?
and the lerp is doing nothing to slow down that angular momentum
so you have 2 counteracting forces
is there anyway to rotate it so that it takes into account this momentum?
that does make sense
is there anything wrong with keeping the angular drag the way it is
besides that, you would have to manually mess with the rigidbody's velocity/angular velocity through code
honestly no and it doesnt feel too hacky
however it would feel cleaner if there was some function on the rigidbody that rotates it to a certain amount and updates angular momentum accordingly
which you shouldn't do unless you know what you're doing
I have an idea that I don't think will work well
have a flag that sets to true on OnCollisionEnter
nvm that's redundant
yeah thats seems a bit sketchy too
in OnCollisionExit, set a flag to true, and have a void (that executes if the flag is true) that progressivly lowers the angular velocity of the object to 0
idk
it does make sense that having no angular drag means the angular momentum never goes away meaning its affecting its rotation constantly
i think just changing that value is a fine enough fix
that all does make sense thanks for the help
yeah very early days but got big plans
ugh
100% of my projects
never hurts to be ambitious and mess around
dude it ABSOLUTELY hurts to be ambitious
I agree
Yeah I have a question… so I’m making a 2D game.. I’m trying to make it so that when the object hits the ground it stops.. I have a box collider 2D for the background and have a polygon collider 2D for my object but the object is not stopping where I set the collider for the background… can someone help?
You dont set the collider on the background but on the ground object
It’s kinda hard to show you what I mean…
I have the green box set for where the ground is
Send a screenshot with the colliders selected
You talking about the one for the background or the object
both
Can I stream my screen to you it would be a ton easier
I have a mesh collider related question, is there a way to prevent "degeneration" of the mesh when i toggle convex? i dont think im describing this well enough because i can't find anything online..
example, convex enabled on left, right is the mesh used to make the collider
it has 24 verts total, so its not too complex
its clearly doable, a demo of an asset has this working
dumb question, are you sure you have the right mesh on the meshcollider component?
fair question though, let me have a check
yes it is the correct mesh, the same one i exported with the rendered mesh
its not named c_meshname though (i have no reason to think this is anything more than a way to keep things tidy)
this has always been its behavior for me since i started messing with unity 2 months ago 😅
thanks anyway spooky ghost friend!
but now...i think maybe something in my project settings or preferences could be the culprit, if this isnt the case for others
I would also love to find a better resource explaining the Convex mesh collider option. I have a hunch that It does more than simply... "decimate" (I think is what the graphic artists call the reduction of surface polygons) the mesh.
But, to directly answer your question, no I don't think we can stop this. The popular workaround I've seen is to create two separate convex mesh colliders, then attach them to this game object.
I don't actually know what's more performant: 2 (3, 4, ... ?) smaller convex mesh colliders, or one large non-convex collider.
same, there seems to be a dearth of explanations about this.. as for splitting, it seems to still seems to decimate the hulls, so thats annoying
i do wonder how that bottle asset up there managed to do it though, i think i'll just ask the creator if nothing comes up
hm, decimate is probably the wrong idea, since if we were to click the decimate button in Blender on this bottle, it would preserve the narrow neck
decimate with very very low values probably, in any case, its a bit of a black box it seems
i couldnt find anything on preferences that relates to the extent of the decimation/degeneration unfortunately
If i have a physics object that is shaped like a bowl, and it has multiple balls inside which are also physics objects. They all have different mass, so can i somehow calculate how much that bowl weights with multiple balls inside without referencing each balls rb mass? I know this is a confusing question but i don't know how else i could describe that.
If the bowl is sitting on, let's say a table, and you can get an OnCollisionStay between the bowl and the table, you can read the total impulse between those two objects: https://docs.unity3d.com/ScriptReference/Collision-impulse.html
It should be equal to the bowl's weight * Time.fixedDeltaTime.
Hnng.
I have a tank (collider is a box, so the tank part doesn't really matter) that just won't rotate right.
It's being dragged around by a navmesh agent and has a rigidbody restricted on rotations Y and positions X and Z
When I hit a bump or something, the thing ramps up on one side properly but then falls down back flat really slowly. This is even worse with procedural terrain, and it's impossible to keep the vehicle upright with this issue. What could be causing a rigidbody to fall back flat so slowly? Both drag and angular drag are 0.
I'll post an example.
Hmm. It appears the issue is related to the fact positions X, Z are constrained
Yeah I just jury rigged it by applying a downforce on the tank because why not
what was the mass of your tank?
Real tanks are very heavy. If you left the mass at 1 then I imagine it would be quite bouncy indeed
What's the difference between terrain and large mesh colliders? I know terrain has many extra features, but for simple use, are the two somewhat interchangeable?
I know that if we have a lot of rigid bodies moving around, then mesh colliders should be avoided at all costs. I assume the same goes for terrain as well?
Is there disadvantage to using a large mesh object as terrain? As far as I can tell, it seems fine.
I've read that there's a 65k vert limit to mesh objects in Unity, but it seems that large fbx are being split up on import somehow under the hood, I guess? For example, I was thinking about chopping up this model into 10 pieces (<65k vert each), but it seems that I don't need to?
terrain is pretty highly optimized compared to a mesh, especially when it comes to collision. That doesn't mean a mesh won't work.
if it's just the player for collisions, is there anything to worry about?
I couldn't tell ya. Test it out on your target hardware and see.
I made a four arm avatar and I added rigid and fixed joint to the secondary arm, anyways, they dont rotate
they keep the T pose
How are you trying to rotate the arms?
i am a begginer creator and for some reason whenever i move my character in my game and when it collides with another object my character randomly pushes back in the opposite direction without me pressing w, a, s or d
does anyone know why this is happening
?
Physics
You're probably not moving your character in a physics-friendly way, so your character is tunelling partially inside obstacles, and the physics engine is pushing it back out
Ok
terrain is so optimized the only circumstance I'd use a mesh instead of that is if I needed big overhangs like floating islands
optimized in what sense? if it's just a player using the CharacterController component, is there any danger?
it seems fine afaict, but I'm still suspicious, haha
it's loded for starters, you get this for free
lod changes with distance too
hmm, partial culling too?, a single mesh might insist on being rendered all at once?
as for physics, I am unaware of any terrain specific optimizations so my guess is it would be the same
it's sounding like bearable drawbacks under certain circumstances
i figured out the degeneration issue, disabling this allowed it to work! @desert timber @shadow seal thanks for the assistance regardless guys
thank you for sharing! I wasn't sure what these options were for
you're welcome, least i could do since its so esoteric
i dont know what "fast midphase" actually refers to, but the rest seems self explanatory, if difficult to actually determine if it was processed
hmm, docs say that it's faster for runtime creation, but might not work on some systems
i think that's what it's saying at least https://docs.unity3d.com/Manual/class-MeshCollider.html
i see, im not really sure if the advantages outweigh the extremely inaccurate collisions however 😅
midphase
@limpid vigil I think that it's for high poly meshes
in your case, though, you custom modeled the collider?
yes, several other used optimised VHACD generated meshes from Easy Collider Editor
in any case, i did not want them degenerated since they're already "light"
Hey guys, looking to read up on character movement with a rigidbody, I'd like my guy to push things around naturally
Is there any existing knowedge?
There is a script that does exactly this as part of the starter contents, if you have it installed, you can check Assets\StarterAssets\FirstPersonController\Scripts\BasicRigidBodyPush.cs (im using first person starter, not sure if third person has it)
https://docs.unity3d.com/ScriptReference/CharacterController.OnControllerColliderHit.html and here is some related documentation linked directly in the comments
The terrain is a mesh, but one that comes out of the box with a bunch of optimizations like tiling, instancing, LODs and all the same for trees and foliage
Still, it would seem that you can make something more optimized using meshes if you know how to optimize massive amounts of geometry, but that involves making all the same systems but better than unity
Thanks dude
I'm having a raycast issue. I'm currently behind a wall that is made of 1x1x1 BoxColliders, all placed by 1 unit to the top or to the sides or bottom. But there are areas behind that wall that the raycast doesn't fire TRUE for a hit to that layer. Raycasts are firing at 1 Y unit
This ray is returning false (cast is made from the player)
Its probably is due to the seam between the colliders and you firing the ray exactly at it. Can you offset the raycast a bit as a quick test to see if it fixes the issue?
I already added .01f to Y End Point's Direction. But I'll move it also.
you've shown a single point for your ray. What does that mean?
if one hits, you should be able to see player silhouette through the wall
the other is in the right side hair corner
Still confused. Is this a ray fired from the camera? Or somewhere else?
You're shooting this ray from the camera to the marked point?
What are the starting and end points of this ray?
I was actually shooting from the player looking for a true hit to layer mask "wall, ground or cutout sprits"
Ok so the bushes are made of a bunch of box colliders?
yes
It may jsut be you're running into the issue where raycasts in 2D don't hit colliders that they originate inside
oh so the ray stops at first hit?
it's 3d colliders tho
But if the source of the raycast is inside that collider.
project demands 3d colliders, in case you are wondering
Try it from the camera, and layermask it against the wall objects just to be safe about it.
alright, I will invert the raycast. Thanks
I was also wondering this, yes, it wasn't obvious
tysm
Car rigidbody mass 600
oh mine is about 5000 but since the friction values are ratios (i think) then it shouldnt matter
Still returning at least 1 false when fully behind wall, sometimes 2 falses, depending on the area.
public LayerMask groundMask, wallMask, cutOutMask;
private void Start()
{
layers = groundMask | wallMask | cutOutMask;
}
private void Update()
{
float dist = Mathf.Abs(Vector3.Distance(camRaycast.position, transform.position))*2;
print("LeftRaycast = " + Physics.Raycast(camRaycast.position - new Vector3(0, .1f, 0), leftRaycast.position, dist, layers) + " ----- RightRaycast = " + Physics.Raycast(camRaycast.position - new Vector3(0, .1f, 0), rightRaycast.position, dist, layers));
}
Oh, we meant to use:
https://docs.unity3d.com/Manual/CameraRays.html
To actually raycast from the camera (not it's position). You would have to convert the point to shoot at into screen space and then use ScreenPointToRay.
Raycast wants a position vector and a direction vector. You're giving it two positions. either:
- Do what Osteel said to create a ray from the camera
- Use Physics.LineCast which accepts two positions instead
(assuming camRaycast is the camera transform?)
No, it's an empty 2 units in front of cam
either way - LineCast if you want to specify two positions
RayCast if you want to specify a starting position, a direction, and a length
[Physics 2D] Any idea on how to simulate a rope, made of a bunch of little squares, attached on both ends to a different object, without letting the cells (squares) of the rope go 'crazy' (get away from the rope in a considerable way) whenever a hit from an object with 100m/s occurs? Each rope cell is attached to the next one through a HingeJoint2D.
Is there any other approach which could be taken for simulating a 2d rope, which could resist such forces?
That direction part was the issue. Calculated that direction and got it working, still using Raycast. I will try CameraRay in the future. I want to move on to the next mechanic. Thanks @timid dove and @wide nebula
well I'm not wanting large mesh to perform better, I'm just wanting it to perform, haha
Well, it's very situational to your project and target hardware how much optimization you really need
end of the day, just try and see I guess
the profiler is happy but I'm worried I'm missing something
You know what to look into if it's not working right on low spec tests
umm, not a single clue
I'm using URP and would like to support most laptops
I only have my desktop for testing
I mean the stuff we've been talking about, tiling, selective unloading and whatnot
ohh, no I'm not sure how I would apply these concepts to a single large mesh
Blender would be needed to chop it up, I think, to enable selective loading/unloading
Just converting it to unity's terrain system would allow its optimizations to take effect, you have many different options
Even if you don't know how to exactly do these things, you know wht to search for
that would destroy the UVs, though?
maybe... these things look very time consuming, I might just remove the mesh if performance becomes a problem
Or test it with a low end pc, see if optimization is worth the trouble or even necessary
If you want an open world game that works on basic laptops, you're going to have to learn to do some tricks, I can tell you that much
Ohh, sorry I guess I have multiple questions running. I know anything expansive needs to be handled with a lot of thought..
but, for "player enter a shop" settings, I'm wondering if I can transition to a scene with one of these very high vertex models
really amazed (... skeptical) that Unity can handle 1M vertices with little more than drag and drop
I can almost go nearly to 10M vertices before lag pushes my desktop under 60fps
so I guess that means models with 1M will be fine in most cases
can I put multiple colliders onto a single game object
I'm reading a bunch of conflicting things on the forums
I'm trying to figure out the most efficient way of attaching many simple colliders to a single game object
You can but you will have problems if they intersect.
Also, there could be inaccurate collisions. It would be better, I think, to parent empties to your object and attach the colliders to those instead.
I don't know how Unity's internal code works, but anything that is just GetComponent<Collider>() is going to return the first collider only.
Yea I generally don't program with GetComponent
or any of those APIs
as they aren't very fast
I do use them occasionally
but mostly in init methods
Then you should be fine. Each of the colliders will fire events normally.
Better practice is usually considered to put each collider on a separate GameObject, but there's nothing stopping you from putting multiple colliders on one object
it's not going to affect the performance of the physics simulation one way or the other afaik
it just makes things more confusing when it comes to collision callback functions
gotcha
oh , one thing i think i either didn't mention or explain right is i was planning on using [flags] field across the bitfield, that way i dont ahve to map 1 for 1 to a number and a direction, explicitly, i that is to say, using flags i could have a northeast and northwest positive and interpret that as a lean forward
is there any way to stop rigidbodies giving energy/movement to other rigidbodies on impacts. I have a rigidbody bullet colliding with a player but the bullet is pushing the player and i would prefer if it didnt. anything i can do about this?
Try to assign the minimum mass to the bullet
Although, the best solution is posted over here: https://stackoverflow.com/questions/36991487/prevent-collision-forces-in-unity-physics-in-collision-callback
ok thankyou
Just use a trigger Collider
Yoh,
I was looking for a good way to make something, simple...
My player can move and push all environment objects (affected by gravity with rigidbody).
My question is : How can I remove the fact that the player is slowed down or stopped by these objects?
(I'm not english, if you need more explaination, tell me)
Basically, all objects is affected by the movement of the player, by pushing, but, my player can't be affected by the movement of these objects.
You can't if your player is also a rigid body, equal and opposite forces and all, but you can cheat the system by using the CharacterController class. You'd need to explicitly push rigid bodies on collision like in the manual here:
https://docs.unity3d.com/ScriptReference/CharacterController.OnControllerColliderHit.html
That exactly what i looking for.
My player wasn't rigid body, i trying with, to push other but, not working.
That a good way to start. Thanks a lot!
Work well ! ❤️
Correct me if I'm wrong: If a collider collides, it sets the velocity of its parent to 0, doesn't it?
depends on the collision
it tries to follow the laws of physics
it might stop
might slow down
might bounce
might just knock the other object out of the way and keep going
Understood, thanks! I need to rethink my logic for moving the character around, because if the player "runs" into a wall and tries to climb it at the same time, the vertical velocity is blocked as well
If you aren't doing rotation with the final 3 bits of the bitfield, then yeah you will have just enough bits to do it this way. Personally I wouldn't though. Flags are used for data that can coexist in multiple states simultaneously, whereas in your case, your character can only have one direction. Using flags will mean you will need lots of checks for how to interpret different combinations of flags. Also, you will be wasting information, since this will require all 8 bits, when you could get away with using 5.
Anyone know how to access/modify the random physx seed value assosciated with a unity project?
I'm trying to get the same calculations between multiple projects
that sounds like something that doesn't exist
Whenever I make two different unity projects with the same exact scene and do a rigidbody cube drop, the cube ends up in a different position.
If I create a new project, clone it, and THEN build the scene with the cube drop, it ends up in the same position
so something is going on
I'm aware of what determinism is
physx is supposed to be deterministic on the same architecture anyways
I'm doing it on the same machine at the same time
there's forum posts on the unity forum about people talking about a "physx seed" that aids in determinism across multiple projects
I'm just trying to figure out how to access it
I guess a seed could still exist, but I'm not seeing anything for that in here (at a glance at least)
have you enabled a fixed timestep?
I'm making a game where the floor is launched upwards depending on how long you hold down. I want the floor to bounce the ball up, but not the other way around. How can I do this?
I considered this, however, given that its a single byte, and rider auto generates switch labels, i can simply map these to an enum, and have invalid cases just break or fall through to their correct case, so i'll actually be able to do it in one operation, without any checks
ill probably do some bitmasking in the csaes of the switch
solved, I set the floor to kinematic when not using
I need help with an issue im having
in wich my character keeps flicking when he hits a wall
it doesnt stop the movement
it keeps trying to get through the wall, and the sprite looks weird needless to say
you're most likely moving your character in a non-physics friendly way, which results in him tunneling into the wall. Then the physics engine notices and pushes him out
the solution is to move your character in a physics-friendly way
would u be kind to check my code out and help me improve it?
i got in a youtube tutorial
its probrably not the most optmized
probably*
Is it possible to check if a point is inside a concave mesh collider?
2d or 3d?
3d
Try this:
bool IsPointInsideCollider(Collider c, Vector3 point) {
return c.ClosestPoint(point) == point;
}```
basing that off:
https://docs.unity3d.com/ScriptReference/Collider.ClosestPoint.html
If location is in the collider the closestPoint will be inside.
That would only work with convex mesh colliders wouldn't it?
Because concave mesh colliders are empty inside
I think it works on both
try it
nope
I have a rigidbody movement script but when I walk up ramps then stop mid-ramp it does this hop i think it has something to do with my rb's velocity but idk
Hello everyone, i am trying to make my tank move up the ramp but my player/collider is catching on the ramp despite the physics material being friction 0
I tried using wheel colliders but they are buggy as shit and kept giving me weird physics errors and forcing my entire gameobject to spin into the ether
I am using rb.AddForce(targetPosition, ForceMode.VelocityChange); to apply movment
the mass of my player is "1" if that influences anything
I got it fixed!
The solution was to make the physics material friction 0 (which i already had) and to make the Friction Combine to Multiply too!
smooth as butter now 😄
rigidbodies dont like slopes
so yeah that's pretty normal behaviour
there is a fps movement tutorial by brackeys so before the jumping part he has told about a setting for the slope
the setting is in rigidbody called slop limit
@frank shorethats not a rigidbody. that's a character controller.
oh sorry
Where can I ask a question about prefabs D:
Depends on your question maybe #💻┃unity-talk
Yeah I went ahead and threw my question in there I appreciate it
has anyone used Rigidbody.SweepTest before?
im getting weird behaviour with it and id like some help
i figured out the reason behind the behaviour and its stupid
for some reason SweepTest doesnt report an intersection if the rigidbody is already colliding with the collider that the sweeptest is intersecting
could be bouynce threshold maybns?
hey prolly want the other way tho, its the bounce threshold velocity,k so maybe set it to like 5 or 10 or something
also feel like char controller with rig when dont want need rig and if do want it kinematic
Hi, I have a question. I'm making a flight sim game and I'm triging to make a flight phisics correctly. I'm not sure how to do this, so for the moment I'm just adding a rigidbody.addforce to object, and the problem is that, when I'm changing the object rotation, for example it's going forward, while it's turned 45 deagres to right. How can fix that? Or maybe I should do fly mechanics in other way?
AddForce accepts a force in world space coordinates. You'll have to give it the appropriate direction of force for the acceleration you desire.
You could alternatively use AddRelativeForce if you want to provide your force in local coordinates of your character: https://docs.unity3d.com/ScriptReference/Rigidbody.AddRelativeForce.html
hi so i tried to utilize physics2d ignorelayer collision function between two layers but they still continue to collide. Are there other steps i need to take in order to allow two layers to ignore collisions?
Nope that's all you need
You can also just do it from project settings without any code
Make sure the colliders are on the layers you are setting up to not collide
yeah got it fixed. turns out i had my character on the wrong layer
:p
odd behavior for a rigidbody
we need to see your code
@real finchI have that exact issue
I fixed it it was A result of poorly written code
my character's floating when i do the running animation, and when i stop running, it falls down
You key framed the animation in the air!
So im really new at game engines. I started on the unity FPS tutorial. I started adding my own bits to the map, but something didn't work...
What is the Rigidbody2D equivalent of Forcemode.VelocityChange?
I need collisions between 2 generated meshes. i'm currently using meshcolliders but these will only collide if convex is enabled which isnt an option i could however make it up of individual colliders but i need 4k of these to represent a single one of my current meshcolliders at worst case so it seems like a bad idea to add them as individual components. is there any better solutions?
Hello everyone! I have a rigged character, that uses Jasony's gang beast physics. When it falls down, the model becomes invisible.
I didn't find any other channel to ask for help about this topic
It appears to disappear once the model actually moves
(the character falls down)
nevermind fixed it
Hello! I have an empty GameObject that has a specific amount (doesn't matter how many) of small rectangle GameObjects as children. Each of these rectangles has a BoxCollider2D component. When my player collides with one of them, for some reason it detects a collision between the lpayer and the parent, not the children. Any way I can change it?
Child Colliders are considered part of the parent. But look closely at the data in the hit object
There's different fields for different things
Read the docs carefully
copying and pasting pre-built prefabs around in a scene really isn't going to learn you anything
you'll also need to post the code if you want help
there's really no other way anyone is going to help you
I saw something about Contacts. would that be useful? Edit: Yes it is. Problem solved!
Hey everyone! I have an active ragdoll npc working. I am animating it by changing the target rotation in an animation. How should I move it? I tried setting target velocity to 0,0,20 in the root configurable joint, but it didn't affect it at.
I did change the z-drive value to a high number, still no effect.
and the docs don't have any information/examples on that
Hello, can You tell me why the charactercontroller is always above ground, when I directly adjust it, it jumps so there is a gap between foots and ground
Oh, skin width helped me I think..
Would it be possible to have two rigidbodies, one for a vehicle and one for a passenger, such that the passenger would be able to roam around on top of the vehicle while the vehicle is in motion (i.e. accelerating, decelerating and turning)?
I would imagine so, since the purpose of rigid body simulation is to simulate real systems... but, I would also imagine that behavior could get weird. Let us know if you try it, you've got me curious!
(I like your about me :P)
True but there are some limitations I've found.
For instance, if you use a simple capsule to represent your player, this won't translate well since your shoes have a larger surface area than a single point (assuming the capsule is upright)
Therefore, turns that a player with shoes can withstand might be too dificult for a capsule
sounds like accurate rigid body simulation to me 😛
Hi. Can I get yaw, pitch and roll from a normal vector?(or 2 vectors)
Hello, i want to make a game where you can build stuff like in minecraft but with physics, you can place blocks onto each other, and if the creation isnt placed to the ground, it have rigidbody physics. To do that i create empty gameobject with rigidbody and set all gameobject cubes as its child, but i also want to add bearings so you would be able to rotate stuff but i don't want to use unity joints because they are wobbly and i want them to be rock solid no matter what. Is there a way to do it?
localrotation?
There are fixed joints
idk if that's what you want
but they aren't wobbly
I tried fixed joints and they were not rock solod, they were moving slightly, and thats not what i want either way.
I also need physics, so when the bearing is not powered, it would rotate freely.
Hey guys, is there any way to get rid of the camera flipping when the board does, to always keep it upright?
Hi
I wanted to know if someone could help me with a problem that I have.
I have a player with a rigid body and other objects with their own collider and when pressing shift the speed of the player increases a little. The problem is that when they increase their speed, they begin to go through the colliders of the objects that surround them.
I don't know if someone can give me a guide to solve this problem
Make sure you're moving your character in a physics friendly way.
If you're using transform.position = or transform.Translate() that is not a physics-friendly way
Problem with rigidbodies that has me puzzled is that only one of them seems to obey interpolation
The planet is jittering, or skipping in relation to world as it moves, while the ship isn't
Both are about as simple RBs as one can make with no code that moves them, besides AddForce on the ship
Oh, heh
Seems I found the issue before I finished typing up the description of it
The planet had Transform.LookAt towards the camera in LateUpdate, which one would reason only affects rotation, but apparently it has an effect on the position as well
Or enough of an effect that it breaks interpolation
Hey, guys. If I want to apply torque to a rigidbody, it's moment of inertia is defined by collider, that is linked to it?
yes
you can also read/set the moment of inertia https://docs.unity3d.com/ScriptReference/Rigidbody-inertiaTensor.html
is there anyway to only allow an object to move on a certain local axis, ive tried using rigidbody constraints to lock it on the other 2 and those work globally, so it only will go one way and not depend on the orientation of the parent
but i want it to depend on the orientation of the parent and only not be locked on the local z
project its position onto the appropriate Plane(s) each frame
the planes can be defined by the parent object's local axes
gonna be kinda rough with a Rigidbody though
also possible to just zero out the relevant 2 components of the object's localPosition
or - reset those two components to whatever the desired non-zero value is
thanks, somehow didnt think i could just set the localposition x and y to zero
but works out fine
have a good one
Hey everyone,
Sooo.. beginner question😂
I made this very basic and probably bad movement script for a character in a top down 2d game (Script: https://imgur.com/a/iV8DVaM). It's not the best piece of code but it worked, UNTIL it hit object colliders. For some reason, when i let go of the movement button, it keeps moving along the wall rather than stopping like the code says. (Here is the issue in action: https://imgur.com/a/8ZMjssb)
Is the problem in my code? or is it something else in the rigidbody settings or something?
Any help would be appreciated
it's picking up some horizontal or vertical velocity from the collision. And your code only zeros out velocity on one axis depending on which key was just released
for example you only zero out vertical velocity when releasing the W key
Oh
Is there a way I could turn that off?
I mean you could simplify this whole thing to about 3 or 4 lines of code
void Update() {
float horizontal = Input.GetAxisRaw("Horizontal");
float vertical = Input.GetAxisRaw("Vertical");
playerBody.velocity = new Vector2(horizontal, vertical) * moveSpeed;
}```
Hmm yeah that's much better than my garbage code😂
Just that i haven't used those before
Thanks
One thing the player is very fast when you click both buttons
yeah just change new Vector2(horizontal, vertical) to new Vector2(horizontal, vertical).normalized
how do I get my objects to slide? They kind of just tumble. I'm trying to make a conveyor belt and that's not really what I'm aiming for.
Reduce the friction of the ground collider material.@safe flare
WHYYYY
I'm having an issue with updating mesh colliders for procedurally generated planets.
Currently what I do is bake the physics mesh on a different thread and once that is done assign the updated mesh to the mesh collider. However, the mesh collider does not recognize the fact that the mesh has already been baked and it goes and bakes it once more. ( This is the same if I bake it in the main thread, so threading isn't the problem here ).
I have searched online and only found one forum thread covering this where the issue was marked as fixed in the 2019 - 2020 versions of Unity, but it seems clear that the issue still exists ( At least in the 2021 version of Unity which I am using ).
There was a suggested workaround that I tested to no avail. The workaround was this: "Do not reuse the Mesh instance for now. Every time you bake, that should be a new Mesh instance.". I could have misunderstood this as there were no code examples of the workaround I could find.
I'll post the code responsible for setting the mesh of the mesh collider shortly
thisThread = new Thread(() => Physics.BakeMesh(getMesh.GetInstanceID(), false));
thisThread.Start();
while (thisThread.IsAlive)
{
yield return null;
}
faceData.face.collider.sharedMesh = getMesh;
Of course, this code is within a coroutine as to not slow down the main thread while it waits for the other one to finish the work
Alright, I have found a fix. You need to set it inside FixedUpdate, for some reason that fixes the double bake
Hello everyone, i would just like to ask, what are the physics that can be apply for Unity? So far the only I’ve seen would be water, vehicles, airplane and i was wondering if there would be more?
Unity has a physics engine (three of them actually) that simulates realistic newtonian physics in general. It doesn't really know or care about what kind of objects or vehicles you are simulating in the game. it can do anything within its limitations.
I see, thanks alot @timid dove
have you sen the grabit script
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Trap"/* && !other.gameObject.GetComponent<Trap>().hasTriggeredOnce*/)
{
other.gameObject.GetComponent<Trap>().hasTriggeredOnce = true;
other.gameObject.SetActive(false);
other.GetComponent<BoxCollider>().enabled = false;
print("HELLO WORLD");
}
}
Why does it trigger 5 times with enabled = false; and trigger only once when SetActive(false)?
How realistic are you going
don't forget about the torque being applied by the main rotor on the fuselage
does your game allow for autorotation
are you sure that's the center of mass? Did you manually set it there?
why are collider types still being drawn regardless if I have them selected or not?
trying to emulate gravity. Using this formula.
But this dosent work. on the bottom right. how do i fix it.
Error: "Operator '/' cannot be applied to operands of type 'int' and 'GameObject'"
now tell me how you're planning to divide the integer 1 by the gameobject a
@stuck bay
i feel like im stupid but the problem is. This yt video said it was the "fix"
Legit
bruh
but i have no other way of fixing this. moon wont orbit this planet
it will only orbit the sun
can't divide a game object by a number that doesn't make sense
probably some value attached to the game object
yeah thats what i was thinking. but i thought that i was being dumb. But i was the opposite.
maybe a.transform.forward or a.transform.up or a.transform.right
well they want it to orbit a planet and they have it looking at the planet now they just need to move it in a direction no?
I Did instead ((Gravity * m2) / r);
but
That dosent work either. just orbits one object
Cant divide 1 by a vector3
oof feel like an idiot rn i forgot that's a vector3
Lol
im like confused on why they say that 1 / gameobject is a "fix"
i thought their trolling but its a legitmate tutorial
They cant have done 1 / a without getting the same error as you in any known universe
Oh actually i fixed it
Cool
hey @verbal karma any idea why my physics debugger is acting like that? Do i just not know how to use it?
I am making a 2D game and I want to set the default physics offset to as low as possible so I can make colliders the same size as the sprite without the gap in between colliders. The problem is, turning the default physics offset to as low as possible causes the collisions to be bouncy and dampened, removing any rigid collisions, even if the rigidbody is set to continuous. I noticed that changing the physics simulation mode from FixedUpdate to Update fixes the problem, bringing back rigid collisions. However, I don't want to simulate physics in Update because the framerate can cause inconsistencies in the physics simulation. Is there any way for me to set the default physics offset to 0.0001 while still maintaining rigid collisions and using FixedUpdate?
Here is a video that demonstrates what I am referring to
Can anyone help me understand how I can generalize this to 3D? It is finding the value of gravity g and initial velocity v_0 based on the inputs peak projectile height h lateral velocity v_x and the horizontal distance to the peak of the jump x_h
my main headache is trying to calculate g since squaring a Vector is undefined.
The simplest way is to just do the math separately for the x and z components of velocity/position
That is what I thought too. Perhaps I am not thinking of it correctly but if I do that I get a gravity vector with 0 doward force
or y component is 0
?
what are you trying to calculate here
that system of equations can be used to calculate a bunch of things:
- initial velocity
- peak height
- etc..
- result distance
So in 2D the goal is to be able to say, "I want my jump to be h high, and cover 2x_h ground" So you input those values along with the lateral traveling speed v_x and you get a gravity value g and initial velocity V_0 that gives you the exact parabola properties you wanted.
Or so that is what it says in the GDC video for this slide
https://www.youtube.com/watch?v=hG9SzQxaCm8
In this 2016 GDC talk, Minor Key Games' Kyle Pittman shows how to construct natural-feeling jump trajectories from designer-friendly input like desired height and distance, modeled programmatically using one of a few available integration methods.
GDC talks cover a range of developmental topics including game design, programming, audio, visual ...
but in 2d V_x is scalar, so I am stuck
So g would generally be something you're inputting to this. So you rquestion becomes "in a world with gravity g, I want my jump to be h high, and cover 2x_h ground"
and then you'r ebasically solving for v0 and vx
Which probably goes something like:
- ok with gravity G, I need to jump with initial velocity of what to get to that desired height?
Then if you know the desired height you can calculate how much time you'll spend in the air
and then you just use that amount of time to calculate the horizontal velocity you need to move the desired distance along the ground in that time
though that system of equations seems poised to calculate it the other way around 😛
Yea I am confused. Thanks for the help, I need some time to think and let this simmer in my smooth brain.
Maybe I am misunderstanding and misrepresenting the video. Because he is an accomplished professional developer. And I tested out his jump in a free game he provided and it feels really good.
Gonna rewatch it a few more times.
TBF I did not watch the video
So in the end I replaced V_x with the scalar lateral speed in the direction of the jump and it worked perfectly. The jump has all the properties you give as input.
I need to derive the equations by hand to see if V_x was actually meant to be a scalar the whole time.
I have a spring joint but it wiggles too much before reaching resting point, how can i reduce this wiggling?
Increase the dumping(or whatever was that parameter name)
Damper i presume
v_x by definition would be scalar, as that notation means the x component of vector v
Thank you. I see that now. Explains all my confusion.
I have a question about how to manage multiple sources of velocities and accelerations. Any help would be appreciated.
I do want to preface this with, I know I should just let Unity Physics handle all this and I should just use the CharacterController, and I agree. This is more for me to learn than something I would put into an actual game.
How do you handle multiple velocities and accelerations?
For example, I have an input event from wasd keys that moves the character in each respective direction. To accomplish this I do the usual
var moveVel = new Vector3(input.x, 0, input.y) * runSpeed;
Then I set my final velocity to moveVel
Great it works. But now I want to add a jump velocity?
I don't want to set my final velocity to moveVel every frame because then it overwrites my jumpVelocity that only gets added a single frame.
So what do I do here? I know theres like a hacky solution like
var moveVel = new Vector3(input.x, finalVelocity.y, input.y) * runSpeed;
This prevents my lateral moving velocities from overwriting my constantly changing (due to gravity and random jump forces) vertical velocities.
But this is only a bandaid fix that breaks the moment any more velocities are introduced (like random velocities from speed zones or projectiles hitting you, etc).
Does anyone have an resources that explain how to properly manage velocities acting on a body that can easily scale to handle any number of outside forces?
Velocities are additive so what you have there is almost right. Just update the components in separate lines, eg, moveVel.y += jumpVelocity;
I think we only want to use the character controller when we want advanced collision detection
I see. I think I am having trouble explaining what I don't understand.
I think what I am confused about is how the velocities are managed frame to frame.
for example
frame 1
- d is pressed. Velocity = (0,0, runspeed)
frame 2 - d is being held Velocity = (0,0, runspeed) // notice that we dont add the velocity since that would double the speed so we overwrite the velocity
frame 3 - spacebar is pressed Velocity += (0, jumpForce, 0) // this is the only frame where the velocity is correct
frame 4 - d is still being held Velocity = (0,0, runspeed) // jump is overwritten since we are not just tacking on the constant velocity
I could of course just not replace the y component when getting move inputs but then what happens when I want to add horizontal movements from other sources. How can I manage those outside of the movement input
frame 1
- d is pressed. Velocity = (0,0, runspeed)
frame 2 - d is being held Velocity = (0,0, runspeed)
frame 3 - speed boost applied Velocity += (0,0, boost acceleration) // this is the only frame where the velocity is correct
frame 4 - d is still being held Velocity = (0,0, runspeed) // speed boost gets over written
is user input a special case? Do I only add the velocity onPress then subtract it onRelease? But then that makes it so I cant introduce any friction because the velocity is only ever applied once and adding friciton would reduce it to 0. I am just super confused on how all these sources of forces are managed
specifically sources where they add constant velocity, like mvoe inputs
Hm, overwriting is simply a coding mistake, just add them all together for a final velocity. An acceleration vector is needed to keep track velocity over time
I think the tricky thing is that for the motion you're looking for, you can't be using v=runspeed, you would want v+=acceleration*dt each frame
Sorry, I was trying to simplify my explanation of the issue I am having so it wouldnt be so long.
I am using the integration from that popular blog post, forgot the name
newVelocity = (Velocity + 0.5f * Acceleration * deltaTime) * deltaTime;
Velocity += Acceleration * deltaTime;
I understand the relationship of acc and velocity. Acc is the rate at which velocity changes.
I think I just suck at explain my issue. Tomorrow I will make a concrete and detailed example and post here again.
It can be hard to ask the right questions when we're learning something new
Too true, and it is giving me a headache. I don't even understand what I don't understand. Thanks for taking the time to help anyways. I will think this over and have a more precise example tomorrow.
how do I make my player not slide on the ground?
I made this material and gave it to the ground
but its still sliding
fixed.
ROTATE PLAYER TOWARDS TARGET USING PHYSICS?
I'm trying to make a RB rotate towards a target, using physics only, but its much harder than I imagined.
1: MUST use .AddTorque()! NOT .MoveTowards(), transform.RotateAround() etc.
2: The RB has a "maxForce" that it can use when applying torque - either at max or less (never more)
3: Function should make RB use max allowed torque to reach point where it needs to break with max torque, to reach target perfectly.
DOES ANYONE HAVE GOOD RESOURCES FOR THIS?
All related forum posts just repeats the same misunderstandings like:
- "Why do you have to use physics for this" (I just do, ok.)
- "You can create a PID controller for this!" (No, since we know how Unity works, we can actually calculate this perfectly instead, which is what I want.)
- Also many answers forget that there's a "maxForce" that can be applied.
I would also use a PID controller ( I remember I did a looong time ago and it worked - just need to be patient to tweak values). I don't understand your argument when you say:
No, since we know how Unity works, we can actually calculate this perfectly instead, which is what I want
Well a PID controller is used in environments where variables are not 100% measurable
THis sounds to me like you could run your own equation and appy the correct rotation to the transform yourself, so you wouldnt need physics in that case
But since Unity is a program, we can know how is works. How it applies accel, velo, drag etc.
I WANT PHSYICS OMG xD
It amazes me that I cant find a solution online - seems like noone wants to touch physics when it comes to rotation, only movement
Well it's messy especially in 3D with gimbal-lock, quaternions, and such
Anyway I don't understand how you want to achieve your goal so not sure i can help here
Its 2D, so that makes it tons easier
Sure
Only need for 1 direction
Its primarily a physics problem (the only thing you need to know about Unity, is how it applies these things). So most programmers just resort to "how can we make it function as fast as possible", without caring about the fact that I want it done with physics.
I got a question i cant get cloth to work in unity 2019.4.29f1 anyone know a solution for this?
Anyone know why my rear tires (using Wheel Colliders) keep sliding (like turning into a drift) whenever I make a turn?
Here is what I'm talking about
physics material?
either way, I kinda like it like that
Dumb question here. I forgot how to edit the walkable area / navmesh thing. How do I change it?
It's the green lines btw
Ill try messing with that
it is nice that you can kind of drift easily with it, but you basically can't turn at all at high speeds without spinning out unless you just keep slightly tapping the turn key
Anyone?
Are you using box collider?
Does anyone know if there is a way to toggle eDISABLE_SIMULATION on a physx colliders, which nvidia recommends for objects that are not affected by simulation/forces/etc? I have a use case where I have many active physx scenes, most of them have non-movable objects and I am still seeing significant CPU time just calling scene.GetPhysicsScene().Simulate(Time.fixedDeltaTime); on these otherwise inactive scenes.
How would I edit the Mesh Collider?
I’m new to map building so idrk how to edit mesh collider i only know how to do box collider
Ah okay, I know how to edit a box collider as well haha but not mesh
Yeah sorry i wasn’t helpful
That's fine. Just need to find someone who knows how to edit a Mesh Collider
Anyone?
umm, sounds not possible to me, but I'm not sure. Unless you wanna' head over into blender to edit vertices? But, if you're talking about ProBuilder, then you can edit the vertices then apply the new mesh collider
@desert timber
any shape created with probuilder can be edited
But the mesh is FBX which isn't ProBuilder?
Yep, you'd have to export that into Blender, then reimport. I think the pros block out an approximate shape with tools like probuilder for colliders since mesh colliders can cause performance problems
You mean import to Blender then export into ProBuilder?
umm, export from unity, import into blender, export from blender 😛 .. if you want to edit vertices of a mesh, yeah
Okay one sec
Hello,
I'm already desperate of this situation and even after 5 hours I can't think of any solution so maybe someone more experienced can advise.
In the picture I have two colliders set on one object, boxCollider is a trigger and capCollider is not. The problem is that the trigger is supposed to give me the information in the script that I have landed on the ground, this works for me but it absolutely does not stop on the capCollider and the object ends up under the texture (maybe somewhere in the middle, it's random), as soon as I remove the trigger on the boxCollider it stops on the capCollider without any problem but it doesn't work passing it to the script (I have to have the boxCollider because of the different rotation). And the bottom left picture is exactly the same only with MeshCollider where everything worked as it should, unfortunately I had to redo the model because of the texturing and because of that meshCollider can't be applied (it does something that absolutely can't be used). My question is, what should I do about it? I really don't know what to do anymore.
When exporting from unity? Mind explaining how to do that?
if your model is already FBX then it's good to go, if not there's a package that will convert the model to fbx and export it
probuilder would be a completely separate idea
No like to import to Probuilder
probuilder creates mesh from scratch
Because I'm not sure on how to edit meshes in Blender
umm, it sounds like you might need to find a tutorial to follow, it should be available
i think so? hard to tell
It's the Poly Shape
yeah that's one option you can use
I'm sorry I can't provide help at this level of detail, look for a ProBuilder tutorial, hundreds out there
The plane is a bit weird because it's on the floor but you get the idea
looks like a good start, if you reconstruct your scene in blocks like this (keep them small if you can), then apply Convex mesh colliders or just use primitives, it will be very fast compared to one big mesh collider
it's a lot of work though
True but that's for a later day
So the yellow lines. What are they and how to edit them?
light probes 😛
Meaning?
meaning you've dived straight into the deep end without following a tutorial 😛
Sorry, my friend helped me with this build and I don't know half of what he added
The mesh and light probes he added which is why I don't know what they are haha
well you can google about light probes I'm sure
Oh, it is just in the name
Okay so why can't I move into a certain area
The white cyclinder gets stuck at the door
It's this bit
ok, well let me know if you need tutorial recommendations
I do with this part
Brackeys' is my goto, but sometimes his videos are too short, give this one a try maybe? https://www.youtube.com/watch?v=CHV1ymlw-P8
Learn how to create AI pathfinding using the Unity NavMesh components!
This video is sponsored by Unity.
● Watch on Unity's website: https://goo.gl/jUsU8D
● Example project: https://github.com/Brackeys/NavMesh-Tutorial
♥ Support Brackeys on Patreon: http://patreon.com/brackeys/
·································································...
Thanks
What is baking?
This
maybe this will help? https://www.youtube.com/watch?v=FkLJ45Pt-mY
Learn how to update your NavMesh at runtime!
This video is sponsored by Unity.
Watch on Unity's website: https://goo.gl/rz5mda
● Example project: https://github.com/Brackeys/NavMesh-Tutorial
♥ Support Brackeys on Patreon: http://patreon.com/brackeys/
····················································································
♥ Donat...
If you've watched both of these, then you know more than me. I haven't played much with navmesh yet
ntdll!NtWaitForMultipleObjects+0x14
KERNELBASE!WaitForMultipleObjectsEx+0xfe
KERNELBASE!WaitForMultipleObjects+0xe
UnityPlayer!winutils::ExternalCrashHandler::HandleCrash+0x26d
UnityPlayer!winutils::ExternalCrashHandler::HandleCrash+0x22
UnityPlayer!winutils::ProcessInternalCrash+0x118
KERNELBASE!UnhandledExceptionFilter+0x1bc
ntdll!RtlUserThreadStart$filt$0+0xaa
ntdll!_C_specific_handler+0x96
ntdll!RtlpExecuteHandlerForException+0xf
ntdll!RtlDispatchException+0x40f
ntdll!KiUserExceptionDispatch+0x2e
UnityPlayer!DynamicHeapAllocator::Allocate+0x299
UnityPlayer!DualThreadAllocator<DynamicHeapAllocator>::Allocate+0x9a
UnityPlayer!MemoryManager::Allocate+0x8c
UnityPlayer!malloc_internal+0x5c
UnityPlayer!NovodexAllocator::allocate+0x31
UnityPlayer!physx::shdfnd::BroadcastingAllocator::allocate+0x3c
UnityPlayer!physx::shdfnd::ReflectionAllocator<physx::Gu::AABBTreeBuildNode * __ptr64>::allocate+0x70
UnityPlayer!physx::shdfnd::Array<physx::Gu::AABBTreeBuildNode * __ptr64,physx::shdfnd::ReflectionAllocator<physx::Gu::AABBTreeBuildNode * __ptr64> >::growAndPushBack+0x48
UnityPlayer!incrementalBuildHierarchy+0x6a
UnityPlayer!physx::Sq::AABBTree::progressiveBuild+0x18f
UnityPlayer!physx::Sq::AABBPruner::buildStep+0x128
UnityPlayer!physx::Sq::SceneQueryManager::afterSync+0x79
UnityPlayer!physx::NpScene::fetchResultsPostContactCallbacks+0x68
UnityPlayer!physx::NpScene::fetchResults+0xcf
UnityPlayer!PhysicsManager::Simulate+0xa49
UnityPlayer!ExecutePlayerLoop+0x57
UnityPlayer!ExecutePlayerLoop+0xf3
UnityPlayer!PlayerLoop+0x10c
UnityPlayer!PerformMainLoop+0x1be
UnityPlayer!MainMessageLoop+0xda
UnityPlayer!UnityMainImpl+0xca1
UnityPlayer!UnityMain+0xb
RustDedicated!__scrt_common_main_seh+0x106
kernel32!BaseThreadInitThunk+0x14
ntdll!RtlUserThreadStart+0x21
Anyone seen this crash before? Getting it randomly but frequently
hello
i have an issue regarding my character floating on a terrain while he's running
and when i stop, it falls down
these are my current settings as of now
how do you get tree colliders that aren't just capsules?
I'm using poly trees but don't want to use capsules for collision
mesh collider
I've added one to the prefab but it doesn't collide in game
it should, try making it convex perhaps?
PhysX sometimes doesn't like non-convex mesh colliders
Neither convex or concave work
it does show this though
also apparently concave mesh colliders don't interact with rigid bodies (my player). it's low poly though so I might just be able to make 4 different meshes and mesh colliders for the prefab
Hmm yeah so mesh collider isn't working but capsule collider is
Both by player mesh and the tree mesh are set to convex
Enable terrain colliders is ticked in my terrain collider
Why tf is this not working
Guys
Someone help lmfao
does anybody know how to make a moving rigidbody not go through colliders? the rigidbody has collision detection on continueos
OOOO
I FOUND OUT HOW TO MAKE SIMPLE WATER!
it looks like this.
all you need is circles and particles.
but its a little laggy
it works as a slime-like substance too
it is connected together with particles.
You have to move it via rigidbody methods rather than directly moving the Transform
when i move my character by rigidbody.velocity. It moves by "Horizontal" and "Vertical" but how do i make it move in the direction that im facing and not a set direction
if you know what i mean
It's a Vector2 or Vector3, you can give one that pointe in any direction you want
transform.forward (or transform.right for 2D) is generally the "forward" direction for your object.
wait imma send my "Move" function
void Move()
{
float xMove = Input.GetAxisRaw("Horizontal");
float zMove = Input.GetAxisRaw("Vertical");
rb.velocity = new Vector3(xMove, rb.velocity.y, zMove).normalized * walkSpeed;
}
that works but i need it to move by the direction im facing and not in a set direction
its a 3d project btw
but if i do transform.forward then the collider skips the physics of collision
No it doesn't
Use transform.forward to set the velocity
It only skips physics if you set transform.position
could you edit the script i sent and put in what you mean pls
you said you want to use it for the velocity
yes
So what's the confusion
i want to use rb.velocity but where in that method do i put the transform.forward
like this or what do you mean : rb.velocity = new Vector3(xMove, rb.velocity.y, zMove, transform.forward)
Wat
You should read the documentation for things to see what parameters they take
For example the Vector3 constructor only takes 3 parameters
ok
Is there a way how I could calculate how much velocity is being added to the rigidbody from 1 particular source? I have multiple .AddForce() sources to the rigidbody and I would like to limit one of those sources to only be able to add up to X velocity, no matter the global velocity (So lets say current velocity is 0, so I can add up to max 0 + X velocity, if current velocity is 100, then I can add up to 100 + X velocity, etc.)
alr yeah i quit
@desert timber Do you know how to add a point in ProBuilder?
I've got a point (TOP LEFT) but I was wondering how to create a point below it. I can't find a way to do it
that would be called splitting an edge, and is not available in Unity, it's also unrelated to #⚛️┃physics
actually, you can, neat: https://docs.unity3d.com/Packages/com.unity.probuilder@4.3/manual/Edge_Subdivide.html
(probuilder does a lot more than I realized, actually... wow)
you'd have to keep track of that yourself somewhere I believe
Alt + S doesn't do anything
umm, try asking in #🔀┃art-asset-workflow
Yeaa, the problem is that I don't really know how can I keep track of current local velocity value that is being added by 1 source independent from global velocity
I would imagine two monobehavior classes, eg, Train and Passenger, where the Passenger keeps reference to the Train and adjusts for changes in relative velocity each step
maybe tricky though, since things can move in random orders and potentially cause collisions
Gravity not working at all
I'm creating a custom 3D player controller and I'm using a box collider as the collider (idk if this is relevant, but the box collider will always have an identity rotation). I'm trying to create custom physics simulations for the player using Physics.ComputePenetration, Physics.BoxCastNonAlloc, etc. but how would I actually put the results of those functions into use?
I have a player, and it has gun recoil that pushes the player back, or exploding crates.
I use rb.AddForce. The issue is, I need to have a high Linear Drag so that when the player's input stops, the player doesn't carry on walking "as if it's walking on ice". Unfortunately, this causes the side-effect that recoil and when nearby crates explodes, the player almost "teleports" and the movement is "rough". I want recoil / explosions to be slippery, but player movement not slippery. So, in other words, high linear drag for player movement, but low drag for recoil and explosions.
I heard that using the mix of rb.velocity and rb.AddForce can cause issues?
One solution could be that everytime there is recoil or crate explode, I would have to do if (recoil > 0) rb.AddForce(recoil * recoilDirection); recoil -= Time.deltaTime or calling some coroutine? Is that kinda approach the right one?
There are a few odd solutions like using coroutine on rb.AddForce/velocity. I have to be careful not to make it interfere with physics calculations in future e.g. slippery floor etc.
Actually for now, I'll compromise on tweaking the Linear Drag to try make it high enough for player movement, but low enough to make the recoil good looking and not changing too much.
Edit: I think this is the best way to avoid complications with interfering with built-in Physics calculations. I tried it and it is good enough.
any reason my 2drigidbody is acting weird like this? it keeps literally intersecting with a box collider at high velocities
still processing, so resolution might be ugly but does anyone know why this might be happening?
i cnat believe that sussy king can be this sus
@tough cloak hi
Hi
one sec
👍
can i stream my screen to u
np
https://docs.unity3d.com/ScriptReference/Rigidbody2D-isKinematic.html
read this through
I've been stuck at the problem with rigidbody movement for quite some time, basically what I want is to limit only player's movement from his input and not any external forces. I've been googling a lot lot and all solutions I've found consisted of:
- You can't set rigidbody velocity with RB.velocity because you will overwrite any other external forces added to the object
- If you want to limit maximum possible velocity from .AddForce() you need to clamp RB.velocity
Which is kind of frustrating because this 2 solutions contradict one another. Another solutions I've found were based on only adding force when player's velocity is under maximum speed, this solution isn't very appealing because the forces applied to gameobject will be inconstistent because you can always go sligthy above limit.
I've tried to implement or find multiple solutions and the best movement I was able to achieve was with this type of limitting maximum speed: Vector3 velocityChange = targetVelocity - RB.velocity; (source: http://wiki.unity3d.com/index.php/RigidbodyFPSWalker). But the problem again is that when I add external force, it will get immediately reduced because of this line.
Could anyone help me with this problem? I don't want realistic physics behavior, I'm currently working on prop style game mechanic, that means player can transform into many objects in the game which are being controlled by Rigidbody and I want this movement to be smooth (from player's input) and at the same moment I want to be able to add any external forces, e.g. jump pad, to the object without this impulse force being overwritten by player's movement from his input.
I've done this before. Basically, if you're going at max speed or greater, you'd project your potential AddForce vector along the current velocity direction, and subtract that bit from the potential force vector
in plan english think of it like: "remove the component of force that is in the direction of current motion, leaving any other force alone"
so you would be able to add a force opposing the current velocity but not add more velocity in the direction you're already going too fast
and you wouldn't be touching velocity directly so no worries about interfering with velocity you picked up from external sources (knockback effects, etc)
I'm going to look into this, thank you
