Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Friction between objects

Discussion in 'Physics' started by kumao23, May 17, 2022.

  1. kumao23

    kumao23

    Joined:
    Jan 19, 2015
    Posts:
    11
    Sorry!
    I know this is very rudimentary and very simple, but I'm stumped....
    I tried to reproduce an earthquake by placing the cubes on top of each other on a moving floor, but there is no friction between the cubes in terms of left/right movement and they slide.
    The floor is Kinematic with rigid body and no gravity, the cubes are rigid body and the friction of the physics material are both set to 1, Maximum.
    Collision detection for all objects is continuous and dynamic.
    I think I have all possible settings, but it slides beautifully.

    The video was created again for posting and I tried to run it manually.
    I looked on the net and found only scripts to make the player a child as a way to prevent it from slipping, but I couldn't find anything about such a basic issue.
    I am truly embarrassed and would appreciate your help.
    Translated with www.DeepL.com/Translator (free version)
     
  2. o888Roses

    o888Roses

    Joined:
    Nov 27, 2019
    Posts:
    10
    I wrote a simple script for an earthquake. How to use it:
    You can invoke the earthquake by moving it with the
    MoveEarthquake(Vector3 _Target)
    method. You can add an affected game object with the method
    AddAffectedObject(Rigidbody _Body)
    . Have fun!

    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. using UnityEngine;
    6.  
    7. public class Earthquake : MonoBehaviour
    8. {
    9.     [SerializeField] private List<Rigidbody> m_AffectedGameObjects = new List<Rigidbody>();
    10.     [SerializeField] private float m_EarthquakeForce;
    11.  
    12.     public List<Rigidbody> AffectedObjects { get { return m_AffectedGameObjects; } }
    13.  
    14.     private Vector3 m_LastPosition;
    15.  
    16.     public void AddAffectedObject(Rigidbody _Body)
    17.     {
    18.         m_AffectedGameObjects.Add(_Body);
    19.     }
    20.  
    21.     public void MoveEarthquake(Vector3 _Target)
    22.     {
    23.         // Stores the last position before moving to the target position.
    24.         m_LastPosition = transform.position;
    25.         transform.position = _Target;
    26.  
    27.         // Triggers the earthquake.
    28.         TriggerEarthquake();
    29.     }
    30.  
    31.     private void UpdateEarthquake()
    32.     {
    33.         // the direction towards where the earthquake plane is moving.
    34.         Vector3 _lastDirection = (transform.position - m_LastPosition).normalized;
    35.  
    36.         foreach(Rigidbody _body in m_AffectedGameObjects)
    37.         {
    38.             // Add force in the direction of the earthquake movement.
    39.             _body.AddForce(_lastDirection * m_EarthquakeForce, ForceMode.Impulse);
    40.         }
    41.     }
    42. }
     
    tmonestudio likes this.
  3. kumao23

    kumao23

    Joined:
    Jan 19, 2015
    Posts:
    11
    UrEGirlVipere.
    Thank you!!!
    It worked.
    Thanks!!!
     
    o888Roses likes this.