https://docs.unity3d.com/Manual/class-WheelCollider.html
The doc is pretty self explanatory
If the level of control/understanding you need is greater than that then yeah create your own.
Aint no easy task so that's for you to choose
#⚛️┃physics
1 messages · Page 74 of 1
is it possible to attach a animation from mixamo in a gameobject in unity?
Idk if this is the appropriate chat
let me know if it isnt
yes, im not sure i understand your question but you can download the animations form mixamo to unity
I mean, can I apply the animation in my player?
the player is a different mesh renderer
avatar
idk
yes i think
You need a rigged mesh with the correct bone structure and a skinned mesh renderer
Hey do anyone know how to make the player add force onto the other objects by ran them up, like in karlson, dani make it so like he would bump into billy and make him fall down and kind of bounces off like adding force to it, do anyone know how to make that in unity
Hey, how can i change the shape of a hitbox of the box collider 2d? I have a triangle spirit, but the hitbox is a rectangle
Box colliders are always box shaped
Look into polygon collider
ah thank you
Hello! I'm trying to make room in a level of a platformer game by moving things to the right. The issue is that the game is prefab-based and some objects have trigger areas that do not move with the object itself. Is there a way to quickly select and move like half of the level?
Why are the colliders not attached to their objects ?
and why can't you move both the colliders and their objects the same amount if they are not connected
And why would you need to move everything in the first place
unity's physics already do that type of stuff
with rigidbodies and colliders
How can this happen at all?
How do I stop a 2D object from moving?
Mostly depends on why it's moving.
And whether it's got velocity or is being lerped to a position (or some similar effect)
It'ts moving because of a 2D collider and 2D rigidbody.
I just figured it out myself, I needed to set constraints. I'm gonna' see if that worked.
Nope, fuck.
how can what happen?
@timid dove It didn't work on mobile for me but apparently the stack of 5 boxes collapses into 4 and kind of bounces like a spring.
Well, i didn’t know that, now i do
Thanks
I am having a little trouble with rigidbody2.velocity.y
the rigidbody inspector is showing incorrect values for my player's y velocity
you can see in the vid above that rigidbody inspector is showing a value of 7.67128e-06 or something when moving on x axis and shows 0 when it slides down of ladder
does anybody know why this is happening?
If there is a really fast and brief collision onEnter is called, but onExit is not.
Does anyone know how to fix that? I have to add and remove the colliding collider from a list
what collision mode are your colliders set to? try setting both to continuous and the one moving fast to continuous dynamic
Ah the head was still at discrete yeah
That fixed it!
Thanks
Also, whats the exact difference between continues, continues spec and continues dyn
How is it possible that the collider moves but not the mesh ?
the axis is wrong , i fixed that but still the mesh doesnt follow the physics
Nevermind , I found the problem. The object was marked static
Does anyone know why my character shakes?
too much caffeine?
idk it could literally be anything
is this vr?
Are your objects thousands of units away from teh origin?
This isn't VR, not sure about caffeine haha
Not sure
sorry i didn't see this but discrete is the default setting where collisions are checked every frame, use this if you have no fast moving objects
continuous is where collisions are detected in between frames, use this for objects that will collide with fast moving objects
continuous dynamic is for objects that move fast and so is also checked between frames, so use this for the object that will move fast
meanwhile continuous speculative is the same as continuous but it's less resource intensive, and i think that's cus it tries to guess where objects will be and instead of checking inbetween frames it does collisions based on that guess, so use that if you have performance issues
the docs have some info here https://docs.unity3d.com/ScriptReference/Rigidbody-collisionDetectionMode.html
Thanks a lot!
Are you directly setting a rotation without lerping
it definitely looks like you are running out of precision, try moving your character onto 0,0,0 and see if it fixes it, Unity currently does not support camera relative rendering, which means object over certain distance from origin 0,0,0 will start getting out of precision
Ah okay, might be why because I've moved the object
Hello have a simple question,
how is the addforce mesured?
is 1 meaning enough force to traverse 1 block?
or is it a force like newtons?
force doesn't mean distance
it is like newtons
so say i zero friction how much force will it take to move 1 block/meter?
If you apply 1 unit of force for one second it will accelerate the block to one meter per second of velocity
assuming the block weighs one kilogram
ohh ok i see thanks
F = ma
ok
notice the "apply it for one second part".
normal force is meant to applied over a span of time
meaning over the course of multiple FixedUpdates
so is there a way to know how much force is need to launch a ball in an arc to hit a specific position?(sorry im not that good in physics)
yes, there's a whole field of study called physics and a set of equations called kinematic equations that are designed to calculate that kind of thing
typically with kinematic equations you can determine the appriopriate starting velocity and angle you need to launch the object at to land at a particular place
if you know that you can simply set the velocity as desired and not worry too much about how much force would actually be required to do it
wow school is useful (sometimes)
Doesn't fix the issue
No, it did. I had it set to 500 100 700
hey guys how could i detect in a good way the collision? because my projectile sometimes pass through without trigget OnCollisionEnter :/
- Switch the collision mode on your Rigidbody to continuous
- decrease fixed timestep
- reduce the speed of your projectiles
- increase the size of your projectile collider
- increase the thickness of your walls or whatever the projectile is hitting
- do custom raycasting
Can someone help me understand this formula. I cannot figure out why this does not take into account the "density" of the body in the water. i.e. if its made of wood it's gonna be 50% less likely to float than if it was a beach ball.
Applying this to my boat, if i pull it deep under water, it orientates itself pointy end first (very cool), but then it shoots out like a rocket, but I would have expected the buoyancy force to be significantly less
I do this with a linecast. It checks whats between the current position and previous position and if it hits something it does damage and destroys itself
No, buoyancy doesn't depend on the mass of the object. Only its volume (and thus the volume of water displaced)
really? is it not dependent on the mass of that volume vs the water's ?
or rather.. the mass of the object has gravity acting on it, but its not using that here
It's more about the density of the object compared to the fluid
I guess if it has applied this to a rigidbody, and that has gravity enabled & has a mass configured it should even out
Buoyancy will fight gravity, sure. But mass shouldn't affect the result
You could mess with rho if you want to really tweak what floats and what doesn't, see what you get
density of water is assumed 1
You could increase or decrease it slightly depending on the relative density you expect from your object
🤔 I don't know you may end up with weird results elsewhere
show it to friends around you, see if they find the floating too quick too
https://streamable.com/v2wrjx the issue if you're curious 🙂
this is one thing, its very unintuative thats for sure
Oh I see. speed looks okay in water but once in the air not so much 🙂
yea haha
I also have quite low drag, as I thought it would affect the handling in the water. Maybe I should up that too
(outside of buoyancy - when in the air)
Yeah focus on fixing the feeling in the air, not in water
i do have an "isAirborne" bool available already, can maybe fiddle with that
added 5 tons on, seemed to help a lot
hi can someone tell me why the player still sticks to the platform even though i've added a no friction material?
Are you applying force to the player
@desert wave force as in..? they have the rigidbody component and the no friction material attached
And does one of them have gravity?
Or do one of them is being pushed against the other?
gimme a sec i'll show u how the game works
@desert wave it's basically just a very simple platformer game
@desert wave
it should just fall but it sticks to the platform even after lifting the right arrow key
Are you on windows?
yeah im using a windows laptop, if that's what ur asking?
Hit windows + G
It will show a bar in which you can record your screen better
But going back how do you move your character
by using the arrow keys
With Addforce, velocity or translate?
{
private Rigidbody rb;
private bool JumpKeyWasPressed;
private float HorizontalInput;
[SerializeField] private Transform groundCheckTransform;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) == true)
{
JumpKeyWasPressed = true;
}
HorizontalInput = Input.GetAxis("Horizontal");
}
private void FixedUpdate()
{
rb.velocity = new Vector3(HorizontalInput, rb.velocity.y, 0);
if (Physics.OverlapSphere(groundCheckTransform.position, 0.1f).Length == 1)
{
return;
}
if (JumpKeyWasPressed)
{
rb.AddForce(Vector3.up * 6, ForceMode.VelocityChange);
JumpKeyWasPressed = false;
}
}
}
this is the code im using
What happens if you put the no friction on the player?
it's already been added
So it gets stuck only when you fall on the edge of the platform ?
yeah, instead of sliding down
uhm probs because the overlapsphere
you can detect the ground diagonally
and even from the side
so you can stick to it like spiderman
i don't quite get it..
Physics.OverlapSphere(groundCheckTransform.position, 0.1f)
what do i change/add?
it would even stick you to the bottom of the platform if you jumped to it from below 🙂
I would probably try to do 1 raycast down. Or 2, one at each feet eventually
but why does the no friction material have no effect
ah it's alright, thanks anyway :)
maybe show the rb and collider of the player
yeah at first I thought you returned too early because of the overlapsphere but it's just jump code after that
Shooting in the dark here, can you try with a Friction combine of zero on the NoFriction mat ?
maybe the average with the platform prevents it from sliding 🤷♂️
?
didnt work,,
Uhm. capsule mesh of the collider seems right... I have no clue right now what is the problem :p
collider f the platform is just a box i assume
hiya, i have a question; i'm trying to make a one-way 3D platform (similar to smash bros) but i cannot get it to work. any ideas?
like, i got it as far as being able to jump through the platform and land on the top, but i cannot make the "hold x key to go down" part to work
Hey, I need Polygon colliders at all of the street walls. Is there any way to do this quicker than placing them all manually?
if your walls follow a strict pattern, you could generate the colliders programmatically
if not, when you add a polygon collider, it should automatically detect the shape if it's 2d but otherwise you'll have to place them manually unfortunately
Hoping this is the right place to post this, I haven't been on this discord in a looooong time
So
I'm trying to get this crouch mechanic working
And when the player crouches, the shrink, and all looks to be well. The capsule from the first person controller component shrinks accordingly
Nevertheless
I can't fit under the slab!
And I don't get it at all
Hey guys, I'm trying to make a system where a player (rigidbody) can stand on a boat (rigidbody) and he can move freely around it and not fall off it it starts moving. The solutions online suggest making the player a child of the platform only when on top. This doesn't work as they are both rigidbodies. How can I make this work?
3D btw
See the video below for the weird behaviors.
To be clear it doesn't do this all the time, more like in 10-15% of the cases.
Normally the discs bounce of each other and other collision objects(like the pillars) and move in an equal or opposite direction.
Weird behavior includes:
discs being clued to the ground and not budging or just flipping weirdly and getting pushed through the ground collider
Instead of bouncing off various collision objects and going into an opposite and equal direction ... it just pushes through the initial direction and does not bounce off of collision objects but rather , it pushes around them
I was wondering if anyone knew where or how this behavior gets influenced or defined ...because I don't know where to look anymore
https://youtu.be/HA60zLETNc4
You have the moving platform problem
It doesn’t seem that hard to solve can you show us more, like how is the force applied, is the collision continuos, do they have a physics material
It should
Work
how can i transform a collider? i want it to be on the human model yknow
I am 99% sure you are just resizing only mesh of player not its collider
At what point should I consider creating a simpler mesh for a MeshCollider?
why capsule collider for player is a good idea? the more i work with character controller the more i get frustrated
Yes
I have a question, how can I look at the havok debugger?
I wanted to play with it but I can’t find out how to access the debugger
There is no one fits all answer, it depends on the accuracy you need and how many of the collider you have active at once. But I'd say always, unless you have a reason not to.
i think both objects involved in the collision have to have a rigidbody as well as a collider so try that and if it still doesn't work check the normals on both meshes
also i vaguely remember reading something about mesh colliders not being allowed to collide with other mesh colliders but that might be wrong idk
can anyone help me with cloth physics? its like colliding with a collider thats not even there
If youre willing to use probuilder, you can use the meshes made as mesh colliders (keep them simple of course)
Hello, can you say why my character controller jitters when jumping to a wall?
wow, setting step offset to 0 worked
but... with step offset with value 0 I am still able to climb stairs
why?
I wish it wasn't hard to solve. 😉
The force is applied by taking a dragdistance and apply that as a force multiplier, I use Forcemode.Impulse.
The collision detection is set to continuous dynamic and I have made and applied a physics material.
On this material I have set Dynamic and static friction to 0.475 and bounciness to 1 ...friction combine to minimum and bounce combine to Multiply
I have frozen Position X on the rigid body and the rotations of X & Z
what are the constraints for?
can you freeze position on the y?
Well there is a setting that says it constrains things on y ...not sure if it really works though.... and I constrained y because otherwise the discs fly into outer space ... I fixed rotations because someone suggested that the discs might tip on collision ...but it doesn't really make a difference .... even physics settings don't do anything noticable
well you need to discover what causes the error, try only 1 constraints
or different settings and stuff like that
if its the velocity or your pc
Can u help? pls
Usually this issue is caused by calling CharacterController.Move more than once per frame
you should combine all of your cc.Move calls into one
hmm.. I use .Move() for x & z
and after
for y
in different functions
yeah you will need to combine those
ok, thanks, I will try it out
the basic idea is simple. Just take the two Vector3s you call Move with and add them together, then call Move with the combined vector instead
like I said you just have to add those vectors together and call Move one time with the result
_velocity * Time.deltaTime + (moveDir) * _currentSpeed * Time.deltaTime
?
yes that looks more correct
you can also simplify a bit like
(_velocity + (moveDir * _currentSpeed)) * Time.deltaTime```
anyone know how i can make a wall that only the player can walk through, and no other 3d objects can get past
You can use layers and toggle the interaction off for certain layers in the Physics settings
wdym by physics settings
in project settings
theres a place for physics
Hello, is there a way to share colliders between different physics scenes? I have a big world and copying everything to every scene seems to be wrong
Make a Prefab from them, then Instantiate in each scene ?
the problem is that the collider i want scenes to interact with is a massive multi object thing, copying it 16 times will be too slow
terrain, tons of roads
Not sure what your setup is, why do you have the same world in different scenes? Why not use one scene and lay the gameplay as a dynamic object on top?
The setup is just a big world scene and small scenes dedicated for physics only that i want to step
Y’all ain’t no nothing till you make soft body physics with a swarm of pixel art monkeys
is it lagging or is the player moving and stopping?
Player is moving and stopping and monkeys are pushing character around
or maybe video hasn’t loaded fully for u
It’s like a thick syrup of monkey
it was my internet that was lagging, looks cool tho
Does anyone know why my collision stops working whenever I add a Rigidbody to my Player, but when I remove the Rigidbody and only keep the Box collider it works again? The collision is specifically with the particle system
what are you doing to detect collisions
Sending message in the "collision" module in my particle system
The particle system works as a gun firing particles as bullets, but the collision is only registered when it hits the player with a Box collider, but as soon as a ridigbody is added it stops detecting it
I did "solve" it with a workaround by adding an empty object as a child and attached another Box collider + Rigidbody so I can register collisions with other colliders in the world, but the combo of both those components is what the particle collision has something against apparently
Feels very weird
Unity is the ultimate game development platform. Use Unity to build high-quality 3D and 2D games, deploy them across mobile, desktop, VR/AR, consoles or the Web, and connect with loyal and enthusiastic players and customers.
Seems like this dude had a similar issue, though never addressed
There's a bool for https://docs.unity3d.com/ScriptReference/ParticleSystem.CollisionModule-enableDynamicColliders.html I wonder if that would help here
Hello i have a question about rigidbodies and i think best way to explain my question is by giving examples(because my english isnt that great). Lets say that i have an object that i want to catapult towards a location. How can i calculate the force to make sure that object hits its target?
There's a series of equations in physics called "kinematic equations" which relate various aspects of a ballistic trajectory, including initial velocity, initial height, final height, angle of launch, etc...
you would use those equations and plug in the desired distance, initial angle, max height, target height, etc.. and solve for initial velocity
thank you very very much! i didn't even know what to look for while i was doing research!
There is a way to disable/enable all physics in game? I need to enable physics when player initial spawn event is called (mp game)
two main approaches I'd say:
- Pause time with Time.timeSale = 0;
- Physics.autoSimulation = false;
Physics.autoSimulation can be changed at run time?
of course
yeah, thank you so much man
hi,
i have gameobject that contains some colliders as chid ...
so, does OnCollsionEnter() working for that gameobject or have to this gameobject have a collider itself??
the game object itself has to have a collider
OnCollisionEnter on the parent works for child colliders
as long as the parent has a Rigidbody
not sure if this is actually a physics issue but i just have a sphere falling freely then sliding down a track. i have set the main camera to follow the ball via position and look at constraints. when i use either of the two constraints by itself, everything is smooth, but when i activate both constraints the ball/camera appears to jitter severely
is the ball rb set to interpolate position?
set to none
Try enabling it.
tried both interpolate and extrapolate and it still jitters
ball movement appears smooth when camera is in static position
How are you moving the ball?
just gravity via rigidbody
why doesnt transform.position work while physics are being applied?
Okay. And the camera is using the unity constraint component?
wdym?
yes, position constraint and look at constraint
Does the jitter happen if you just set the camera as a child of the ball?
no jitter though it creates the need to lock rotation as the camera spins with the ball
not rotation sorry but
the ball spinning changes the position of the camera globally (but not relative to the ball), like it orbits it
Interesting. The constraints component is only on the camera, right?
yeah, but the camera moves regardless of the constraints when it is child of ball
Yeah, I get that. What I'm asking is whether there's anything else on the ball.
or the camera
Hey guys!
Anyone knows the right direction to implement custom collision solving to heightmaps? Mesh-based collisions won't work because I have a lot of problems with rigidbodies boucing off the edges, also I want something more smooth without increasing any kind of resolution, just pure mathematics.
I think I have something, if a point of the rigidbody is bellow the terrain height in (x,z) I move the rigidbody up based on this difference, but sometimes the rigidbody would still be bellow the surface because of some kind of async between rigidbody physics update and FixedUpdate, I'm not sure, but every frame the point would still be bellow the surface by a tiny amount.
Also, I'm using Rigidbody's position and rotation instead of transform, because it seens that every physics frame only the rigidbody transform is updated and then it applies to transform every visual frame, I think.
So what's the correct way to threshold a rigidbody point position so that it always will be above the threshold every physics frame?
ball is just rigidbody, camera is just the two constraints
@tender gulch if I have a force applied to my player or if they are moving the transform.position runs but the player returns to their position from before it did
Maybe try using parent constraint component instead. https://docs.unity3d.com/Manual/class-ParentConstraint.html
if you're doing it on the same frame, then it's not gonna work, because physics move the objects somewhere around the fixed update.
@tender gulch how do I work around that?
this seems to produce the same results as having the camera be a ball child
You don't - that's just how physics in games and unity specifically work. What are you trying to do though? Maybe there's a better way?
There are constraints on that component too.
my best guess is that the position offset it is using is local to the ball and not global, and im not sure how to fix that
@tender gulch I want to teleport my player to a previously saved location
And what does it have to do with physics and forces?
@tender gulch the jump is based on physics because I don't know how to do gravity without physics and cant find a tutorial
I mean, what's the actual issue? How does it prevent you from teleporting to a previous location?
yeah i can uncheck rotation but the isnt the issue. unchecking position just stops it from moving at all ofc. the problem is that it is staying in the fixed place relative to the balls local space, not the world space. so when the ball rotates and its local axis change direction, the offset position moves
the only reason I know the player teleports at all is because of a debug.log but immediately after the go to where they where before the position change
If you play with freeze rotation axis, you should be able to achieve what you want, I think.🤔
Oh, I see. How do you move the player?
@tender gulch like this
This is via the controller too!
it is?
controller.Move
oh. well that's good to know.
I don't remember why, but yeah, CharacterController has that issue, that it overrides transform position.
@tender gulch ok thx for the info i'll scour the internet thank you for your time.
@hard furnace share the code where you teleport it too.
couldnt seem to find a configuration that works, however im spending way too much time on a minor issue for a learning micro project so I'm going to move on. thank you for your help
And where you call Recall?
Oh, didn't notice it
Does that work?
no, I think what you said was right about the character controller having it's own position tracker was true.
@hard furnaceHere's an explanation and solution:
https://issuetracker.unity3d.com/issues/charactercontroller-overrides-objects-position-when-teleporting-with-transform-dot-position
@tender gulch thank you
hey guys i need some help applying some spring bones to my model can anyone help me please
Say your problem, people will respond to that
Hi im trying to sync a player models position to a physics objects velocity but I want to keep the player model always facing up and only rotating around the y axis (Hope that makes sense) This is the code I have currently (This is in Update) but it rotates around other axis not just Y
//Set position of player model to the same as the Physics ball
transform.position = new Vector3(ballRB.transform.position.x, ballRB.transform.position.y - 0.25f, ballRB.transform.position.z);
// Rotate player direction to direction of travel
if (ballRB.velocity.magnitude >= 0.2f)
{
Quaternion dir = Quaternion.LookRotation(ballRB.velocity, Vector3.up);
Quaternion slerp = Quaternion.Slerp(transform.rotation, dir, ballRB.velocity.magnitude * bounceTurnSpeed * Time.deltaTime);
transform.rotation = slerp;
}
that is my problem i need to apply spring bones to my model
just project the velocity vector on the x/z plane
Vector3 velocity = ballRB.velocity;
Vector3 projectedVelocity = Vector3.ProjectOnPlane(velocity, Vector3.up);
Quaternion dir = Quaternion.LookRotation(projectedVelocity, Vector3.up);
anyone know how I can stop the player/capsule from being brought upwards by the ball? i'm just using addforce Acceleration on the x&z plane
your video isn't loading for me, but could you constrain the player's Rigidbody position on the y axis?
I need the player to walk up the ramp and i'm sure that's not the proper way to go about this.
https://streamable.com/s0hwwx
in effect the ball is also a ramp right
but it seems weird to me it's flying upwards that much
i don't see how when the pill collider shouldn't be stepping onto the ball
can you show your code?
void FixedUpdate()
{
//CancelUpwardVelocity();
if (!mouseDown)
return;
destination.y = transform.position.y;
targetVel = (destination - transform.position);
targetVel = speed * targetVel * Time.fixedDeltaTime;
var currVel = playerRb.velocity;
currVel.y = 0;
var diff = targetVel - currVel;
var force = diff / Time.fixedDeltaTime;
if (force.y > 0)
Debug.Log("FUCK");
playerRb.AddForce(force, ForceMode.Acceleration);
}
somehow the angular velocity or the torque of the ball is bringing up the player
Plane.Raycast, clicking on a plane the player is in.
it shouldn't matter because i am taking out the y component in destination and in targetVel
i check if there is any upwards force being done, but I don't get that debug message
so the upwards force that is being generated by in-house unity physics
yeah it's probably not your force that's pushing it up it's the collision
and/or friction
if the ball rotates there may be a friction force pushing your player up a bit
i have added a physical mat on the capsule/player that gives it 0 static & dynamic friction, same issue
with friction combine set to minimum?
no, let me see
i think that fixed it lol
why would this be a thing when i gave it 0 friction?
nice
by default friction combination takes the average
so your player has 0, the ball has the default which is nonzero
the average is nonzero
ah so if it collides with anything that has friction then it will average between my 0 friction and something's 1 friction lets say, giving the ball 0.5 friction?
now how do I raycast at the capsule/player feet to a wall?
i don't know what would be the best way getting the vector from feet location
besides using -rigidbody.y/2, which i probably will do i guess
i need to remove addforce into walls, so i will project onto a plane and have it slide against all steps/walls
essentially this https://www.youtube.com/watch?v=Q6LC1ubawCo
you can get the bottom of the collider using collider.centre - collider.height
then to get the direction you can use rigidbody.velocity.normalised, and set the y to 0
and then multiply that vector by the distance of the ray you want
only problem is utilizing the right raycast distance, i assume i need to somehow get the thickness of my pill collider. but i don't see how that can work with dynamic players like rotated rectangles
capsule colliders have the radius property
i'm going to be using multiple box colliders, like leaning forward with arms outstretched
once i learn how to 3d model lol
what is that vector supposed to be? the ground acting against my feet? or a vector of a wall opposing me?
that vector is from the bottom middle of the capsule collider outwards in the facing direction
oh, normalized. i was reading normal vector
you could have a vector3 that is transform.position + direction * aLargeNumber
and then you could do Bounds.ClosestPoint of a mesh collider of the player to get which point is going to collide first with a wall if the player moves in the current direction
then you can raycast from that
i'm sure the ground will always be the closest point
closest point on the player's collider
if the case is that the player has an arm sticking out then the closest point will be on that arm
i imagine my colliders will look like this
maybe even a bunch of pill colliders
so the main body will be a big pill collider where the ground should be the closest point
so in that case the red square is the far point, which is determined by the red arrow which is the direction of movement, and the end of the green line is the closest point
then raycasting from that green point will determine if the player is going to collide with a wall
the green arrow is the velocity of the player, wouldn't the red circle be the closest point for bounds vs the orange circle?
or is it that using ClosestPoint with the direction vector will ignore the ground completely because there's no y component on the vector?
in this case the point where closestpoint will be determined from is directly ahead of the centre of the player, because it is transform.position + direction * [distance you want to look ahead]
so it will be somewhere around the edge of the orange yes
on the capsule collider, right?
this would be easier to do if it was all one collider, so either that or one mesh collider
if it was separate colliders then you would have to run this check on each one, and see which is closest to the far point (the green circle)
you can't fuse colliders?
i imagine the mesh collider will be tied to my character's animation
which i want to ignore and have non animated colliders
the mesh itself and the mesh collider can be different
like the renderer can be animated but the collider stay the same
hmmm
apparently you can have compund colliders which collectively act as a single rigidbody https://docs.unity3d.com/Manual/class-Rigidbody.html see "Compound Colliders"
yes but i don't think you can call Bounds on them as if they were one collider
np
each collider in a compound collider would have it's own bounds.
is there a way to make friction specific between 2 rigid bodies but not change the overall friction?
give them special colliders for each other with the appropriate friction properties and set up layer based collision so they only hit each other
and have normal separate colliders for everything else
how do you setup a special layer based collision like that?
thanks
@here Hey there, I am working on a movement system for my game and I need help with implementing a good system for sliding on slopes with character controller. I want to create a realistic sliding system in which when you jump forward with an initial speed to a slope, you will slowly change direction to the ground. In my current system, when I jump on a slope, the player immediately changes direction to the ground, which is something I don't want. I will appreciate any help.
Basically, I need something like this: https://ophysics.com/f2.html
how can I check if my player is grounded? this doesn't work because it's a null reference and i'm sure this won't work with floors
private void OnCollisionEnter(Collision collision)
{
if (Vector3.Dot(collision.rigidbody.position, transform.position) == 0)
grounded = true;
}
i'm thinking of raycast, but it's not perfect because the collider/rigidbody can be bigger than the playerCollision.size.y/2 used for raycast
I'm trying to stop the playing for addforcing into a wall using friction to stop themselves from falling. i want friction but not anti-gravity friction so i need to do a ground check
i feel that this is just too hackish
return Physics.Raycast(transform.position, Vector3.down, playerCollider.bounds.extents.y * 1.1f); // 110%
i don't think a raycast is a bad way to do it, but i would have the ray start slightly inside the collider and finish slightly outside of it to have a skinwidth
you could also try something like a physics.overlapsphere instead https://docs.unity3d.com/ScriptReference/Physics.OverlapSphere.html
am I not able to get the contact point in O(1) for OnCollisionEnter?
afaik you need to for loop through Physics.OverlapSphere
i assume it would be the last collision in the list so collision.contacts[collision.contacts.length-1] could be the way
if it's going to be overlapsphere with a ground layermask, and the sphere doesn't extend beyond the x or z of the collider then it can only hit the ground
so i don't think iterating through it is necessary
i'm not using ground layermask, seems like a hassle
but i want dynamic physics
where dynamic things are happening like maybe a piston hits you up, or you land on other balls
or you're on a vehicle moving on the rooftop
so if you want to check for other things that aren't the ground then it isn't a ground check, so pass in the layers you want to the overlap
pass in layers you want to overlap?
i mainly need a boolean check for when to stop player control when in the air
so you can have a LayerMask and add to it the layers that are considered ground, so 'Ground', 'Piston', 'Vehicle' whatever
and if the sphere is below the player and doesn't extend horizontally, then it's only going to hit things below it
so then you only need to check if the length of the returned array from overlap is more than 0
no need to iterate through the array
or you could use the NonAlloc version and check the returned int https://docs.unity3d.com/ScriptReference/Physics.OverlapSphereNonAlloc.html
wouldn't that be expensive to check per oncollisionexit?
since you're constructing a list and adding to the list by iterating through all game objects that have this layer?
the nonalloc version is like the normal but generates no garbage
so it uses less resources
why not just do collision.contacts[collision.contacts.length-1] for OnCollisionEnter, then check if the dot product is 0 or close to 0?
i'll see if it works, if not i'll try the nonalloc
yeah sure
this kind of works but not very well
var contacts = collision.contacts;
var dir = (contacts[contacts.Length - 1].point - transform.position).normalized;
var dot = Vector3.Dot(dir, Vector3.down);
Debug.Log($"dot: {dot}, dir: {dir}, down: {Vector3.down}");
Debug.DrawRay(transform.position, dir, Color.red, 50);
grounded = dot > 0.9;
ah whatever, i'll just use layers
void OnCollisionExit(Collision collision)
{
if (!grounded)
return;
grounded = collision.gameObject.layer == 9;
//grounded = IsGrounded();
}
though the exit part breaks
wouldn't this break if you have walls on the side of your character that are Layer Ground? also isn't this checking via a sphere vs your collider?
so as i said you should not have the sphere's radius be larger than your player's, so horizontally it should be smaller so that it can't detect something next to it but only below
what do you mean by your collider
you're not using your collider instead of this sphere hitbox/collider
if you want to just use the player's collider then you can check if the collision's layer is 'ground' on exit or enter
this sphere is if you want to check below the player by a certain amount
yeah i'll probably do what you're saying, though I think the sphere needs have a smaller radius at your feet so it doesn't come into contact with walls that are ground layer by accident
so your collider blocks the sphere at your feet from touching walls
if it's a capsule collider then you can set the radius of the sphere to be the capsule's radius minus a little
just to be safe
are physics and player controllers the hardest part of making a game?
because i'm astonished how many issues/bugs there are with this lol
physics player controllers are always glitchy, thats why "everybody" builds custom controllers with kinematic physics
they're a fundamental part of it so you need to get it right for sure or else you don't have a game
some people find it easy, some don't
it also depends on how complex it is
well i never took any gamedev courses or read books on it
so i don't know how to handle a lot of things properly or its physics
its easiest to not use "realistic" physics at all for gameplay
i imagine if i actually took gamedev courses in my comp sci program, i would probably understand how to deal with a lot of these issues i'm having lol
very unlikely, a CS course cant teach you nearly enough
maybe you can draw some neat space filling curves or rotate a camera, but other than that... this is a learn-for-your-self type of thing
you are unable to check via Length to check there are 0 ground layers or not in the sphere as you pass a pre-allocated array that has a pre-set Length. I find even check colliders[0] == null doesn't seem to work either
i.e. Physics.OverlapSphereNonAlloc(bottom, radius, cols, 9); isn't picking up layer 9 even though it should be
or am I supposed to do 1 << 9?
oh that was it...
Still having issues trying to stop adding force if the player is stuck on something. Capsule/player flings off steps/walls too easily
i thought having a raycast done at a lower position would help but then the raycast doesn't register because it's in the ground
you can just check whether it's touching a wall using a collider
tag the wall and check in OnCollisionEnter
walls can be ground, so i can't use tags
wdym walls can be ground
if you see the ramp in the video, that ramp can be wall + ground
but then it will still fling up
it shows in the vid when i make the capsule move into the ramp at the bottom, it gets caught on the ramp and the extreme horizontal force forces it to fling up because of the capsule collider getting over the step
I just realized that this may be a better thread for my problem than #archived-code-general - I have a wall that's supposed to pivot around a point. I used a hinge joint for this. It spins properly when the transform rotation is set to 0 or 180, but if I try to set the transform to 90 or 270 it gets stuck. Any ideas?
Actually looks like setting the transform rotation to anything other than 0 or 180 breaks it
I made it so my capsule slides along walls, but when the vector reaches a corner then it stops working as the raycast isn't detecting a wall anymore. Any advice?
i have no way for sure checking if my capsule is colliding with a wall in my function unless I raycast all around me and check if i'm colliding...
at this point i'm considering of having an array of collisions that i update with OnCollisionExit/Enter
What are you even trying to do? Make a custom physics engine? 😅
i'm trying to fix all the bugs i'm having D:
Try a CapsuleCast perhaps? Instead of a raycast
but then i'm reliant on using a CapsuleCollider
maybe a SphereCast but providing the largest boundary?
I guess a sphere cast could do as well, anything that has a radius and not just pin point.
I still don't know what you're trying to achieve, so I might be wrong.
the problem is that i don't want the capsule/player to fling around corners of walls or slingshot off steps like the bottom of that ramp
because there's a large force being applied by clicking and dragging your mouse around which tells the capsule where to go
so if you apply a huge horizontal force and the capsule hits a speed bump, it will fly upwards
so i need a way to check for speedbumps and corners of walls so the sling shotting doesn't happen
i like the control scheme as is, but i don't like this sling-shotting/flinging coming from the collider getting stuck on the environment
i feel that the corners of walls can be fixable, but the speed bump bug is impossible because if you raycast so close to the ground then the raycast will hit the floor itself instead of the speedbump
@tender gulch the slingshotting
err i cropped i video, so this is the exact moment
maybe playing around SphereCast will fix it...
but i thought this is a common issue with rigidbody player controllers so someone might know how to fix it
Maybe detect the ground level in direct proximity to the capsule, instead of where the mouse points?
You don't usually use rigidbodies with mouse controllers.
could you elaborate?
well i didn't want to code everything from scratch and wanted the player's colliders to move the ball
also, aren't FPS games rigidbody player controller based? Why don't they have these issues?
Neverminded. I assumed something about your implementation that's probably not the way it is.
What could be relevant though is that you increase the force the farther away the pointer is, right?
Because they always apply the same force no matter the direction. They also often just control velocity. Some of them might be using CharacterController instead.
Why not use a navmesh agent?
What could be relevant though is that you increase the force the farther away the pointer is, right?
I do, I find the controls become very response and intuitive given that there are no obstacles that glitch it
navmesh agent?
Well, that's probably the problem. I don't think it's a great solution. At the very least, you should clamp the force magnitude to some maximum value and also probably take into account the current velocity of the character to not make it jump from 0 to max in 1 frame.
Yeah, navmesh, you know? The usual way you'd handle click and move movement.
i never learned it in the junior programmer pathway
i'm new to gamedev, i just know how to program
if that's for AI pathfinding why would that help with player controllers?
Yeah, there are way more features in unity. You should explore different approaches.
i don't even know how to find them without being told about them lol
Well, if you want a click and move movement, then it's 50% ai.
I think it's possible to configure your controller if you take into account the things I mentioned.
even if i clamp the force, the unity engine will still treat speedbump like a launch ramp converting the horizontal force into an upward trajectory. it just won't slingshot up as high
Limit the max force you apply based on the current velocity of the character.
if it's small enough, it won't be able to go up. I think
another way, is not using a capsule but a box for example
in what manner? force * playerVelocity.magnitude?
Yeah. And maybe use a curve too, if you want it to be more responsive.
a curve? so a log function?
force = max force * velocity/ max velocity;
You could use an AnimationCurve to configure it in the editor however you want.
i don't understand what you mean by curve. you mean to configure the acceleration?
force = maxForce * curve.Evaluate(velocity/maxVelocity);
i mean you could do a squareroot function, but squareroot is expensive for computers
velocity/maxVelocity gives you a value from 0 to 1. You can use a curve to remap the value in a desired way.
Sure you can, but you probably want it to be more customizable and adjust it manually/visually in the inspector.
like this
that's a component? I'm not finding it
Yeah, it can be pretty handy at times.
i think the sphereraycast + velocity checks should fix mostly everything
Perhaps.
@tender gulch i think the velocity limiter helped, though it's still launching over speed bumps
yeah last thing to do, but i'll save it for tomorrow as it's 2 am here
plus i gotta actually study for some job interviews i got coming up
@tender gulch in case you were interested https://simmer.io/@Davidj361/ball-pusher
anyone have any advice on how to add controls to balance a 2d capsule, to push it left and right, on a flat surface as challenge?
use Rigidbody.MovePosition or Rigidbody.AddForce. avoid manually changing velocity as it can mess with physics, also transform.position should usually be for reading, not modifying
ill try that and get back to you
dont know if im doing it wrong, but it still isnt working
btw im also using a hinge joint as the balance point
did you debug.log the value of horiz in Update to make sure you're not multiplying by 0?
and did you debug.log the value of moveSpeed in FixedUpdate
yeah also from -20 to 20
and debug.log the value of rBody.velocity at the end of FixedUpdate?
congratulations you've narrowed down where the error is, that's 80% of solving the problem 👍
yes
oh
next step is to debug.log a right before rBody.AddForce
to make sure you're passing the right vector AddForce
it stays stuck at 0.4,0.0 and -0.4,00 depending on the arrow key i press
yeah i would suppose it should be greater
try multiplying it by like 1000 or something before passing it to AddForce and see if it moves
sometimes it is actually moving, you just can't tell bc the force is too small that happens to me a lot
it stayed the same when i changed to speedfactor to 1000
hmm
but when i removed the deltatime multiplication it kinda worked
maybe the issue is friction with other bodies?
oh ok
maybe make speedfactor like 1 million lmao
seems hacky but whatever works, i guess
oddly enough it seems mulitplying it by Time.deltaTime just totally restricts it to 0.4
weird
and btw why do you use time.deltaTime?
use Force.Acceleration
using Time.deltaTime makes the movement the same speed across all computers regardless of cpu speed
thats update problems, fixed update runs at a constant speed
ah yes i missed that it was in fixedupdate oops
in that case definitely don't use time.deltatime
where should i use it?
rb.AddForce(a, ForceMode.Acceleration);
https://docs.unity3d.com/ScriptReference/ForceMode.Acceleration.html for reference if u want it
i think i can only use ForceMode2D
cuz im using rigidbody2d
and there doesnt seem to be a ForcceMode2D.Acceleration
well do rb.Addforce(a*rb.mass);
thanks, seems to be working well without the deltaTime
ill just mess with variables to control how fast i want it to rotate
np, good luck
Anyone know how I can prevent my particle system (shield bubble around the character) from moving after a collision? The Transform is 0,0,0 after collision but the mesh keeps moving. If I stop/play it's always reset back to the original position.
set the position to world position instead of local position, it should be an option in the particle system component somewhere i forget where exactly
oh wait i see it
simulation space
in the first menu
yea i tried that, i actually wanted to use custom and set to the player transform but the bounding sphere is totally wrong then. Either way none of those options seems to have any effect 😦
i also tried playing with Limit Velocity over Lifetime... also seems to have no effect.
also collision > dampen etc seem to have no effect
oh huh
crazy right? 😄
did you try making the particle system a parent of the player
ik that seems weird but it could work 🤷
no but it does work with custom to some degree, its just that the bounding sphere is a bit off. but its ok i dont need it to be stuck to the player, its fine if it's in a fixed position, probably better for GPU in VR anyways 😉
ok well you decide what works best for your project 👍
i just need it to not move when something collides with it 😦
you could remove the collider
what do you need the collider for? is it completely necessary?
yeah its a shield, to block stuff from hitting the player
i see
you could make it a trigger and manually remove or repel objects in OnTriggerEnter
im also reflecting stuff OnParticleCollision()
idk if it's possible to make particle colliders a trigger but if it is, try that
then reflect stuff in OnParticleTrigger or whatever the equivalent is
yeah but the difference is that triggers don't physically collide with anything
so you could have the same effect without the system getting pushed by other bodies
i'll have to investigate that, dunno if i can get particle system triggers to work the same but its a good tip, cheers 🙂
ok gl!
should I use update or fixed update for applying a force on a rigid body player when the wasd keys are pressed?
you should use update to register input, as doing that in fixed can miss some inputs, but you should use fixed update to apply the force since that will be in time with the physics simulation
and to get information between the two you can store the input as a global Vector2 in Update and then use that for applying force in FixedUpdate
hi guys, I had a problem on meshcolliders, my terrain is made by meshcolliders , when my character(with rigibody) walking on it(use add force), it bumps a little on the seam of meshcolliders, even it is absolutly flat. both my terrain and character have physic material with no fiction ot bounciness. any way to fix this?
so i have a rigidbody2d the starts frozen on the y axis, then the y axis is unfrozen (constraints set to none). now, it should be falling at this point, but it stays until interact with the constraints in the inspector (doesn't matter which one. i could tick freeze rotation and suddenly it starts falling)
nevermind, I had to set the object to never sleep
so i tried to make a steering script and now the steering works but the problem is after i made that script this started happing
can someone help me how to make the character slide like this?
the tutorials were useless
help plz
i think if you take the velocity of the player * normalized vector of player's aim
anyone know how I can detect walls? I'm using this but the spherecast ends up in the middle of the wall sometimes and doesn't detect a wall...
Physics.SphereCast(bottom, playerCollider.bounds.extents.x*1.1f, rayVec, out hitData, rayDist, ~(1 << 6 & 1 << 8))
why are you detecting walls and how are they positioned? normally i would use a raycast so i'm wondering why you can't use that
because i want to slide against walls and also stop adding force into a speed bump that causes my player to fling of them
oh right i remember that
you could do a 4-way raycast that might work better than a spherecast
oh wow, i think my mic below my computer picked up electromagnetic interference from my GPU
4way raycast?
yeah 4 raycasts: in front, behind, right, and left
i mean what i'm doing would serve the same purpose, but i notice that if the spherecast location is inside the wall then it doesn't detect a wall
Physics.SphereCast(bottom, playerCollider.bounds.extents.x*1.1f, rayVec, out hitData, rayDist, ~(1 << 6 & 1 << 8))
if you have colliders on the walls and the player, you shouldn't go into the wall
you could make a second slightly larger player collider to serve as a buffer for the walls only
and set layer collisions off for other layers
i mean they already don't go into the wall, not sure what you mean
if you don't go into the wall, why is the spherecast inside the wall
just cast it from the player's position and it won't
i think this is the spherecast, i tried using Gizmo drawsphere but this is what the spherecast should look like:
looks like its origin is outside the wall so what's the issue?
spherecast isn't detecting a wall apparently
try casting from the player's position
it doesn't look like it's at the player's position
it's at the bottom of the player's "feet" but i had to give it a distance of 0.1f because i can't give a distance 0 as it doesn't work
Here's the vid of the issue, it has working wall sliding but when the player goes too fast into the wall then it doesn't work
maybe i need to make the spherecast radius smaller
sure sounds like a good idea
also don't make it at the player's feet
you should cast from the center of the player
i think i'll just give up the the speed bump flinging issue
i'll just focus on polishing this wall sliding
i don't get why spherecast doesn't work if any part of the sphere is already inside an object because that means i can't spherecast with a radius of my player's height
that can't be the issue
if the sphere wasn't touching anything it would never detect anything
there has to be a way to cast and have it collide with objects lol that's the whole point of it
don't use speherecast, use OverlapSphere
but how can i get the contact point and the normal of that?
since it returns Colliders
do you need the contact point?
well i need to know where the OverlapSphere is touching and i want to calculate the normal of that
but why do you need that
because i need to project my movement over the normal
wut
if you project your movement vector over the normal of the wall it will make you slide https://www.youtube.com/watch?v=Q6LC1ubawCo
Start your spherecast at the top of the player's capsule and send it down
can OverlapSphere not provide the normal vector that i need? not sure if it's possible via the Collider objects it gives
it doesn't provide any normals no
not sure how such a thing would make sense with overlapsphere
Hello, I am creating a 2D game.
I got a problem with combining triggers and colliders. What I have are 3 layers: Unit (players and enemies), Environment (platforms) and Collectible. Environment are static objects, and both Units and Collectibles are objects with rigidbodies, having gravity, etc. So all 3 groups of objects need to have colliders to prevent Units and Collectible fall through Environment. However I also need to make Units "walk through" collectibles, if they cannot pick them. If I remove Unit/Collectible from Physics 2D matrix in project preferences, I also make them unable to recognize their triggers, so Units cant pick Collectibles onTriggerEnter2D.
Best solution would be if this Physics 2D matrix affected only colliders, but triggers would work for any layer (I can then resolve its effect myself), but that doesnt seem to be an option. Does anybody know the correct sollution for this? Pretty please? 🙂
you can put the different colliders on different layers
like have a non-trigger collider for the item so it doesn't fall through the ground, and then a separate trigger collider so the player can pick the item up
and have them on separate layers and set up the layer matrix appropriately
Yeah, that was my backup plan, but it doesnt seem right, since I would then need duplicated every layer, something like Unit_Colliders, Unit_Trigger, etc... 😦
Only the item needs two layers in the system I described
Is there a way to make it so particles stop being affected by physics after a first collision?
I have snow particles falling on a slope and I want them to "stick", not slide down
Hey, im currently trying to implement wall jumping and its mostly implemented just it should bounce back the opposite way and its not doing that currently
It just jumps on the wall and slides down then slides away horizontally, when it should jump off of the wall the other way. Here is the code: https://pastebin.com/D6SFUckk
Pastebin
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
the wall jump code is at the bottom
Well, I guess I have no other choice. Still I would expect Unity to handle this better, I dont really belive this is the most correct solution.
How would you like or expect it to work better?
Some settings that enables triggers to work for all layers or to split colliders and triggers in Physics2D settings.
I have a question about Rigidbody constraints. I have an object that shouldn't move in the z axis (that works fine) and shouldn't rotate on the x axis (doesn't work). I don't understand because if the game is running and I enable constraint on the y rotation then the object stops rotating on both but when I disable the Y rotation constraint both remain constrained. Any Ideas?
How would i make it so it goes back up by its self?
You can affect the rotational velocity of an object with AddTorque
Can anyone help me with this?
why dont you use ragdolls? i guess your using no physics at all right now
hey i have some problem with ontrigger. its just not detecting ALL of my collisions when they happen to fast
is that because of some other scripts that are taking to long to process, or is it due to physics settings, or is untrigger unstable when it comes to fast objects?
my scripts where fine and now i get this error
so i used 10 colliders instead of one large scaled one and its working now. why is that a deal?
damn its still unstable with large stacks of collisions
i still dont get it
Your project is using the new input system, your code is still using the old.
so how do i make it so they update
why is the damn ontriggerexit not working?! this is pure horror
my problem is that ontriggerenter works but ontriggerexit is not working all the time
Weird
my timestep is already at 1/30 so i have higher collision detection
my projects is based on physics and i have tousands of colliders and rigidbodies in my scene
if the issue is with collision detection then have you tried setting the one of the colliding rb's with Continuous collision detection and the other (the one that moves) with continuous dynamic
no i will try that. now i store the colliders in a list, but that is so stupid
but both colliders are moving
and yea i tried to change the mode for one object, but not for both
but i also dont want to set the mode to continuous with a tousand rigidbodies in my scene
its working much better now with both objects set to continuous , but still i need to have a list
you can have continuous speculative mode, it's less accurate but more resource efficient
oh ok
or you can have some type of method where you occasionally do a spherecast to check if a collider is nearby, and if it is then turn on continuous / continuous speculative
that could save some colliders from being continuous if they're further away
https://answers.unity.com/questions/1189707/oncollisionenter-being-called-without-the-collider.html I have this issue where my player not-visually collides with objects behind it that are somewhat close. I have many OnTriggers and OnCollisions. What should be my next step to fix this issue and future proof this?
Unity is the ultimate game development platform. Use Unity to build high-quality 3D and 2D games, deploy them across mobile, desktop, VR/AR, consoles or the Web, and connect with loyal and enthusiastic players and customers.
Figured out that the Default Contact Offset was something like 1e-08. Documentation states: "Set the distance the collision detection
system uses to generate collision contacts. The value must be positive, and if set too close to zero, it can cause jitter. This is set to 0.01 by default. Colliders only generate collision contacts if their distance is less than the sum of their contact offset values". Changed to 0.01 and it's solved.
Can someone help me make my character sprint?
here is the script
My character controller uses rigidbody.velocity to move the player, and whenever I move horizontally while on a moving platform (that is the player's parent while hes on top) the player stops moving with the parent. When I jump, again setting rigidbody.velocity, the player still moves with the platform. If the player stays still the moving platform moves the player without issue. The whole game takes place on a moving platform so it's kinda a big deal that it works, does anyone have any insight into what I'm doing wrong?
don't make the platform a parent of the player
how do I make the player move with the platform then?
yeah - when you set the velocity directly you... set the velocity
that overwrites any velocity your character may have picked up from friction with the platform
ok, I'll switch it to transform.translate or something I guess, thanks
Are unity's rotational constraints not working for anyone? Because I am having trouble with them in my current project so I created a new project on the latest version of unity and it still doesn't constrain the rotation axis.
that's going to be even worse...
want to elaborate on what you're trying to do and how you're trying to do it?
I am creating a physic Ik character that is 3d but the game will be viewed 2d, this means the character should not rotation on the X axis. the problem I am having is the rotation constraint of the rigidbody of the parent body doesn't stop the character from rotating on that axis. plus I have tested a cube object in a new project and freezed the same x axis and it still doesn't freeze it.
The Rigidbody constraints will only prevent the physics engine from rotating your object on that axis
if any other code or components do it, it will not stop them
for example if your IK controller or other scripts do it, it will not stop that
there is no code touching that axis
in this test project there is no code all together and the transform still shows the object is rotating on that axis
this is the test project, the x rotation axis is constrained and yet it still rotates
Hi all,
I was wondering,I have bunch of static colliders on multiple objects that I want to group together as a single entity so it can hold an OnCollision handler on a root object. The only way I know to do this is to add a kinematic rigidbody on the root object. However the doc says that static colliders are colliders with no rigidbody, so how are these static-but-not-quite colliders treated by the physics engine? Kinematic colliders, or Static colliders? Does it make any difference at all if I remove the static flag on those objects and just have them be a kinematic object that simply never moves?
I see a star next to the filename. Could you save the scene, just to be sure ^^
The "static" flag on the object is irrelevant here.
If you have the rigidbody it's a kinematic collider
If you don't it's a static collider.
It was. Now i'm done changing everything to rigidbody.moveposition and it works. I wish I read your comment earlier.
its much less acurate on android
i have 5 ghz cpu. its running at 300 fps on my machine
damn
i cant have realtime log from android on my pc. that is f**d
I want to rotate my object so that it is parallel to my collider all the time. I am emitting a ray and find the angle between hit.normal and myObject.transform.up. And how to rotate an object knowing this angle? Thanks
if you want to set the rotation to that angle, just do transform.rotation = rotationYouCalculated;
if you want to rotate by that angle, do transform.Rotate(rotationYouCalculated);
Hey! I've been working on a player rigidbody controller and have come across an issue that I need to solve. The script uses rigidbody drag to slow down the players movement, however this means that when the player is jumping that their fall is slowed. Is there some way to make drag only effect x and z movement, or another way to slow down the player that doesn't use the rigidbody drag.
Drag How much air resistance affects the object when moving from forces. 0 means no air resistance, and infinity makes the object stop moving immediately.
Either you slow down player speed, increase gravity or exert an opposing force to the players velocity (times) a certain dragMultiplier. For example, you have an rb.velocity vector of (1,1,1), you can then rb.AddForce(-.5f, 0, -.5f).
Thanks for the help!
how do I make my rigidbody that has some joints attached to it, not be dragged down by objects that are hanging from those joints.
I still want to be able to set the velocity and stuff so can't make it kinematic
that's kinda what joints do though
@cobalt pilot how about you lerp the velocity instead
rb.velocity = Vector3.Lerp(rb.velocity, targetVelocity, 0.1f);
one thing you could maybe do is make objects that are not children of your Rigidbody but do follow your rigidbody and are kinematic at those attachment points. Then attach your joints to those follower objects.
I often do something like this to also make it more realistic via limiting the equilevent impulse per frame
Vector3 targetVelocity;
float maxImpulse;
Vector3 currentVelocity = rb.velocity;
Vector3 nextVelocity = Vector3.Lerp(currentVelocity, targetVelocity, 0.1f);
Vector3 delta = nextVelocity - currentVelocity;
rb.velocity = Vector3.clamp(delta, maxImpulse) + currentVelocity;
Why woukd I do that
setting the velocity part
but looking more into it, thats probably not what you want
hmm actually yeah
if you do this velocity control on the main object
and it has a few other objects trying to drag it down
it should be able to maintain the altitude
isnt that just going to fall down sstill?
cuz it's set at 0.1f
so its almost the same as the original velocity
Hi, for some reason my particle effect collision isnt working. It was working just fine one another one I was testing before.
It just phases through walls. Although it works with planes, but thats not what Iam going for
@viral ginkgo how does that work since it's not compensating for the force pulling it down is it?
lets say you want it to follow a trajectory
or a position
targetPosition
you set targetVelocity = targetPosition - transform.position
yes
and feed to my code
and you'll follow the position
it will follow a little below
like 1 meter maybe
and it will compansate
I see
Ill try it out, don't completely understand it yet
it does not compensate for the force and is still dragged down
did you try my suggestion
well if I have it follow that object then it will also just move with the object when dragged down no?
why would the object be dragged down
there's no force pulling it down in what i described
ooooh I understand now
yes Ill try that
that makes it very stuttery for some reason
Hello, quick question, for some reason my instantiated object falls slower than a normal one and I have 0 idea as to why.
Vehicle = Resources.Load<GameObject>(MenuScript.Vehicle);
Instantiate(Vehicle, Hitbox.transform.position + new Vector3(0,10,0), Hitbox.transform.rotation);
you probably have a script on it that affects the velocity
Now I'm even more confused since I don't remember changing any velocity / gravity values, I guess I know how I'll be spending my weekend
SHould be very easy to find
Don'y you have some kind of movement script on the vehicle?
It was actually a box collider being right inside of the vehicle's collider haha
i have a shoooting script spawning bullets with rigidbody runing into an enemy which also has a rigidbody
but the enemy gets confused bc it gets pushed by the bullet and it meses up the ai
how do i fix it?
make the colliders triggers, then use OnTriggerEnter in your code instead of OnColliderEnter
you can also make one of the colliders a collider and the other a trigger so that one still collides with other things, just not with the enemy
I have a problem... I have a gameobject that has a character controller (of course it has its own collider) .. and in one of its children i have added a collider too... I need the child's collider to be bigger than the parent's one ... here is the problem :: IN GAME MODE THE CHILD'S COLLIDER DOESN'T WORK it goes inside other colliders ... any help on how to solve this problem
where it stops is where the character controller collider hits (it is small and in the center of the object and the big collider is on the child game object)
and the rotation is done by a script put on the parent object
i have two colliders on different objects: a small sphere collider on a projectile object and a player sized capsule on a player object. in the layer matrix, the projectile will not collide with the player. how can i get a bool (or an event) when the projectile is intersecting the player?
ping me if you have a solution
CharacterControllers will only use themselves (the capsule) to determine their own shape for collisions
Since you have disabled collisions between those two layers, you will not be able to detect their intersection
Re-enable collisions between those layers to get collision events between them
hmm is there another way to detect collisions without a projectile being able to fling a player out of the map?
and yes, i am developing your average fps
Yes you can use a trigger collider
you can detect the overlap without them physically affecting each other
oh thanks
Look up OnTriggerEnter
so triggers have no collision?
ok
yes i dont mind that but I also need other colliders to be working ... but they are not
working in what way
like what are you expecting it to do
i am expecting that when the colliders hit other colliders of game objects to not interfere with them... look at the picture i uploaded above, half of the capsule collider (which is used on the child game object) is inside the wall which has a collider as well
If that's not the capsule of the CC itself, the CC will allow that collider to go through the wall no problem
also if it's just a child object of the CC and there's no Rigidbody involved at all, that's just a static collider
it is not the collider of the CC, but also I dont want it to go through the game object and I did try to add a rigid body to the game object but it still didn't work
by game object I mean the wall
If you want that kind of behavior you need to either:
- do your own custom capsule-casting solution
- Use a Rigidbody based character controller instead of CharacterController.
what do you mean by do your own custom capsule-casting solution
would a rigid body based character contoller let me use several colliders that will work simultaneously ?
I mean each frame when you want to move, do a capsule cast to detect if there's a wall there and only move as far as any collision you see if there is one
yes
you can put as many colliders on child objects as you want with a Rigidbody and they will all be considered part of the body
may you give me the function that does so or the unity documentation
thank you
and just to make sure , if the parent and child capsule colliders dont collider and one of them isn't inside of the other , they still wont work?
that was a lot of negatives lol
Are you talking about for the Rigidbody strategy or for a custom Capsule-casting approach?
no
i wanna make sure my current solution wont work at all
Just using a CharacterController it will only respect the main capsule of the CC itself
no other colliders will be considered
thanks for making it clear
howdy, just a quick question
how do i add force without intruding in the rotation?
i wanna move with addforce but i wanna keep the player rigidbody rotating in whatever direction it was rotating
in my fps i shoot a raycast from the player's view to interact with things, to avoid colliding with myself i use RaycastAll and bail when the hit is a child of my player, this works well but when i stand on the object to interact and try to interact with it looking straight down its the FLOOR that comes first in the raycastAll is this a bug ?
The order of raycastall is undefined. You'd have to sort by hit.distance (or just search through for the closest)
Hello, is there anyway to update colliders positions, rotations and scale in the game if the Time.deltaTime is set to 0?
to be more specific I have an issue where I have an editor mode in my game that set the Time scale and delta time to 0, and I need to detect when my player is touching an object so I used physics.raycast to get an object at the position of the player touch but when I move this object the raycast doesn't seems to update the colliders positions and therefore it doesn't work properly
This is the default behavior of AddForce. It adds the force at the center of mass resulting in 0 net torque.
How are you moving the object?
nevermind, I figured I could use Physics.Simulate() to update the colliders, it works now, thanks!
I think maybe you need to call https://docs.unity3d.com/ScriptReference/Physics.SyncTransforms.html
If you call Simulate () then the rigidbodies will actually be simulated for one physics frame
Probably not what you want
so i'm learning colliders and rigibody in 2d. And i'm noticing if i take corners too tightly it'll mess up the orientation (i think) of the player object? Like it'll mess up which directional keys move which directions. Anyone know why this happens?
here's a small recording. You can see based on the animator which direction i'm suppose to move and that it works till i interact with the walls too much.
player character is the pacman in the middle
i'mma gonna go out on a limp here and assume it's cause I use transform.translate
yep switching movement to velocity based worked
Hey - has anyone here ever projected a kind of "curve" based on where an object is going where they predict a possible upcoming collision?
I'm trying to find resources. Anything pointing along the way would be appreciated.
yes indeed. Basically just take the object's velocity, and Physics.gravity and Time.fixedDeltaTime and simulate what the trajectory will be for each upcoming physics frame in a for loop
(works best if it has no drag)
and use raycasts along that trajectory to check for collision
Thanks! I'll try to give that a spin.
Hey sorry. Quick clarification - you saying just look several frames ahead in a fixed update method? So something like:
Velocity*gravity*time.fixedDeltaTime*numberofframesahead
I'm saying keep track of the position and velocity as you iteratively simulate each future physics frame in a for loop
For as many frames as you're willing to look ahead
Ahhhhhh okay. So increment in a for loop time.fixedDeltaTime by something like 1
Ah, nvm. time.fixedDeltaTime is THE frame physics interval set in the project. Okay, got it.
I'm having this weird bug,
my ragdoll always flies up whenever it gets activated, but only when the timeScale is less than 1, when the timeScale is 1 it acts normally (or at least it seems to act normally), what could be the problem here?
timescale shouldn't affect physics at all really, other than speeding up or slowing down how fast it is simulated
are you perhaps doing physics things in Update?
I'm sure I'm not. I do use add force after the ragdoll when the ragdoll activated, but even when I remove the AddForce, it keep flying up (only when timeScale is < 1)
You got additional colliders that collide with ragdolls?
Just the floor, but it's outside below the ragdoll when it's activated
Wait, it seems that it flies up when ragdoll activated after certain animation
Does your character collider get disabled when ragdoll is active?
Hey guys, I really appreciate the help that I've found here so far today. So I used @timid dove 's suggestion to calculate a projected position based on the velocity of my car object - and I THINK it's working. The deal is, now I want to turn the car an additional amount to what it is currently turning to follow the spline walker (yellow arrow). What I've been doing to get it to turn towards the spline walker is - take the InverseTransformPoint of the walker, and then divide the x value of that position by the magnitude to get the amount the car should steer (the value is a clamp between -1 and 1, with the first turning the wheels completely left and the latter turning them completely right). While that logic does work, I want to figured out the difference between the projected position, and the ideal position as indicated by the red marker here, and add that to the steering value. I would think that subtracting the ideal marker's position from the projected one's (light blue) would do the trick, using an InverseTransformVector function relative to the vehicle. However, I can't say this is working as expected. Plus, I ONLY want to do this if the angle is excessively wide. Would anyone be willing to give their two cents here on what I'm figuring out? Sorry if I'm overthinking things here.
Ah there it is, it seems that I added a sphere collider at runtime to the root, I'm not sure what was that for 
~~After I disabled the sphere it works fine ~~
Thanks
Nope, I think the problem still remains
To understand the problem better, here are the comparison between with and without slowmo
Without slowmo
And with slowmo
I could simply reset the rigidbodies velocity to 0, but I need to know when to reset it. But it would be better to know what causing it to fly off so I can fix it.
maybe put OnCollisionEnter on a script and print out what you're colliding with.
Maybe it's some errant collision causing it
I ended up by setting Rigidbody.maxDepenetrationVelocity to 0. It seems that the rigidbodies inside the ragdoll are colliding with each other, and timeScale seems to magnify the 'separation' velocity.
I tried multiplying the maxDepenetrationVelocity by timescale but it still flies up..
Thanks for the help
The physics joints will have a setting that determines whether the connected bodies can collide with each other
maybe that would be helpful?
Do you mean the Enable Collision flag? Yep, I've tried both checked and unchecked, and it still fly away.
Setting Rigidbody.maxDepenetrationVelocity to 0 works with a trade of that the collider 'might' sink a little into the ground, but I dont think it will be noticable (if it happens at all)
Anyone know why my rigidbody 2d cylinder likes to stick onto walls?
Because of friction
And how do i remove it?
You can make slippery materials by creating a Physics Material asset, changing the friction to 0, and applying that asset to the collider on your wall.
I cant put it into the box colliders materia
Ok
Can I get cloth to work with DOTS physics
Hi everyone! I have an issue with colliders intersecting. I've checked everything including the contact offset. I am attaching a screenshot of what is happening. Thanks in advance.
The game is for the Ludum Dare game jam.
@stuck bay Nope, their not triggers.
Anyone got any pointers for my 2 solutions for implementing whenever a "loot location" has been found? I'm currently using a circle 2d collider that extends outside the screen resolution as what I call my "View", which will scan the surroundings for loot. (it follows the player)
-
Use a very simple gameobject with a collider and some LootData (position, loottype etc) on it so it is detected with collision by the view, and the prefab for the loot can be pooled to the location
-
Let the Update() function look for the position of the LootData in a list of all the spawn locations and check if they're inside the view. However, since this will happen with each player, and going through all the LootData on the map I thought that I could divide the map into different chunks that the player searches for the positions in the current chunk instead.
Not sure which of these methods are the most efficient, since I am unsure of the performance different between using Physics2d to detect collision VS searching the positions in a list in a chunked area each frame
Any tips and tricks are appreciated
Physics will be more efficient
Unity's physics engines use a quite efficient algorithm to divide the space of the world such that only a small area of it is being tested for collisions by your collider at a time.
in effect you are getting that "chunking" behavior for free
Ah sweet, I'll do that then, thanks!
Is there any easy way to make meshes deformable through physics interactions? I want to something akin to making a cube of gelatin that deforms to a certain extent when something pushes into it
not with stock physics
you need softbodies for that
well, one can still fake the effect at some extent but that's another topic
either way, not going to be easy
Do you know of any good unity assets for softbody physics that can be used with skinned meshes? Seems like there are not many choices, especially if you limit your search to recent stuff:
https://assetstore.unity.com/packages/tools/utilities/uflex-59843
https://assetstore.unity.com/packages/tools/animation/vertexmotion-23930
Get the Obi Softbody package from Virtual Method and speed up your game development process. Find this & other Physics options on the Unity Asset Store.
Use the uFlex from Dr Korzen on your next project. Find this utility tool & more on the Unity Asset Store.
that second one is limited in what platforms you can target :
- NVidia GPU with at least CUDA 3.0 compute capability
- Windows 64 bit (Win 32bit experimental, Android and Linux support planned)
does anyone know why a charactercontroller isnt actually moving?
im using the Move() function and when i do CharacterController.velocity it shows that it indeed does have a velocity
but its not actually moving
EDIT: the reason was because the char controller was on a child object
Can someone help me make my formulas physics and stuff better in Unity?
DM me if yes
Just ask your questions. #854851968446365696 describes how to ask a good question
My camera is shaking around and my car goes weird....
Idk anything more than that
Hi guys i need help About vehicle physics in unity i am new in this server where i should ask?
What your question is?
I want to learn how can i make vehicle controllers in unity i am struggling from weeks to get a good Tutorial or course that can teach but i cannot find anything even close to that i am looking for
I have some decent understanding of programming but i cannot code it myself because i have never worked on something like vehicle physics before
I can show u how I did it.... When I get out of school
Thanks i will msg u in persony
Peesonal*
Hey! I'm trying to get the count of particles from a particle system within a specific collider... Any points on how to do this? ParticleSystem.ParticleCount only shows the total amount in a scene
Just found this: https://docs.unity3d.com/Manual/PartSysTriggersModule.html
Hello folks, having a issue with the simplest chain of ConfigurableJoints deforming in a strange manner. Any idea?
Solver iterations makes it sound like you're using IK. Are you using IK, or are you using physics joints?
It's only basic configurable joints, capsule colliders and rigid bodies, nothing else
And by solver iterations, I mean the physic engine iteration count in the project settings
Is this the right channel to ask about marching cubes?
does anyone have a solution for a character controller not being grounded when walking down a slope?
Are you doing something like calling Move multiple times per frame?
Any reason why a Physics.Raycast() will not a ProBuilder object if the object's transform has a rotation applied? I'm rotating the object around the Y axis, and raycasts aren't hitting it for some reason. (Specifically this seems only to be a problem when the object's Y-rotation is 90 . . . between 0 to 89 degrees the Raycast hits) . . . one more quick update . . . it seems to only happen at Y rotation values of "90" and "270"
. . . probably related to the Mesh collider on the object. I replaced it with a box collider and it works as expected now. So much still to learn.
could be something wrong with the geometry of your mesh
most likely because the colliders overlap one each other
Hello, I am having problems with addforce and hinges. When I apply a force (not torque) to a rigidbody object that also has a hinge it rotates child the hinge in a wacky way.
Currently I am applying a force to the knee and to the toes to get them to try and follow the IK (the green debug boxes). when I apply the force to the knee the limb below the knee moves more than it should.
This is with just the force added to the knee
@tiny ospreyobi is probably best out of those options... also if you want flex, nvidia has free integration for it too but it's kinda abandoned
in addition bullet physics can also do softbodies
oh, nvidia took all their content out of asset store
well, their free flex integration is gone then
but yeah it was very limited for platform side