Hello. i've done ton's of posts, and my First Little space invaders like game, was built 90% of the code given here. i just find things hard to grasp at the moment, and need somethings explained out for me.
How would i go about making a conveyor belt, which is Interactive with EVERY object in my scene.
i have made a conveyor belt before, but all it was, was that the actual object moving along the belt, moved in a animation, which was set to Play when instantiated. this can't be the way of Doing thing, surely? do i have to create an animation, for EVERY object? can't i just use physic's? (i tried before, but all the objects i tried just slide over the belt's surface )
Any answers are EXTREMELY appreciated (No seriously, they are)
A conveyor belt can be done in a number of ways, but the general approach is:
Decide if something is on the conveyor.
Move everything on the conveyor.
A simple way to do this would be something assuming collisions are setup attached to your conveyor like:
KinematicConveyor.js (attached to every conveyor)
var speed : float = 5.0; //conveyor speed
function OnCollisionStay(collisionInfo : Collision) { //On the conveyor
collisionInfo.transform.position += transform.forward * speed; //move stuff
}
or
PhysicsConveyor.js (attached to every conveyor)
var speed : float = 500; //conveyor force
function OnCollisionStay(collisionInfo : Collision) { //On the conveyor
collisionInfo.rigidbody.AddForce(transform.forward * speed); //move stuff
}
If you don't have or want collisions set up, then you will have to somehow determine if you are on a conveyor and apply changes via the kinematic method. The implementation is dependent on how you choose to decide what is on a conveyor.
Conveyor.js (attached to every conveyor)
var speed : float 5.0; //conveyor speed
var objects : Array = new Array(); //everything on the conveyor
function LateUpdate() {
for(var object : Transform in objects) {
object.position += transform.forward * speed; //move stuff
}
}
Conveyable.js (attached to every conveyable object)
static var conveyors : GameObject; //all the conveyors
var currentConveyor : Transform; //the current conveyor
function Start() { //Get all the conveyors once
if(!conveyors) conveyors = GameObject.FindGameObjectsWithTag("Conveyor");
}
function Update() {
if(currentConveyor && !CheckConveyor(currentConveyor)) { left conveyor
var script : Conveyor = conveyor.GetComponent(Conveyor);
for(var i : int = 0; i < script.objects.length; i++) {
if(script.objects *== transform){*
*script.objects.RemoveAt(i);*
*break;*
*}*
*}*
*}*
*if(!currentConveyor) {*
*for(var conveyor : GameObject in conveyors) {*
*if(CheckConveyor(conveyor.transform)) { //on conveyor*
*currentConveyor = conveyor.transform;*
*var script : Conveyor = conveyor.GetComponent(Conveyor);*
*script.objects.Push(transform);*
*break;*
*}*
*}*
*}*
*}*
*//Checks if on a conveyor*
*function CheckConveyor(conveyor : Transform) : boolean {*
*return transform.position.y - conveyor.position.y + conveyor.scale.y / 2.0*
*< 0.01 &&*
*transform.position.x*
*> conveyor.position.x - conveyor.localScale.x/2.0 &&*
*transform.position.x*
*< conveyor.position.x + conveyor.localScale.x / 2.0 &&*
*transform.position.z*
*> conveyor.position.z - conveyor.localScale.z / 2.0 &&*
*transform.position.z*
*< conveyor.position.z + conveyor.localScale.z / 2.0;*
*}*
*```*
I would love to help you... I'm not an expert in Unity, but I have been using it for a while, and I might be able to help... I know generally how to script, make 2d models/UI's, Storyboard, and Level Design... I'll, basically, help you get your "foot in Unity's door"... Per say... Anyway, if you want you can contact me from my website (Under the Contact page: Either E-Mail, Twitter, Shout Box, Skype... Whatever you prefer...) and I'll try to answer some/all of your question...