|
|
@ -28,6 +28,7 @@ public class magnetGun : MonoBehaviour { |
|
|
|
public float maxPullSpeed = 30; |
|
|
|
public float rotateSpeed; |
|
|
|
public float minDistance = 3.0f; |
|
|
|
public float closeRange = 5.0f; |
|
|
|
public float impulsePower = 50.0f; |
|
|
|
|
|
|
|
private RigidbodyConstraints originalConstrants; |
|
|
@ -54,39 +55,40 @@ public class magnetGun : MonoBehaviour { |
|
|
|
// Update is called once per frame
|
|
|
|
void Update () { |
|
|
|
|
|
|
|
float triggerL = Input.GetAxis(L_TRIGGER_INPUT); |
|
|
|
float triggerR = Input.GetAxis (R_TRIGGER_INPUT); |
|
|
|
if (playerController.active) { |
|
|
|
float triggerL = Input.GetAxis (L_TRIGGER_INPUT); |
|
|
|
float triggerR = Input.GetAxis (R_TRIGGER_INPUT); |
|
|
|
|
|
|
|
|
|
|
|
Collider target = testItem (); |
|
|
|
Collider target = testItem (); |
|
|
|
|
|
|
|
crossHair.GetComponent<RawImage> ().color = Color.white; |
|
|
|
if (target != null){ |
|
|
|
if (target.GetComponent<Collider>().tag == "moveable"){ |
|
|
|
Debug.Log("Moveable Item"); |
|
|
|
crossHair.GetComponent<RawImage>().color = Color.red; |
|
|
|
if (Vector3.Distance (rayHitPoint, camera.transform.position) <= minDistance) { |
|
|
|
crossHair.GetComponent<RawImage>().color = Color.blue; |
|
|
|
crossHair.GetComponent<RawImage> ().color = Color.white; |
|
|
|
if (target != null) { |
|
|
|
if (target.GetComponent<Collider> ().tag == "moveable") { |
|
|
|
Debug.Log ("Moveable Item"); |
|
|
|
crossHair.GetComponent<RawImage> ().color = Color.red; |
|
|
|
if (Vector3.Distance (rayHitPoint, camera.transform.position) <= closeRange) { |
|
|
|
crossHair.GetComponent<RawImage> ().color = Color.blue; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
updateColors (target); |
|
|
|
updateColors (target); |
|
|
|
|
|
|
|
if (getAxisDown(L_TRIGGER_INPUT)){ |
|
|
|
Debug.Log ("axis down"); |
|
|
|
//Debug.Log (GravityTarget.name);
|
|
|
|
if (getAxisDown (L_TRIGGER_INPUT)) { |
|
|
|
Debug.Log ("axis down"); |
|
|
|
//Debug.Log (GravityTarget.name);
|
|
|
|
|
|
|
|
if (GravityTarget != null){ |
|
|
|
dropItem (GravityTarget); |
|
|
|
Debug.Log("dropping item"); |
|
|
|
}else{ |
|
|
|
pickUpItem (target); |
|
|
|
if (GravityTarget != null) { |
|
|
|
dropItem (GravityTarget); |
|
|
|
Debug.Log ("dropping item"); |
|
|
|
} else { |
|
|
|
pickUpItem (target); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* (triggerL > 0) { |
|
|
|
/* (triggerL > 0) { |
|
|
|
if (!L_Trigger_Down) { |
|
|
|
pickUpItem (target); |
|
|
|
L_Trigger_Down = true; |
|
|
@ -96,9 +98,12 @@ public class magnetGun : MonoBehaviour { |
|
|
|
dropItem(GravityTarget); |
|
|
|
} |
|
|
|
*/ |
|
|
|
impulsePush (target); |
|
|
|
if ( GravityTarget == null) |
|
|
|
impulsePush (target); |
|
|
|
else |
|
|
|
pullItem (triggerR); |
|
|
|
} |
|
|
|
moveItem (GravityTarget); |
|
|
|
pullItem (triggerR); |
|
|
|
rotateInput (GravityTarget); |
|
|
|
cameraRotateTest (GravityTarget); |
|
|
|
|
|
|
@ -153,8 +158,9 @@ public class magnetGun : MonoBehaviour { |
|
|
|
targetOffset = GravityTarget.transform.position - rayHitPoint + (Vector3.up * 0.05f); |
|
|
|
|
|
|
|
|
|
|
|
playerController.immobile = true; |
|
|
|
playerController.grip = 100.0f; |
|
|
|
playerController.slowed = true; |
|
|
|
playerController.movementLock = true; |
|
|
|
playerController.grip = 15.0f; |
|
|
|
|
|
|
|
if (!topScreen){ |
|
|
|
playerController.cameraSpeedX = 0.0f; |
|
|
@ -166,7 +172,13 @@ public class magnetGun : MonoBehaviour { |
|
|
|
|
|
|
|
private void impulsePush (Collider item){ |
|
|
|
if (item != null) { |
|
|
|
|
|
|
|
if (item.tag == "moveable" && Input.GetButtonDown("Quick Push")){ |
|
|
|
|
|
|
|
if (item == otherPlayer.GravityTarget){ |
|
|
|
otherPlayer.dropItem(item); |
|
|
|
} |
|
|
|
|
|
|
|
Vector3 direction = (transform.position - item.transform.position).normalized; |
|
|
|
|
|
|
|
item.attachedRigidbody.AddForce(direction * impulsePower * maxPullSpeed* item.attachedRigidbody.mass,ForceMode.Impulse ); |
|
|
@ -175,13 +187,14 @@ public class magnetGun : MonoBehaviour { |
|
|
|
} |
|
|
|
|
|
|
|
private void moveItem(Collider item){ |
|
|
|
if (item != null) { |
|
|
|
float step = objectSpeed * Time.deltaTime; |
|
|
|
Vector3 direction = gravityWell.transform.position - item.transform.position + targetOffset; |
|
|
|
direction = Vector3.ClampMagnitude(direction,1.0f); |
|
|
|
|
|
|
|
item.attachedRigidbody.AddForce(direction * objectSpeed * Time.deltaTime); |
|
|
|
if (item != null) { |
|
|
|
if (item != playerController.curCollider){ |
|
|
|
float step = objectSpeed * Time.deltaTime; |
|
|
|
Vector3 direction = gravityWell.transform.position - item.transform.position + targetOffset; |
|
|
|
direction = Vector3.ClampMagnitude(direction,1.0f); |
|
|
|
|
|
|
|
item.attachedRigidbody.AddForce(direction * objectSpeed * Time.deltaTime); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -195,7 +208,8 @@ public class magnetGun : MonoBehaviour { |
|
|
|
item.attachedRigidbody.velocity = Vector3.ClampMagnitude (item.attachedRigidbody.velocity, 5); |
|
|
|
GravityTarget = null; |
|
|
|
|
|
|
|
playerController.immobile = false; |
|
|
|
playerController.slowed = false; |
|
|
|
playerController.movementLock = false; |
|
|
|
playerController.grip = normGrip; |
|
|
|
|
|
|
|
playerController.cameraSpeedX = 250.0f; |
|
|
@ -206,7 +220,10 @@ public class magnetGun : MonoBehaviour { |
|
|
|
|
|
|
|
private void pullItem(float speed){ |
|
|
|
|
|
|
|
float step = maxPullSpeed * speed * Time.deltaTime; |
|
|
|
if (!Input.GetButton ("Quick Push")) |
|
|
|
return; |
|
|
|
|
|
|
|
float step = maxPullSpeed * 0.5f * Time.deltaTime; |
|
|
|
|
|
|
|
Vector3 maxPull; |
|
|
|
maxPull = camera.transform.position + (camera.transform.rotation * Vector3.forward); |
|
|
@ -247,7 +264,7 @@ public class magnetGun : MonoBehaviour { |
|
|
|
|
|
|
|
if (item != null) { |
|
|
|
//Debug.Log ("distance test: " + Vector3.Distance (gravityWell.transform.position, camera.transform.position));
|
|
|
|
if (Vector3.Distance (gravityWell.transform.position, camera.transform.position) <= minDistance) { |
|
|
|
if (Vector3.Distance (gravityWell.transform.position, camera.transform.position) <= closeRange) { |
|
|
|
playerController.cameraSpeedX = 250.0f; |
|
|
|
playerController.cameraSpeedY = 120.0f; |
|
|
|
} else { |
|
|
|