Skip to content

Instantly share code, notes, and snippets.

@graylan0
Created August 11, 2023 13:33
Show Gist options
  • Select an option

  • Save graylan0/6866098f033a4f35a77fb30acd41c614 to your computer and use it in GitHub Desktop.

Select an option

Save graylan0/6866098f033a4f35a77fb30acd41c614 to your computer and use it in GitHub Desktop.
ok we tried that but it still slideback a
ChatGPT
I'm sorry to hear that the issue persists. Let's dig deeper and explore some more advanced solutions. Since the standard approach of adjusting the physics material didn't work, there might be other factors at play.
1. Check Collider Alignment
Make sure that the colliders are aligned properly and that there are no gaps or misalignments that might cause unexpected sliding.
2. Analyze the Forces
If there are any forces being applied to the rigid body (e.g., through scripts), they might be causing the sliding. Check for any scripts that might be applying forces and adjust them accordingly.
3. Custom Friction Script
If the standard physics material is not providing the desired friction, you can write a custom script to simulate friction. Here's an example:
csharp
Copy code
[RequireComponent(typeof(Rigidbody))]
public class CustomFriction : MonoBehaviour
{
public float frictionCoefficient = 0.8f;
private Rigidbody rb;
private void Start()
{
rb = GetComponent<Rigidbody>();
}
private void FixedUpdate()
{
Vector3 velocity = rb.velocity;
Vector3 frictionForce = -velocity * frictionCoefficient;
rb.AddForce(frictionForce, ForceMode.Acceleration);
}
}
Attach this script to the object, and you can adjust the frictionCoefficient to control the friction.
4. Check for Interfering Components
Sometimes other components, like Character Controllers or custom physics scripts, might interfere with the rigid body physics. Make sure there are no conflicting components or scripts.
5. Adjust Physics Settings
You can also try adjusting the global physics settings:
Go to "Edit" > "Project Settings" > "Physics."
Experiment with the "Bounce Threshold" and "Default Contact Offset" settings.
6. Consider Constraints
If the object is sliding in a direction where it shouldn't be moving at all, you might want to consider using constraints on the rigid body. You can freeze the position or rotation along specific axes to prevent unwanted movement.
7. Debugging
Use debugging techniques to understand what's happening:
Use Debug.Log to print values like velocity, forces, etc., to the console.
Use Debug.DrawRay to visualize forces and directions in the Scene view
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment