Working with a script that allows players to move (pick up) rigidbodies but can’t figure out exactly what direction I should be headed to allow the rigidbodies to still have collision while being moved. Is there a way to move rigidbodies in a predictable manner while still having them be physics aware?
using UnityEngine;
using System.Collections;
public class ObjectSelection : MonoBehaviour {
Transform selectedObj = null;
RaycastHit hit;
float dist;
Vector3 newPos;
Camera cam;
// Use this for initialization
void Start () {
cam = Camera.mainCamera;
}
// Update is called once per frame
void Update () {
if(Input.GetMouseButton(0)){
if(!selectedObj){
if(Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, 5.0f) && hit.transform.tag == "Block"){
Debug.Log ("Selectable Object");
if(hit.rigidbody){
hit.rigidbody.velocity = Vector3.zero;
hit.rigidbody.freezeRotation = true;
}
selectedObj = hit.transform;
dist = Vector3.Distance(selectedObj.position, cam.transform.position);
}
} else {
newPos = cam.transform.position + (cam.transform.forward * 5);
selectedObj.position = newPos;
}
} else{
selectedObj = null;
}
}
}
Edit: Tried playing around with kinematics to kill time, but that was clearly not a step in the right direction. Any other ideas?