Hi all,
I am a beginner. I want to use UNITY to simulate friction. But when the object falls on a moving object, it will stop and not move together. Refer to some articles to add physical materials to objects. But it still failed. How to make it work.
Thx!
The usually happens because the moving object isn’t being moved via the physics API.
For things like moving platforms, the platform should be a kinematic rigidbody, and moved through the rigidbody API, such as with methods like Rigidbody.MovePosition
.
The moving platform is using a script to move. Also, I enabled the “Is Kinematic” and “disabled the Use Gravity”
But are you moving it via the rigidbody API? Can you post the component’s code?
spiney199:
Rigidbody.MovePosition
Here is the code for the base
using UnityEngine;
public class BaseController : MonoBehaviour
{
public float speed = 2f;
public float distance = 2f;
private Vector3 startPosition;
void Start()
{
startPosition = transform.position;
}
void Update()
{
float xMovement = Mathf.PingPong(Time.time * speed, distance);
transform.position = startPosition + new Vector3(xMovement, 0, 0);
}
}
So you’re moving via the transform directly. This bypasses physics.
You need to move the platform via its rigidbody, as mentioned multiples times.
Don’t post in random threads trying to get people to help with your unrelated problem.
Could you please teach me more about it?
What kind of friction do you want to simulate? What are the details of what you want to do? Maybe I can help you after this!
All you need to do is set the position via the Rigidbody, and not directly:
public class MovingPlatformExample : MonoBehaviour
{
[SerializeField]
private RigidBody _rigidbody; // reference via inspector
public float speed = 2f;
public float distance = 2f;
private Vector3 startPosition;
void Start()
{
startPosition = transform.position;
}
void Update()
{
float xMovement = Mathf.PingPong(Time.time * speed, distance);
_rigidbody.MovePosition(startPosition + new Vector3(xMovement, 0, 0));
}
}
Thanks spiney199 . it is moving now.
zulo3d
October 1, 2024, 4:35am
13
Be sure to move the platform from within FixedUpdate and enable interpolation on the rigidbody.
1 Like