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)
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!
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Earthquake : MonoBehaviour
{
[SerializeField] private List<Rigidbody> m_AffectedGameObjects = new List<Rigidbody>();
[SerializeField] private float m_EarthquakeForce;
public List<Rigidbody> AffectedObjects { get { return m_AffectedGameObjects; } }
private Vector3 m_LastPosition;
public void AddAffectedObject(Rigidbody _Body)
{
m_AffectedGameObjects.Add(_Body);
}
public void MoveEarthquake(Vector3 _Target)
{
// Stores the last position before moving to the target position.
m_LastPosition = transform.position;
transform.position = _Target;
// Triggers the earthquake.
TriggerEarthquake();
}
private void UpdateEarthquake()
{
// the direction towards where the earthquake plane is moving.
Vector3 _lastDirection = (transform.position - m_LastPosition).normalized;
foreach(Rigidbody _body in m_AffectedGameObjects)
{
// Add force in the direction of the earthquake movement.
_body.AddForce(_lastDirection * m_EarthquakeForce, ForceMode.Impulse);
}
}
}
1 Like
UrEGirlVipere.
Thank you!!!
It worked.
Thanks!!!
1 Like