- Home /
Is it ok to use Linear Drag and/or Mass to make an object immovable?
I have a top-down character that I move using transform. The character has a rigitbody and a collider in order to check for collision (walls, other entities, etc).
My problem is that other entities in the scene that are moved by force, if they collide with my character they "transfer" some of that force to my character resulting into an "endless" drifting towards some direction.
Now for this to happen the character has a mass of 1 and a linear drag of 0. If I change the linear drag to say 10 and maybe have a slightly higher mass at 2 or 3 the character does not travel as far, actaully it travels just a few pixels almost barely noticable.
The problem when the mass is 1 and linear drag is 0 (it's an atempt of mine to add knockback): Gif of the issue: https://gfycat.com/gifs/detail/MajesticHeavenlyKiskadee
My question is, if I give even higher values to those resulting into an immovable object, is it a good way of handling it? I feel like there is something wrong with this approach and there are better ones. One workaround that I'm thinking of right now is remove any form of force from the game and move everything with transform instead in hopes that this wont cause that issue, but on the other hand it wont feel as nice anymore.
Am I missing something here? The character's rigitbody is set to dynamic, the entities that use forces also have a rigitbody set to dynamic and a collider attached to them.
Answer by jonnydredd · May 20, 2018 at 06:37 AM
Sorry I'm not more helpful, this is something that I've not come across. If you just make your player really heavy, the force will still applied, and so after many collisions he might still start sliding again.
One thing I might try is making the main character Kinematic on the rigid body.
The problem with $$anonymous$$inmeatic is that it doesn't collide with static objects (like walls etc). I did find a different solution (not sure if it's a good one or not) where you keep the Dynamic body but ins$$anonymous$$d you freeze all constraints. This makes the character imovable by forces.
Answer by Harinezumi · May 20, 2018 at 06:58 PM
Try moving the character using Rigidbody.MovePosition()
, that way it will check for collisions. I think it also should be kinematic, but now that you mention that it doesn't check collision with static colliders, I'm not sure. Either way, setting Rigidbody.velocity
to Vector3.zero
after each move could help (it will practically be kinematic that way).
Your answer
Follow this Question
Related Questions
Making a bubble level (not a game but work tool) 1 Answer
Issues with Character Controller moving Enemies 1 Answer
How to go about having two seperate Game Objects follow eachother? 1 Answer
Rotate a 2D Rigidbody to a desired angle using AddTorque? 3 Answers
How to make a rigid body move along a specific path using my mouse? 1 Answer