Why doesn't a cube move when resting on a rotating cylinder?
I have a dozen or so cylinders that each rotate using the transform.rotate to simulate rolling, and then a cube drops on top of them but the cube doesn't move in the direction of the rolling cylinders.
The cylinders are kinematic, so they stay in place and gravity isn't applied. Both the cube and rollers have rigid bodies.
I've come to understand moving via transform tends to negate physics, so I tried to apply torque to the rollers in order to get them moving but following the code in the API nothing spins.
Anybody know what may be going on? I have a cheater script that detects if the cube is on a platform and applies force to simulate a set of rollers, but i'm looking for a more realistic solution. If only one corver of the cube is touching, I want just the corner to move and not the entire cube as the cheater script causes to happen.
I tried the code here link texthttps://unity3d.com/learn/tutorials/topics/physics/adding-physics-torque but if i got it working I only need the cylinder to roll in place.
Both objects need colliders and a physics material assigned to the collider. Then you should get the behavior you want.
I believe they both have colliders but not sure about a physics material. I'll check that when I get home.
One of the objects didn't have the material assigned to the collider, but doing that didn't make a difference on things when I use Transform.rotate in order to rotate the cylinders. I updated below with the code using addTorque.
Don't make the cylinders kinematic. Ins$$anonymous$$d use constraints in the Rigidbody component and lock their position and all axis except the one they're rotating around.
Answer by Animus428 · Nov 09, 2016 at 05:12 PM
Sorry, to clarfiy - Even if I got the addtorque to work, what I need is for the cynlinders to roll in place (i.e. rotate on the X axis) and not move. Their rotation needs to cause the cube that lands on them to move according to their rotation though; just like a conveyor belt.
using UnityEngine;
using System.Collections;
public class RollerScript : MonoBehaviour {
public float speed;
// Use this for initialization
void Start () {
speed = 50.0f;
}
void wake(){
}
// Update is called once per frame
void Update () {
//transform.Rotate(Vector3.up, speed * Time.deltaTime);
float h = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
float v = Input.GetAxis("Vertical") * speed * Time.deltaTime;
GetComponent<Rigidbody>().AddTorque(transform.up * h);
GetComponent<Rigidbody>().AddTorque(transform.right * v);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612100353im_/https://answers.unity.com/themes/thub/images/avi.jpg)