Moving conveyorbelt
Hi, Noob here with a question about conveyorbelts. I searched and found a really nice solution (so far). I hacked the code a bit so I can activate/deactivate my conveyorbelt with a keypress;
using UnityEngine;
using System.Collections;
public class ConveyorBelt : MonoBehaviour {
public float speed = 2.0f;
public float distanceTravelled = 0f;
void FixedUpdate()
{
if (Input.GetKey(KeyCode.X)){
Rigidbody rigidbody = GetComponent<Rigidbody> ();
rigidbody.position -= transform.forward * speed * Time.deltaTime;
rigidbody.MovePosition (rigidbody.position + transform.forward * speed * Time.deltaTime);
distanceTravelled += speed * Time.deltaTime;
}
}
}
now, I made a box, with a boxcollider and a (kinematic) rigidbody, attached the script and it works great when the conveyorbelt is at a fixed position in my scene, i place some rigidbodies on it and they move nice 'n smooth... but... i'd like to attach it to my vehicle, so i can slide those rigidbodies off it whenever I need to.... The problem is that the rigidbodies don't 'stick' to my conveyorbelt when i start moving around. I hope my description is clear, and if someone could give me a hint on how to approach this.
cheers! Mike
Answer by liquidsolder · Sep 08, 2020 at 09:05 PM
I am a noob as well but to do this on a moving platform you make the object a child of the moving object to make it move with it. I would imagine that the conveyor would be the same. You would have to unchild the item where you want it to fall off.
Your answer