#⚛️┃physics
1 messages · Page 62 of 1
it really fuck me up that a simple issue as that is making me reconsider my 7 years of unity devs
Yeah I read that Adri2, and its a bit too above my paygrade.
and the fact that I know what it is coming from is really infuriating
I got about 8 years of unity experience, and about 6 months with physics ugggh
The problem you posted 😄
oh
@stuck bay just watched ur clip. looks physically accurate to me ❤️
well I know why does this occurs, I just can't solve it
that heart really blows a fuse in my brain lmao
you mean unity scale related?
it's 1, 1, 1
if you spawn a default capsule next to it, is it about the same?
so I assume it is?
I'll see that
I assume he is 2,2meterish?
okay maybe a bit more
maybe a bit 3x 😛
yeah 😆
surprised laddy isn't blue and rockin a tail.
anyway, whats the collider setup on the character?
Thanks again guys, and good luck, imma get going!
is that a threat? 😛
lmao if you think my d is too... okay I'll stop there ah ah
no seriously look
Filesize: 3.04 MB | Uploaded: 28/01/2021 21:54:35 | Downloads: 10
trying to eject some shells from my gun, and give them some rotation when they instantiate, but i can't seem to get them to rotate very fast at all
if I use my slowmotion addon, it works fine
@half narwhal there is a default "Maximum angular velocity"
rb.angularVelocity = new Vector3(0f, 800 * Mathf.PI, 0);
with this code they only rotate a few times a second
so my guess is that the physic doesn't have time to process all that mess, what are your thought?
@half narwhal
cool
what AngryArugula said
thanks!
I edited the link, might be better!
@stuck bay if you decrease your Time.timeScale and Time.fixedTimeStep stay proportional, you will inevitably end up with more steps per second.
that's what I understood, thought I want my player not to be forced to use the slowmotion addon
but I feel like I'd have to
yea so OnCollision just drop your FixedTimeStep to a very, very small number
if you dont want to do slowmotion
you might also have to set Maximum Fixed TimeStep
to prevent it from just charging ahead
but wouldn't that act as a "lag"? when you modify the fixedTimeStep you also have to change the time scale now don't you?
ah so the other way around create those "lags"?
so if your timeScale is 1, and your fixedTimeStep is 0.01, you get 100 steps per second
if your timeScale is 0.1, and your fixedTimeStep is 0.01
you get 10 steps per second
oooh that makes sense!
similarly, you can also set your Rigidbody's mode to Interpolated, instead of "None"
that only effects the Transform, not the Rigidbody
well.. I'm too tired to keep coding right now so I'll have to do that tomorrow! may I ping you tomorrow then?
mmmmh, okay I can try that quickly
if your physics sim explodes, Interpolated wont help you
it sjust to smooth out hitches/framerate differences between physics and display
60hz vs 50hz waves (Update and FixedUpdate defaults)
aaah alright!
okay I'll give it a shot tomorrow, I'd love to try and do the fixedTimeStep right now, but it would interfere with my current workflow, and I don't wanna mess it all up! well thanks!
and sure; ping whenever 🙂
great! 😋
I'll show you the end result tomorrow then! Have a good night, or good day depending on where you are!
as it is detecting the input
@distant coyote Dude marry me! I was struggling for 2 days straight with that issue and lowering the Time.fixedDeltaTime definetly fixed my issue!! thank you soooo much!
Hey, so I have started making a procedural spider myself using unity and everything is done, except the rotating the body based on the height differences of the legs
I kinda don't get the math i guess and have been struggling to get this for a few days now. Could someone please explain me how can I achieve the rotation of the body based on terrain irregularities that effect its IK Legs?? i have referred this video https://www.youtube.com/watch?v=e6Gjhr1IP6w
I tried to explain procedural animation in 10 steps.
Check out my twitter: https://twitter.com/CodeerDev
@thick jetty Don't cross-post
@frigid pier ??
@thick jetty it happens that I followed this tutorial myself, you should normally not have an issue with the rotation of your body since the legs move back to the transform you assigned when there is too much difference between this transform and the tip of the leg, could you please show a video of your issue?
@stuck bay Don't tag people out of conversation.
How did he cross post?
You do know how search feature works?
In the most recent messages he didn't cross post, so not relevant
Also how time stamps work
Yes I do but look my previous message
Cross-posting is when person posts the same message in multiple channels. Now stop clogging up the channel with this, if you have questions to a moderator about the server use DMs.
Okay I see you are having a bad day let's leave it here alright.
!mute 362993911255400448 1h
Adri2#5277 was muted
hy guys i have a question, i have applied inverse kinematics to my spider so i can move the leg to the target
but how would i find the next point where i have to place the leg?
I tried to explain procedural animation in 10 steps.
Check out my twitter: https://twitter.com/CodeerDev
using this tutorial
hey guys im working on a project with a mech that can turn around the turret so the turret and the base can be rotated independently, my problem is that when im shooting is shooting right but as soon as im turning around with the base of the mach it starts to shoot for the base directon aswell,
so basicly it shoots the direction where the mech base is looking, how can i sole the problem ? any idea?
can some one help me please?
Hey everyone I wondered if there was a possible way to avoid this problem while rotating a character instantly ^^'
well hum, he is kinda stuck inside the wall
He clips through the colliders and I'd like to avoid that
(Only when I rotate him)
is it a Rigidbody2d?
yup
How are you moving the bullet? Is it a transform.forward ?
Can I still use that even tho I want to rotate him instantly ?
yes
?
this method is to make him rotate at a certain speed
but I can't make him go to a specified angle
I did
Rotates the Rigidbody to angle (given in degrees).
that's all it does
no speed involved
you just give it an angle
it iwll collide with stuff as it rotates - are you trying to avoid that?
I just didn't see it there mb
this is the bullet script
Quick noob question
I have a player with rigidbody and box collider and a trigger object with box collider, but the trigger is still solid?
Might be worth mentioning that the trigger is child of an object with rigidbody, would that inherit?
Hi, guys, I have this OverlapSphere call and I was wondering if I can somehow configure the radius visually through the inspector. For example, sphere colliders can be visually edited in the inspector, is there a chance for me to edit a radius used for OverlapSphere from the inspector?
did some one answered to you question?
Nope
i can give answer @sour bone
Krisztian already answered for me in a private message, because he couldn't post the answer here for some reason.
Can't you just paste it here?
no dm pls
Okay, dm me then.
<@&502884371011731486> Is it a normal practice to give help and code over DMs? Sounds weird.
Yes, if you both agree on the conversation. But it's not the purpose of the server. Others are learning on public answers.
is it possible to apply -currentForce from a joint in order to nullify it?
ive tried doing it in FixedUpdate using AddForceAtPosition but its behaving weirdly
One simple way to burn down momentum smoothly is to multiply velocity by a fraction like .01f (and assign it back) until it is close to zero.
that wont do it for me
i need to get rid of the joint force and add my own force immediately
hey i'm using transform.translate for running and rigidbody physics for grapple hook swinging
but they seem to be conflicting
if I run after swinging it seems like it saves the physics up until I'm done transform.translating and then does it all at once
I never mess with rigidbodies and transforms at the same time. Not sure that's a good idea.
you could eventually add to the rb.velocity
when I said I had a really physics based game and asked if I should implement run with rigidbody a bunch of people told me to use transform.translate lol
or try with rigidbody.moveposition
i'll do that
Maybe they meant to use your own physics system and dont trust physX, a lot of people hate it
I reckon it can be hard to tweak sometimes
ok that's not working either
now the player doesn't run, but sometimes teleports when you hit the run button
is there a way to cancel rigidbody motion?
like if my player starts walking just tell the rb to stop all motion
should be done inside FixedUpdate()
Try to set rb.velocity to vector3.zero
or multiply it by a fraction of itself to "brake", like *= 0.1f maybe 🤷♂️ try some things, see how it behaves
I never tried AoT gameplay, sounds fun 👍
I'll post a link to my website once I get an alpha version up and running
new problem tho
now I need to be able to tell when I'm swinging and when I'm standing on something
I tried using oncollisionenter, but that applies when I hit the sides of walls too
you could watch some platformers tutorials, get ideas how they handle isGrounded state and such
Hello, I have a question. As collisions can only take place if there is a rigidbody attached. How come that my wheels go through the object? There is a rigidbody attached, and a collider
and its still passing through objects
Truly baffling,
what is the collision mode set to?
@median rampart you can possibly try and understand the source code of the grappling here https://github.com/AoTTG-2/AoTTG-2
@unique oak
Is the car is moving really fast, in which case the collision detection is not fast enough¿ (use continuous)
Or, did you move the car by updating the transform of the object¿ (Use rigidbody forces)
https://streamable.com/tiv14o How would i go about making this more performance? Each cube has a RB set to kinematic, and i make it not kinematic on raycast contact (from gun)
I don't know how to make it more performant. would adding a RB to the objects on Contact be better?
@fiery cedar
Er. Perhaps GPU instancing for those same colored blocks?
Seems like a lot of the performance hit was rendering since it occured right as you looked in that direction.
@leaden jay Unfortunately, the material on the cubes are greyed out, They're auto generated
I don;t know how to access them to turn that on
I don't know how i can see why rendering is taking a massive chunk
Does anyone here use the VR Interaction Framework and can assist me with a hinge?
I have this hinge, and no matter what I do, it only opens a little and then slams shut
hi
Has anyone else had problems with the hinge joint? Its incredibly unresponsive and I really cant figure out the issue. It will move very slowly when the game starts, and will rarely respond to the player touching it (which sends it flying)
It seems unity can't solve OnTriggerEnter if the trigger object is created later?
The capsule colliders attached to my CharacterController components will often get stuck on one another. How do I avoid this?
put them on the same layer, then disable collisions between that layer in project settings.
I would like if they still collided, but they are currently very sticky, if that makes sense. The capsule colliders don't slide against one another, for example, so if one falls into another it just stands perfectly upright on top instead of sliding off.
In a similar vein, they will hang onto ledges by just the very edge of the capsule collider, like someone holding up their own weight with only their toes
Well - CharacterControllers aren't "real" physics
if you want more realistic physics, use a Rigidbody
And be cognizant of PhysicMaterials on your colliders
that's what determines friction and bounciness of everything
Ahh, good point. I haven't dabbled in physics materials at all, I'll look into that. I'll also give some thought to using rigidbodies but all my NPCs and code currently use CharacterControllers because I have my own code for more arcadey movement that uses the CharacterController.Move function
Often I use composite colliders to achieve this as well. IE: the Ground collider has a moderate friction, but the Walls/Bumping collider has no friction at all.
so you end up with somethin that looks like this
why collisions work so bad in my game
i get knocked out
for 10 meters
with huge force
whenever i step on item
is it because theres custom gravity applied to the item with AddForce?
and it influences the player when he steps on it
if yes, then is there a way to make that force work only as gravity and not push other objects? (eg not push player)
physx uses force to move everything. That means when there is a collision it will use the physics materials to apply the correct amount of force. Sometimes this gets out of hand with large forces. Especially when something is moved into a collision without force.
How do i stop pick ups from pushing player? I have 3d object drop onto ground and when player is close they fly at the player and when collide they pick up but when the collide they push player (I don't want that) if i make collider a trigger it falls though the floor 😦 idk how to fix
you can use collision layers (project settings) to ensure it collides with the ground and not the player. then you can use a simple raycast or overlap to determine when it hit the player
Does anyone know if particle colliders are precise enough to use for game logic? Right now I raycast and emit a fast moving particle with collision quality set to high, I'm wondering I can safely consolidate this and not have to worry about the particle collision not registering
So when I zoom in on two objects I have colliding, I notice their colliders arent seperated by somewhere around 1/6th a unit. Whats the max distance they can be apart and still collide?
@naive gorge configured in project settings
@split lily if you're moving objects fast enough that you're concerned about missing collisions, use raycast.
Thanks!
@distant coyote Thank you so much!
👍
Anyone know why when I instantiate a shattered object it blows up? I'm not adding force to it, but if I add it to the scene as a normal object it crumbles as I'd expect when I hit play.
ALl the different pieces are probably colliding with each other and being pushed away by each other
not sure why that would be different with Instantiate vs having it in the scene at the start
Yeah, I thought that too, but the prefab working properly when I just put it into a scene made me think that its not a collider thing.
I posted on the Unity forums with some video/code, hoping someone can see whats going on. 😄
Followed Brackeys shatter tutorial and didn't get the same results, definitely weird.
Maybe try disabling the colliders and instantiating it like that?
Just to see if it's a collider thing
if they still explode it's not a collider thing
I've tried setting them to kinematic and after I instantiate the prefab setting then back off, still blows up.
Will give that a shot.
The other possibility is maybe that if it's in the scene at the start, the rigidbodies are asleep at the start?
I haven't tried the entire collider on each shard yet.
Yeah
Just tried with disabled colliders, I instantiate them, then loop and re-enable all colliders and it still blows up. lol
One possibility to consider is maybe turn this sequence into an animation with https://docs.unity3d.com/2018.3/Documentation/ScriptReference/Animations.GameObjectRecorder.html
but I'm not sure how dynamic you need things to be
that will make the object break the same way every time and you won't be able to interact with the pieces
but maybe that's OK for your use case
Just trying to setup a rock in game that when a player mines it, it shatters and just crumbles to the ground. Wouldn't have thought it would be this complicated, but always something!
Two more options to look at:
- have the "shattered" rock be a child of the actual rock, but disabled. When the actual rock is destroyed, enable the shattered rock and hide the real one. Maybe that will work since technically it is in the scene at the start rathre than being instantiated?
- assign PhysicMaterials to the colliders on the shards with low or zero bounciness
The shattered pieces have no bounciness, and dynamic and static friction of 0.1, so they slide pretty well by default. I'll try the child one, thats not a bad idea, then I get around the instantiation explosion.
Think I found it, and it doesn't make sense but whatever.
So I'm destroying the rock, then instantiating a new prefab shattered rock at the same position and rotation.
Apparently the collider for the original rock is still there for a frame, so the new rock collides and blows up.
So I just disabled the collider on the original rock, then destroy it, then instantiate the new one and it works fine. Talk about weird frame timing.
Or if I call the shatter in update instead of fixedupdate I don't have to disable the collider.
Ah! nice. Yeah the problem is that when you call Destroy, the object doesn't actually get destroyed for real until the end of the frame
It kinda just gets "scheduled" for destruction
Just to confirm, unity is "mostly" deterministic on other hardware right? So my networked rigidbodies should stay in sync for a good while on all clients assuming no packet loss?
I don't think there are any guarantees of that
Floating point calculations are notoriously performed at different levels of precision on different hardware. That would be the point of the "syncing" bit - to reign in error over time.
Today I learned: Unity's Rigidbody2d.AddTorque is in Radians. Angular velocity is in degrees. I'm like WTF is this factor of 57.29578, but it turns out that's just the conversion ratio between degrees and radians.
Unrelated question: Is there any difference between using force mode force of x versus using force mode impulse of x times delta time?
I thought that they might only be semantically different, but actually it looks like Impulse might be overriding any left over forces that could've been applied. https://forum.unity.com/threads/difference-between-forcemode2d-force-and-forcemode2d-impulse.649858/#post-4356277
Weird physics question here. I have a model I made in Maya. It has a box collider and rigidbody. and when I go into play mode it falls through the floor. It's on the same layer as the floor and both layers are set to collide. It's not kinematic.
If I start the object at an angle, it will fall to the floor and lay there. If I then pick it up and drop it again from a flat angle, it will fall through the floor again.
These things don't happen on other similar objects.
Both the object and the floor are very thin and you're doing no interpolation, so it might be just skipping it entirely in a single frame. That would also explain why it collides when it's not straight.
Recommendation: Thicken the floor! If that's not feasible, you'll probably need to turn on interpolation.
I turned on interpolation and I get the same result.
I have a small ball and a large box.
Both of them are rigidbodies.
Whenever the ball lands on the box, it goes through.
Is there a collision detection mode thing going on?
@sly violet I turned interpolation on AND thickened the floor. It no longer goes through the floor, but it goes through furniture and literally anything else
and i mean...the furniture is not really "thin"
I also made the object's collider a little bigger
Collider is twice the thickness of the object, still goes through the furntiure
Try Collision detection to "continuous" ?
I can do that, but that's going to really hurt performance since I have multiple of these objects and I'm building for VR.
that's also why I don't want to make the object's collider much bigger, or it will be noticeable to the player
yeah your memory card is not really supposed to move that much anyway I guess
...I don't know why I wrote interpolate when I meant continuous up above....
How many objects are we talking?
maybe 7 or 8 at at time
That shouldn't be a problem even on a low power device.
@halcyon cipher When you export from your 3d program, are you used to click some kind of reset transform and normals and such ? maybe normals are inside out ?
Also did you try asking in #🔀┃art-asset-workflow ? maybe people there are used to that problem
oh nvm is a box collider from unity
Yes, I disabled the colliders that exported with the object.
that box collider is so tiny though 🤔
transform.up = Vector3.Lerp(transform.up, gravityUp, rotationSpeed * Time.fixedDeltaTime);
I am using this function of Vector3 and I am wondering if there is a way of doing this without affecting the local Y rotation of the transform? I am quite new to Unity so any help would be appreciated
@halcyon cipher box collider with 1 unit scale each axis falls through the floor too ?
(jsut to test)
No, no other objects have this issue
alright maybe the size then. Sorry never used objects that small, I think I can't help
These guys are .1 units, and do just fine
🤷♂️ I'll let someone else help you
mass related?
mass isn't making much of a difference
Tried putting the box collider on the parent. No difference
try making an entirely new collider of the same size and shape
@vernal spindle Just did that. It fell through my 1-unit-thick floor
narrowed it down a bit I guess
oop wait
added rigidbody but not collider. derp. 2 secs
ok. similarly-sized brand-new collider has the same behavior 1-unit-thick floor stops it, but .5-unit-thick table does not
check manual, it will explain better than me
not particularly
OK, found the issue! Looks like mesh collider on the table in question wasn't working well. Replaced it with a compound box collider and everything is fine
(if anyone encounters this again, increase your Substep count until it stops)
Heh. That'll work, but I use it as a last resort, because usually there's another less expensive way to do it.
Yeah, MeshColliders without convex set to true are not volumetric and therefore super thin and prone to having things step through them. (And if you do set convex to true, well, it'll be convex, which won't necessarily play nice with your geometry.)
Thanks, Fogsight, that's helpful.
@sly violet the only difference between Impulse and VelocityChange is that the former respects mass
they both have a cumulative effect on velocity
Generally yea, but increasing substeps lets you figure out if thats what you want at all.
additionally unless you have several hundred dynamic objects rolling around at the same time, 12-20 substeps is fine
(even on mid-range modern smartphones)
i have a 2d rigid character and he bugs into tiles when touching them from the side
how can i fix this
its only if force is applied. So while walking into it from the side the player bugs
Hi guys, i'm using this code to prevent player rigidbody to slide when WASD isn't being held; the problem is that it just works in one direction (when player rotation is 0 0 0), when i try to face in another direction and move my character just gets yeeted out of existence
How can i move a rigidbody using add force without acceleration
void FixedUpdate()
{
Vector3 Move = Vector3.forward * Input.GetAxisRaw("Vertical") + Vector3.right * Input.GetAxisRaw("Horizontal");
Physics.gravity = Vector3.up * Gravity;
float ModifiedMoveSpeed = Acceleration;
if (new Vector2(RB.velocity.x, RB.velocity.z).magnitude >= MoveSpeed)
RB.AddForce(new Vector3(RB.velocity.x, 0, RB.velocity.z));
if (new Vector2(RB.velocity.x, RB.velocity.z).magnitude > 0 && Move.magnitude < 0.01f)
CC.material = Friction;
else
CC.material = NoFriction;
RB.AddForce(Move * ModifiedMoveSpeed, ForceMode.Acceleration);
}
i tried setting modified speed to 0 when the player is moving too fast but that then i cannot change movement directions when im already traveling in one direction at full speed
see this . i have lag if i go in wall . why ?
maybe the collider isnt right sizes
My problem is not that my character enters the shrine of the wall or ... My problem is the jump that happens when I hit the wall. For example . Suppose we go to the wall with the D button. This jump happens if our character hits the wall and we still hold the D button. Of course, I think this problem will be solved if I do something that disables the motion code when it hits the wall. :)
But if there is any other way but to use the code, tell me. Thankful :)
I have raycast collision problem.
I changed my character controller to use raycast instead of force to stick to ground. This proved to be better at really huge distances from world center (eg 40000 meters) some of you may know that your game physics and other factors start to break after 10000meters+/- mark. due to floating point error precision.
so raycast solves that issue very well (at least with movement and sticking player to planet)
but in return it messes upp all my collisions completely (i **think ** raycast is the culprit, but dont know for sure)
for example it pushes objects when i dont want it to
or it gets pushed by them very far
what would you guys do?
Very little in this question makes sense to me:
- CharacterControllers don't use force in the first place.
- Raycasts are just a query about the physics scene. Raycasts cannot "stick" anything to anything
- Again, raycasts are just a query, so I'm not sure what you mean by it pushing objects
ALso raycast suffers the same problems far away from the origin that everything else does. You should really look into floating origin systems if you have a world that is more than ~1000 meters square
i mean sticking to raycasthit.point does better job than addforce
far from world center
by sticking i mean eg rigidbody.moveposition
Wait so you're using both CharacterController and Rigidbody on your character?
im not using controller i just called my script that
oh
ok that confused me a lot
yeah if oyu MovePosition your Rigidbody to the raycast hit point, it's going to immediately cause a collision
and the physics engine is going to try to remedy that with more forces
maybe MovePosition to a position slightly offset from the raycast hit point?
like ray.GetPoint(hit.distance - .01f)
it will still cause collision if it hits anything
also im pushing objects that are set to isKinematic
🤔 those shouldn't be affected by forces at all
im using MoveRigidbody
oh oh
is it bad?
whats fine
I thought oyu meant you bumped into a kinematic object and the kinematic object moved
i mean if MoveRigidbody casues this issue
i walked into it
with MovRigidbody
and it moved
the thing you walked into is not kinemetic right?
it is kinematic
🤔
kinematic objects aren't supposed to move unless you explicitly move them with MovePosition
something is weird
rigidbody.rotation = rotationStep;
rigidbody.velocity += (planet.velocity - rigidbody.velocity).normalized * Time.fixedDeltaTime;
rigidbody.MovePosition(positionStep);
thats my movement script
it's unusual to both set velocity and use MovePosition
usually you do one or the other
also unusual to multiply the velocity by Time.fixedDeltaTime
why
because velocity is already expressed as "units per second"
and makes the object move at a uniform, framerate-independent speed
but it makes things smooth
multiplying by Time.fixedDeltaTime just makes your velocity a lot smaller
it does not. It's basically equivalent to doing this:
rigidbody.velocity += (planet.velocity - rigidbody.velocity).normalized * .02f;
the time multipleir thing
but yeah setting the velocity means it will move automatically again after the movePosition happens
because... it now has velocity
the physics engine automatically moves objects that have velocity
(unless this object is kinematic)
ok ok
but i still can push
kinematic
things
btw do you add time fixed delta time multiplication to MovePosition?
definitely not
MovePosition takes a position as its input parameter
If you scale that position... well your object is not going to go where you want it to go
I have a question regarding Raycast collision detection.
I'm following along with a tutorial, and it uses Raycast to detect a collision with a tagged object, but I can't get it to work without toggling "Is Trigger" on the object, at which point it falls through the floor. I feel like I am missing something fundamental, can anyone offer some insight?
🤔 That shouldn't make a difference. If anything, sometimes raycasts don't hit triggers
In order for the raycast to work you just need the following:
- An activated GameObject with an enabled Collider
- That gameobject should not be on the
IgnoreRaycastlayer - That gmaeobject's layer should be included in the LayerMask you used with the raycast (if you used a mask)
- The ray needs to physically intersect the collider
Game object is active, set to 'Default' layer, collider is enabled, and I haven't started using masks yet
ok it should work then. Next step is debugging
first, why do you think it's not working?
I honestly can't figure out why, it works when "Is Trigger" is ticked, but then the object falls through the floor
gotcha - what I mean is
been googling for the better part of an hour
why do you say it's not working
what isn't happening
that you are expecting to happen
Ok what does your code look like?
hmm, not sure how to show it
Ok so first thing to do would be to put a line Debug.Log("Hello!"); right after the raycast
just to make sure your code is actually running
You could also log the actual hit distance and the tag of the hit object:
Debug.Log($"Distance: {hit.distance} tag: {hit.collider.tag}");
(by the way are you getting any errors in your console?
Wasn't the debugs, was the detect distance, my scale must be different from the tutorial
but it works now, thank you for your help
if im using raycasts for player collisions for a player controller script, should physics sit inside fixedupdate? i have both input & collision detection in update right now (no rigidbodies)
Do your raycasts in Update()
i do
so I guess I misunderstood the question
should physics sit inside fixedupdate?
You mean AddForce and such ? yes in FixedUpdate. Everything else can go in Update
No rigidbodies at all, all custom physics
there isn't necessarily a right answer to this. If you run your game logic (including physics) in Update, how your game behaves will depend on the framerate the player is running it at. Multiplying things by deltaTime ensures that objects move at a roughly constant speed, but does not mean the game behaves identically at different framerates.
Having all your logic in a fixed timestep ensures that your game will run the same regardless of the framerate. This is especially necessary for networked games
Gotcha, thanks for the details!
may i ask if unity uses the left or the right handed rule for things like joint.current.torque?
im not sure if im phrasing the question correctly
Hi all,
Is there a way to get all collisions in a scene? (instead of handling every individual collision in OnCollisionEnter, etc callbacks) As I understand it the physics engine calculates all collisions, and then calls these callbacks. Is there a way to get them at that stage?
I'm following an ECS approach for some things in my game through DOTS/entities but I'm trying to avoid the actual dots phsyics/rendering stuff as it's not stable yet. So I do want to process all collisions in one batch, but I don't want to rely on DOTS/physics.
From what I've googled it doesn't really seem possible with the regular phsyics engine? That would kind of surprise me.
@void snow if I'm reading your question right, it sounds like what you're looking for is something like Physics.Overlap<collider type>?
No, not exactly. I'm (currently) not interested in adding custom collision detection logic, in which case Physics.Overlap... would of course be handy. I'll try to rephrase: Currently the physics system works by taking all colliders/rigidbodies in the scene, doing some work to detect collisions, and then for each collision it will call certain callback methods (event handlers) on the game object scripts (OnCollisionEnter and friends). I'm interested in all detected collisions (the step right before the event handlers are called) so I can process them in batch (let's say in a 'data oriented way') instead of handling every collision in separate event handlers (let's say an 'object oriented way').
It is not clear to me, however, if it is even possible to get a hold of all collisions at once. Possibly this is not even exposed by the physics system? I know that DOTS/physics does enable this but I'm not comfortable switching to such experimental tech right now.
yeah that sounds like something that's not exposed to you, unfortunately.
hopefully someone who's more familiar with unity's physics system can help a bit more!
Alright, thanks. It really would be too bad if it isn't :(.
You want to avoid having to put MonoBehaviours on your colliders to capture the collision events?
Only way to do that is putting a script on a common rigidbody parent of the colliders(which means they're the same physical entity) or switching to ECS I think
Hey Guys
Need Help on how to do this
I want to get the position of where two objects moving towards each other at different speed will meet.
hey this is that classic math problem with the trains
The speed of the 2 trains are 50 mph and 70 mph and coming towards each other. So over all they cover 70+50=120 miles in a hour . In order to meet/crash 300 miles they will require 300/120=2.5 hours.
Thanks @timid dove
There's a formula in that quora answer you should be able to apply
so I guess to Simplify it is
meetingPoint = (speed1 * distanceFromEachOther) / (speed1 + speed2)
Hi guys. Sorry for spamming this question but I really need to understand this.
How do circle collidors work in Unity? Are they just simple formulas that check the distance against every other collidor on the same layer in the scene? Or does Unity implement some form of optimised function that ignores collidors that are very far away?
Sorry again 😓
They use an optimized data structure involving AABB's (axis aligned bounding boxes) so they only need to check colliders that are nearby each other against each other
is there a way to make an object go up slowly almost as if it was in slow motion
Why is my character sticking to the moving platform some times
im using a trigger collider and setting the parent of the player to the platform
@edgy aurora As was mentioned don't cross-post in other channels to redirect. If your question doesn't get attention you may want to consider adding more information meanwhile.
You have to examine what's happening, experiment. If the object is physics enabled, then parenting does nothing to the simulation unless it was deactivated by setting it to kinematic. Default materials also have some friction.
does anyone know anything about composite colliders
are you asking how they work, or something specific about them?
any collider that is a child of a game object with a rigidbody is treated as part of that rigidbody's collision
thats it?
wow thats very useful
but does it need to have a collider tho?
or does it just do the outline?
bcs i need like an outline
collider
not sure what you mean by "outline"
like i have a randomly generated dungeon
and i want to add collision
but cant
because its random
if you are trying to add collision to static objects, you do not need rigidbodies
no i dont have a problem with that
but there is corridors
wahtever you're randomly spawning
it can block the way for the corridors
corridors have walls
why would it block the way? You don't generate random colldiers
you generate random walls right
using a script
you have some prefabs of map pieces which you place together randomly right?
nope just rooms and corridors
right
so
on those prefabs
put colliders
that make sense
that's all there is to it
u dont understand
I don't
mhmm
why
you don't put collider on the doorway
if you have a room
with 4 walls
and a doorway
you use 5 colliders
3 for the full walls
2 for the wall with a doorway
and a gap in the doorway
🤷♂️
thats the problem
i dont have a seperate prefab for each type of room
i just have 1 room prefab
ok
and a corrridor one
how does it do doorways
ok now I'm confused
like the one in sould knight
how does a corridor go into a room
or the game that dani made in 2 days
there is randomly generated rooms
that are connected using corridors
if there are certain places in the room that can randomly have a corridor attached, you just put box colliders on each of those in the room prefab, and if a corridor is there, you destroy or disable that collider in your script.
right ok so
4 colliders
one for each wall
and if a corridor is there
you just disable or destroy the one on that wall
in the map generation script
im trying to do that rn
maybe i shouldnt have gone for a confusing design
should have done the one in binding of isaac
it's not a confusing design, looks ok
Like Praetor said, you just need to disable a collider when you know where your corridors attach themselves to the room
can be only 4 possible values: left, right, top, bottom
you prob handle that visually too
like you carve a hole in the wall
Or replace if it's easier for you to imagine
I have a ragdoll. I want it to follow the mouse around, but flail around a bit as you pull it. I tried using rigidbody.movePosition, and a fixed join attached to an object following the mouse. (attached to the root) Both of them the ragdoll just falls down instead of staying where the mouse is. It does follow left/right.
Removing gravity helped, but the position still isn't 1:1 with the mouse.
@hot edge are you able to visualize the fixed joint (sphere mesh or something) to ensure it is over the mouse cursor?
I put on a sphere. It's matching the mouse position. It seems like the ragdoll just can't move fast enough to keep up, and if I move too fast the body pulls apart until it slows down again.
I feel like I had this working like six years ago, and can't remember the secret.
Part of the problem was the anchor wasn't lined up with the root. But now that they're lined up it causes insane spinning.
I'm going to try making a build to show how crazy it looks and for a fun record of the bug.
Well it says it built correctly, but I can't get it to load. https://developer.cloud.unity3d.com/share/share.html?shareId=b1IoTz9hsU
Device Detection
oh, fun...
if you're just looking to capture footage of the error, you can use OBS with the editor
Does anyone by any chance know how to edit the physics of an individual tile on a tilemap? I have tried using the Custom Physics Shape on the sprite sheet, but that hasn't seemed to change anything. I am trying to edit the physics collider of these walls so you stop at the actual wall.
also, uploading to something like this will allow videos to embed in discord: https://gfycat.com/upload
yea looks like it might be having trouble satisfying the constraint of the fixed joint at the same time as satisfying the joints of the ragdoll. Try it with just a single rigidbody as the "ragdoll"
They think it violates the ToS
Yeah, it's the two fighting. Damn. I swear I had this working perfectly years ago.
If I try moving the root directly with moveposition 1.) it spins like crazy 2.) The limbs don't respond at all to the movement.
being logged in will avoid the ToS flag.
Are you mostly looking for this kind of behaviour? Use a config joint for your hook, lock position, and then enable projection on all joints (the hook and the ragdoll) to prevent it from jittering a bunch) https://gfycat.com/calculatingwideeyedclam
That looks perfect, yes.
note that I am just moving it in the editor, so you should be able to achieve the same
(moving the transform in editor is the same as setting transform.position)
My ragdoll just won't move like that, if it goes above a certain speed it disconnects. It's almost like the parts have a high drag on them or their max speed is limited. They don't stick together like yours does.
Is that using the ragdoll wizard/character joints?
Also, thanks for all the help. I appreciate it.
by disconnects, you mean breaks apart permanently? Or they all stretch apart briefly?
Stretch apart. They move very slowly too, they don't move as fluidly as yours.
and yea, using character joints
is Projection enabled on each joint? That will keep them together
you could also increase the mass of the ragdoll, I tend to use a fairly heavy ragdoll to keep it more stable
(total mass on the one above is 8)
I did the default, total mass 20
So maybe it's too high.
I tired with 8 and 200 and neither helped. So weird.
are you moving the transfrom via the editor, as my example above?
I just tried that, with the head, and even that doesn't work for me at all. It's actually worse.
hmm
It went flying off like it was being pulled by the body away from where I was holding it.
I just don't get why the rest of the body is moving so slowly.
I'd recommend trying to isolate the problem, build a 2-joint system, see if it works, etc. In case there is something off with your specific setup
if i use colliders on character as HitBoxes (only for damage detection), do i still need to put rigidbody on character object for optimisation? Or this tutorial is no longer relevant? https://learn.unity.com/tutorial/physics-best-practices
Has anyone used the GGphys asset on asset store for physics I have some questions
I'm trying to build a system that instantiates gameobjects at random raycast locations. I got that bit working, but now I'm trying to adjust it so that if an object instantiates within the collision of another object, it will try to move itself to a new location until it finds one where it isn't colliding with anything. I can't seem to get the collision bit to work though
This is the code I'm using so far, is this the correct usage of intersect and .bounds or have I made a mistake? https://gyazo.com/a9983ae04854de5b0bda3c92e64c7531
Hello guys, I have two rectangles (p1 and p2) of the same size. There is a point on p1, and I'd like to retrieve the relative position of this point on p2
Here is an explanation
do these rectangles have transforms?
they do
and are xi, yi, zi expressed in local space of the rectangle or world space?
local space
but you want the world space versions of x0, y0, z0?
or local space?
if it's local, you don't have to do anything
for world space you do p2.transform.TransformPoint(in)
if you have in expressed in world space, then it would be Vector3 out = p2.transform.TransformPoint(p1.transform.InverseTransformPoint(in));
it looks great, thanks
👍
I manually set my angular velocity to 1,0,0 on start, but if it is on ground, it decreases to 0.285, without any drag. why would that be?
@wicked imp I am not sure if that angvelocity is big enough but unity will limit angular velocities on all rigidbodies by default settings
try setting the ang velocity to 0.2, 0, 0 and see if it changes like that imo
@viral ginkgo isn't the limit for angular velocity is 7 by default?
also that happens only when landed
I set use gravity to false and let it fly on the air, angular velocity is as it should be, 1
but when it touches the ground, it goes back to .285
weird thing is that if I pull it up, and let it fall once more
it stays 0.285 still
yes it is a sphere
with zero friction, ball doesn't move though
I need it to move too
Can please someone help me out. I have a game where player falling down and need to avoid obstacles which is flying up. For some reason sometimes OnCollisionEnter just not being called despite the fact that collision did happened in the game.
Is it normal behaviour?
I already tried to change collision detection, collider types, rb kinematic and non-kinematic. Same thing each time. Sometimes OnCollisionEnter just not being called
My player is a ragdoll and he is flying by force of gravity. And obstacle flying by rb.moveposition but I already tried transform and velocity
Hi, when raycasting, do I need a rigidbody or box collider or something else ?
It looks like my object is ignored by the raycast
@solemn beacon maybe raycast is hitting backfaces
or you are mixing up 3d and 2d physics
It only needs a Collider
How can I fix this issue? The Rigidbody2Des jump upwards and flip around. I have no idea why.
I belive you have discovered the classic Physics overlap problem
When two rigidbocies occupy the same space, the physics engine tends to "shoot" it out of it
Can I fix it somehow?
Im hazarding a guess, when a sphere "rotates" into another colliders space, it causes the issue
Hmm...
I am spawning the boxes really quick in an Update loop when the player holds down their mouse. Can they overlap each other when I instantiate them?
It looks like when they rotate at rest "falling off another cube" or "slide down" rotation causes a gitter
Are you using Change Position/Rotation or Velocity for moving the cubes?
No. I am just creating a box that falls down because of physics and collides with each other.
There is nothing on the box prefab except a Transform, SpriteRenderer, Rigidbody2D and BoxCollider2D.
Well, a quick fix might be going into your project settings and increasing the contact offset or Contacts Generations
Or trying a different Detection mode on your rigid body
If it is because they spawn on top of each other, you can do a Physics.Overlap check to make sure you arent spawning on top of something else
Im sure what happens to the physics engine if they spawn on top of another object 🤔
So I have some code that teleports the player to a ball he shoots but if it teleports near another object it sometimes pushes that object inside of a wall like this: https://i.softwarelocker.net/file/softwarelocker/QT1F2W.mp4
Any ideas how I could prevent that?
Okay I fixed the clipping using MovePosition instead of directly setting the position but now this happens: https://i.softwarelocker.net/file/softwarelocker/EDkuu9.mp4
It just throws you like crazy
And it still goes into the wall sometimes too
if input is read in update, and movement is applied in fixedupdate, is it possible to avoid a few frames of reading input but not applying force?
i have an issue with the ignore collisions
the first collision is not ignored but the rest are
MovePosition effectively uses forces to move you
and you will collide with things between you and your target
Okay, then how would I teleport to a position without pushing other objects inside the wall?
you'd have to resolve that conflict somehow
do an OverlapBox or something
find everything in the place where you are going to teleport to
and... move it somewhere?
Basically you're letting the physics engine answer the quetion right now of where to move the thing
right
and it's deciding to put it in the wall, because that's the closes place probably
Well I want the toaster to be moved away, instead of the props
make the prop kinematic maybe?
at least for a few frames
while the toaster is teleporting
I tried setting it to kinematic at all times and iirc it didn't help
I'll try again real quick
ok good
oh huh that just freezes them in the spot
okay so you're saying i change an objects that are in an OverlayBox to kinematic before I teleport and then back to dynamic after I tp there?
tp back?
oh
well like...
after the physics engine gets a change to knock your toaster away
then change it back
hm okay
not sure how to figure that part out exactly
well I still want them to react to the toaster
maybe wait 1 physics update, or some number of seconds?
otherwise you can't interact with the props at all, no?
well I'm not entirely sure how your game works
but you said you wanted the toaster to get knocked away instead of the prop
the toaster keeps the velocity of the ball
yeah I meant if its in a corner
I just don't want the bottle to get pushed into the wall, but in general they should be pushed around
I'll give what you said a try though
right
ok yeah it's kind of a tough problem
the physics engine doesn't like teleporting obejcts 😄
hmm
you could maybe do the overlaybox and try to find a clear direction for the prop to go in that isn't blocked by a wall with raycasts or boxcasts?
and then move the props right before teleporting the toaster?
something like that 🤔
that sounds really hacky and hard lol
yeah i know haha
I wonder if the answers here might help your situation too
I don't really see how this relates to my issue though, the crazy toaster shooting issue I already fixed by increasing the mass a bunch
It's talking about objects getting stuck in walls
apparently the getting stuck part is related to friction?
ah hm
well the object isn't really stuck per-say, it just kinda clips through and then it goes inside of the collision box
how can i prevent my 2d rigidbody player from bugging in collision tiles?
If force is added against the tiles by the player it happens.
How do you code the ball in 3d ping pong to add force in the direction it got reflected in, so it gains speed and doesnt slow down
if it reflected downwards, how do you add additional force downwards
and how do you check how it is moving
Hey guys, I have a point (startingPoint) on a rectangle (portal), and I want to translate this point at a distance (minDistance) from this rectangle
Here is an explanation
I tried the following Vector3 newPoint = portal.transform.TransformPoint(portal.transform.InverseTransformPoint(startingPoint) + new Vector3(0, 0, direction.normalized.z * minDistance));
Calculate its reflected angle just like you do for light off a mirror in this example and apply a force going in that direction, at a high level https://math.stackexchange.com/questions/1844/how-to-calculate-reflected-light-angle
With ignore collision 2d, the first collision doesn't get ignored but everything else does, anyone else have this issue?
I'm trying to move my character through a sphere collider that has is trigger enabled but I can't pass through it, what am I doing wrong? I thought you are supposed to be able to pass through triggers
Did you remove the mesh renderer + mesh?
Happy hunting!
not sure if this is the right section but:
I have a ring of fences (86 seperate meshes) that i've combined into a single mesh, would it be better for performance to use the 86 simple box colliders or use a single mesh collider instead now it's all combined?
From my experience there is no considerable difference. As long as the mesh colliders are static.
@tender gulch thanks, yeah everything with a mesh collider is static, this should cut down on my object count considerably, i'll have primitive collider versions for throwing about if I need to use Physics
I've done some tests. I have a huge city map that was made of separate objects. Most of them were using box colliders. I merged the meshes into bigger chunks and used mesh colliders for them. I used profiler analyzer on data before and after the merge and the mean and median difference of Physics.Process was less than 0.01 ms which might as well be a statistical error. I assume it's due to the count of collider reducing more than 10 times. While mesh colliders are heavier than primitive, if you exchange 10 to 1 apparently there isn't much difference.
I dont think you could desern any performance drops until you are in the thousands of objects territory
If you do have thousands of objects, you want to combine, but not over combine such that object culling gets a hit
Id keep the combined meshes smaller than 100 meters by 100 meters
this is always a balancing act heh
Hey everyone, I'm trying to get smooth surfaces across my level because my character bumps up and down if there is not an edge collider over where my floor is supposed to be (I believe this is due to the player character having a circle collider instead of a box). I am working on a tilemap for the level, and I have added 3 multiple edge collider components when there is a break in the ground. Does anyone know of a possible alternative to this? It seems inefficient to keep track of a bunch of edge collider components in my level tilemap.
how can I make my rigidbody stop quicker, when force isnt being applied?
allright, i will try it
in general, to accelerate a rigidbody, you need to add force
accelerating means speeding up and slowing down
drag simulates a force being added opposite and proportional to the object's current velocity
alright
btw for more context, i am using add force, and i am moving a car left and right
and I wanted the car to switch directions quicker
then more force is needed
F = ma
force = mass * acceleration
acceleration = force / mass
since you aren't changing the mass
you must increase the force
you could check if the direciton you are adding force in is opposing the direction of motion
and increase the force then
thank you
So my friend is playing my game, and sometimes randomly, the rigid body stops on the plane that it is moving on. Why does it do this
Anyone know if you use sphere colliders on a character it will prevent animations from clipping? like if I had a sphere collider on the hand and animated the hand to move towards the face it wouldn't go through the face
Im having issue when applying rigidbody component to object disables its collisions with raycasts
using mesh colliders / renderes
Object collided with is "null" its unable to call the render component of object it collides with
if (Input.GetMouseButton(0) && cooldown == 0 && mag > 0)
{
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
Debug.DrawLine(firePoint.transform.position, Camera.main.transform.forward * 50000000, Color.red);
RaycastHit hit;
muzzleFlash.Play();
mag--;
updateAmmo();
if (Physics.Raycast(ray.origin, ray.direction, out hit))
{
var objectHit = hit.transform.GetComponent<Renderer>();
Debug.Log(objectHit);
if (objectHit != null && objectHit.tag == "enemy")
{
StartCoroutine(enableMarker());
hit.transform.parent.gameObject.GetComponent<zombieHealth>().takeDamage(damage * hit.transform.gameObject.GetComponent<multiplier>().multi);
}
}
}
my rigidbody controller is really messy and its really glitchy
Problem 1: Doesnt move in the direction of the camera
Problem 2: Wobbles back and forth when pressing a or d
Problem 3: Stops moving randomly
I think you have to show the code so that we can figure out what is wrong
Hey guys - when I attempt to add a "Physics Material" (there may be a 2d version but I'm a little lost if I'm honest) to a GameObject's Rigidbody2D but I continuously just get the crossed circle saying I can't. If there's anything I can provide more information with then please let me know! This is what the Rigidbody2d looks like:
Try clicking the circle to the right and see which options you have
I simply get "None", even if I add a 2nd straight into the "Assets" folder (though this could be the wrong place). Dragging is ineffective too. I'm not sure if I need to enable something or not, I'm struggling to find others struggling 😛
So I don't have the option to create a "Physics Material 2D" - I believe this to be the source of my issues. Do I need to have an option from somewhere or an Asset of some form loaded that I probably don't already?
Is the 2d component asking for physics material 2d?
Even inside the 2d tab?
Nope (if this is what you mean?) Using 2021.1.0b5.1871 beta
No, near the top of the create menu in your first picture
That sucks. I am usually stuck on some bug in two hours before I realize I haven’t attached the script to a game object or something stupid like that
Works a dream though - thank you ❤️
Is there a way to make particles individually destroy themselves when they hit a specific target but bounce off a different object?
I'm new to unity, so here's a basic question: I'm making a billiards game and I'm trying to align the balls without them overlapping or being uneven. How would you go about this? I have managed to get them aligned by making a rudimentary triangle, but I don't know how to save their positions after that to use in the game without manually spawning, shaking, and despawning the triangle.
yo, im trying to use Physics.OverlapSphere, but it wont detect nearby enemies. Heres the code:
EnemyList = Physics.OverlapSphere(transform.position, 400, Enemy);
testText.text = EnemyList.ToString();
even when enemies are on screen, the text displays an empty array
anyone else run into this issue?
the third parameter is the layer mask for enemy objects
to clarify, the enemies do have circle collider 2d attached to them
This statement does work with 2d colliders right?
No Physics only works with 3d physics. You want to use Physics2D for 2d.
so then would Physics2D.OverlapSphere be used instead?
Yeah, although I'm not sure there's such a method. Sphere is a 3d object after all.
just checked the API
I'd check the docs for what methods are available in Physics2D.
there an Overlap circle
Then you can use that.
got it, thanks dlich
anyone got a good script for detecting if an object is being clicked on in a 2D environment? Ive been going through scripts ive found online and none of them seem to work well
You can use OnMouseDown or https://docs.unity3d.com/ScriptReference/Physics2D.GetRayIntersection.html
Both of those options require that the object has a collider2D
yeah, thats what ive been messing around with
ive managed to use it to get a solution that works for what im needing it for
I'm making a bomberman game where the player can place a bomb at it's feet and walk away but can't walk over it afterwards.
Right now the player can go oob by using the push force of the bomb collider (I assume that's the reason).
It would be best if there was no force (for the player) until the player moves out of the bomb collider, but just not being able to go oob would be acceptable too.
The character, house and bomb all have a box collider without physics material.
The collider of the bomb and house are exactly adjacent.
The character has a rigid body with gravity off, interpolar none and Rotation and y position frozen.
I turned the global gravity y force off because all movement is on the x and z axis.
I would greatly appreciate it if anyone could help or push me in the right direction!
is it grid-based ? Enable collider only when player leaves the tile ?
or I mean make it a trigger and act upon triggerExit ?
or yeah always trigger and prevent Enter (do nothing special on exit)
The player movement is not. Bombs are always placed in a grid though.
That I didn't think of that
thx!
But if I remember correctly, I won't get trigger events if the object spawns within my trigger
yeah right
plus, the "prevent from entering the collider" part could be tricky if player has free movement
(trigger, not collider)
I was thinking of giving the bomb and player a trigger collider.
Then disabling the player collider when placing the bomb and enabling it on exit. but I think I won't get the Exit event.
Wait, the player could still walk into the house then. nvm
yeah bad idea to disable player collider ^^
agreed
do I understand correctly that the force that pushes things out of a collider is the same force that keeps things from moving into it?
Yeah probs because of that
You could instantiate bomb in front of the player ?
but it's different from your spec "where the player can place a bomb at it's feet"
🤔
Normally bomberman games put the bomb directly at the player
it feels better that way
A distance check above a threshold to enable the collider after the player gets far enough might be easier....
but you'll get a sphere shape, not a box
You're welcome, happy coding 👍
Hello
I am having a slight problem
I am using a character controller, and I want it to react to physics
More specifically, I want it to go up and down slopes
Whats happening is, it just flies instead of going down the slope
Can anyone help me
This is what I've done in the Rigidbody component
How do you expect it to follow the ground when gravity is disabled?
Although, it seems to be kinematic, so I guess you move it manually..?
What do you mean by "manually?"
Sorry, I'm a beginner.
I mean that you don't use physics for the object to move.
Yes
I dont
I mean, I use a character controller
not a rigidbody controller
So I dont think I do
The thing is, this works in my other game
how are you moving your character?
Well, I followed Brackeys tutorial
Code! Do you have it? 😄
I got the raw axis of the x and z axis
Sure
Share it.
This good enough?
Hello?
Sorry for disturbing you
I just started learning unity
So im a noob
😄
You're not applying anything that looks like gravity.
Then you've missed something.
but in THIS game, IDK why, but ive looked back and forth, I cant go down slopes
At least in the code you shared, it won't go up or down. Only horizontally.
and that's why you can't go down the slopes
You're supposed to be able to answer that question, not me. 😅
True
lol
Well, I'll look into it
Well then, for the meantime, how do I detect if I am not on ground and move it on the Y axis until it touches the ground?
Wait
Nvr mind
If your character moves on y axis it means that something is moving it on y axis. Whether it's the physics system or your code.
IK
Then you know what to look for in your other game.
i want that if i walk to the object it should spin a bit and then fall (like in real life) but nothing happens , i m an FPS capsule
I've yet to see objects that spin and fall when you approach them in real life...
clearly you lack the power of Psychokinesis
@dawn spire have you written any code which facilitates this behaviour ?
That must be the problem ><
nope there are no scripts attached to those objects , only rigidbody component
and collider
well then, you would be needing to write some sort of code to do the same
oh!
Hi, I have a question about physicsScene.simulate. I am trying to draw the simulated trajectory of a grenade using a separate physicsScene but it is getting completely different results depending on what value I use for the step value in the simulate function.
I am applying the same force to the grenade in both the main scene and the physics scene but I cannot get it to match up.
Putting a lower value in the simulate step (i.e. 0.01f) seems to reduce the amount of force being applied to the grenade.
The red line is the main scene trajectory. The purple is the simulated using 0.01f steps. I am rendering the purple line using a line renderer with 100 points with the 0.01f time increments.
This is the same scene with the simulate step changed to 0.02f in code... The trajectory looks like more force is being applied to the simulated object.
Mmm I think I figured it out. I am now using Time.fixedDeltaTime for the simulation step and it (mostly) matches now. I didn't expect the differences to be so great between different step timings. On the separate physics scene it doesn't look like the physics are entirely deterministic either, I am still getting some jitter when bouncing off walls for some reason.
Also I figured the idea to predict grenade trajectories using a multi physics scene doesn't seem worth it for performance reasons. Calling 150 simulations (equating to 3 seconds of simulation at fixedDeltaTime) on the physics scene containing the grenade + a handful of environment wall rigidbodies absolutely tanks the framerate. It is going from 200+fps to around 20fps.
Does anyone have any good ideas on how to simulate these trajectories in a performant real-time manner?
yeah physX is not deterministic
you could do your own parabola equation, would cost less 🤷♂️
Yeah I was thinking this would be the way forwards but I would lose out on the ability to show things like the grenade arc bouncing off walls and other objects.
I actually posted this problem in the unity forums now with the code I am using, the exact thing I am trying to replicate here is how Gears of War does it's projectile aiming:
https://forum.unity.com/threads/simulating-grenade-throwing-trajectories-using-multi-scene-physics.1057832/
@old karma I have written some posts about drawing trajectories, along with a repo: https://forum.unity.com/threads/how-to-calculate-force-needed-to-jump-towards-target-point.372288/
Anyone know how to make better jumping using Rigidbody? My character sort of floats back down. Have tried finding solutions but haven't come across any
try increasing the mass on your gameobject, a feather (low mass) will float down, an anvil (high mass) will accelerate a lot harder
I have tried that but it doesn't have an effect at all on it
Decreasing drag speeds it up a tiny bit but mass seems to not change anything in game
is your gravity scale set correctly?
I wasn't sure whether a setting like that may be messed up. How would I check?
if you dont like the default physics behaviour, simply increase the gravity scale of your way down
if its at 1 thats okay
*on your way down
Where are the gravity settings sorry?
under the rigidbody component
Oh might not exist on the normal one, I'm used to the 2D one, in that case yeah increase mass over time till you land
Hmmm
In my project settings it says the y value of gravity is - 9.8
No idea if that's where it should be
thats fine, its the same as earth
in 2d bodies there is a gravity scale, appearantly not in 3d bodies, so when you are coming down from the jump either progressively add mass or progressively add a downwards force until the jump feels right
yeah, I've tried adding a force down, it's just quite hard however low I put the multiplier, and just haven't set it up yet so that it doesn't effect the character walking down a slope
Do you think you should use velocity changes or add force for jumping?
really depends on the feel you're going for, i'd say experiment with both, personally i often use add force
its by trying out different things you sometimes stumble on something unexpectedly fun
Yeah that's true
Do you know a good way of finding when the player is at the peak of their jump?
I've been trying to use when the velocity.y goes starts to go below 0
but still having troubles
using the inflection point of velocity.y to 0 works for finding the peak of the jump
note that many games use a much higher gravity for characters, since 9.8 can feel unnaturally slow. We use 25 in our game
Inflection point of velocity.y? What's that? (Sorry stupid newbie questions, haven't done this stuff for quite a while)
as in, the frame velocity.y transitions from a positive number to a negative will be where the peak of the jump occurs
How would I work where that is out in C#?
also, note that mass does not affect the speed an object falls https://www.youtube.com/watch?v=KDp1tiUsZw8
Courtesy: NASA - Galileo and Apollo 15
At the end of the last Apollo 15 moon walk, Commander David Scott (pictured above) performed a live demonstration for the television cameras. He held out a geologic hammer and a feather and dropped them at the same time. Because they were essentially in a vacuum, there was no air resistance and the feather ...
That's what I suppose I was trying to do when seeing whether velocity.y was below 0
are you trying to play an animation or something at the peak?
No, just literally trying to find where the peak of a jump is, so I can add downwards force to speed up the falling part of the jump
as currently character is falling quite slow
ahh
to the point where they're gliding
cranking up gravity might get you the effect. But you could just check if velocity.y < 0, add a force each frame. So downwards gravity would become much stronger
if you just do a huge force add the moment the peak is hit, it may look jarring
void Jump()
{
if (Physics.Raycast(transform.position, Vector3.down, jumpRayDistance))
{
if (Input.GetKeyDown("space"))
{
RB.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
}
} else
{
if (RB.velocity.y < 0f)
{
RB.AddForce(Vector3.down, ForceMode.Impulse);
}
}
}
}
Something like this?
The player falls down quite hard and violently with that
you want ForceMode.Force
Impulse is for forces that are added once
like an explosion
np
Okay that's working a bit better now thank you. I think that's given me a good basis, just needs details tweaked about it
Thank you again
Now when I try build the game, the falling force doesn't take effect. Just works like it used to without the fall part? I've saved compiled everything obviously
check to make sure the build isn't failing. There can be differences between editor and builds, but it's very unlikely in this case
it's possible it is failing and you are playing on an older build
Build completed with a result of 'Succeeded' in 9 seconds (8536 ms)
Comes out in the console when I do it
make sure the build you are running is indeed up to date
Yeapp I am. Just edited the script that contains the updated falling code to do something really visually obvious when I press "e" and that works. Just the falling part of the script isnt
Btw anyone got any advice on fixedupdate and multiplying by deltaTime. I was using Update() for my WASD controls and Jump, all of which use add forces and multiplying by Time.deltaTime which I've read you shouldn't do? Changing it FixedUpdate() and without the Time.deltaTime. What should I use for forces?
Okay so I've got it working in the build version now. Jump needed to be in FixedUpdate()
Hello! I'm having unfavorable results on my coin pusher physics. If anyone would like to help me out (i literally started using unity for 3d last night) I would LOVE the @ or a DM
I am currently live on twitch while i work on it, so you can see it, but I'm also ok to do screen sharing or whatever through discord.