Hey guys,
I really struggle with the physics of a industrial crane. The crane consists out of three parts. One is the crane-rail, one the motor and one the hook. I have made a movement script where you can enable which axis should move. This movement script is on each of the three parts of the crane. My problem is that I want to stop the crane at certain boundaries. These boundaries are made with colliders. The parts are rigidbodys.
First question: Is there a better way to stop the crane at certain point.
The next problem is that I need physics applied to the whole crane when the hook collides for example with a box.
Second question: How do I do that?
Thank you for your help !
using UnityEngine;
using System.Collections;
public class Movement : MonoBehaviour {
public bool x_Movement;
public bool y_Movement;
public bool z_Movement;
private float speed = 200.5f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//Check if movement on x axis is possible
if (z_Movement) {
float leftright = Input.GetAxis ("dpadleftright");
if (leftright > 0) {
transform.localPosition += (Vector3.left * speed * Time.deltaTime);
}
else if (leftright < 0) {
transform.localPosition += (Vector3.right * speed * Time.deltaTime);
}
}
//Check if movement on y axis is possible
if (x_Movement) {
float updown = Input.GetAxis ("dpadupdown");
if (updown < 0) {
transform.localPosition += (Vector3.forward * speed * Time.deltaTime);
}
else if (updown > 0) {
transform.localPosition += (Vector3.back * speed * Time.deltaTime);
}
}
//Check if movement on z axis is possible
if (y_Movement) {
if (Input.GetButton("leftshoulder")) {
transform.localPosition += (Vector3.up * speed * Time.deltaTime);
}
else if (Input.GetButton("rightshoulder")) {
transform.localPosition += (Vector3.down * speed * Time.deltaTime);
}
}
}
}
