Browse Source

Destructible Fence

master
Joshua Reason 9 years ago
parent
commit
a7316e435c
9 changed files with 69 additions and 7 deletions
  1. +24
    -0
      unity_Project/Assets/Scripts/fence.cs
  2. +12
    -0
      unity_Project/Assets/Scripts/fence.cs.meta
  3. +3
    -3
      unity_Project/Assets/Scripts/magnetGun.cs
  4. +30
    -4
      unity_Project/Assets/Scripts/thirdPersonController.cs
  5. BIN
      unity_Project/Assets/Terrain/New Terrain.asset
  6. BIN
      unity_Project/Assets/_Scenes/MainLevel.unity
  7. BIN
      unity_Project/Assets/prefabs/Fence.prefab
  8. BIN
      unity_Project/Assets/prefabs/wall_cube.prefab
  9. BIN
      unity_Project/ProjectSettings/InputManager.asset

+ 24
- 0
unity_Project/Assets/Scripts/fence.cs View File

@ -0,0 +1,24 @@
using UnityEngine;
using System.Collections;
public class fence : MonoBehaviour {
private Rigidbody rigidbody;
// Use this for initialization
void Start () {
rigidbody = GetComponent<Rigidbody> ();
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter(Collision collision) {
if (collision.transform.tag == "moveable")
rigidbody.isKinematic = false;
}
}

+ 12
- 0
unity_Project/Assets/Scripts/fence.cs.meta View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7e92a1181b412274f95aac6cac6d6b46
timeCreated: 1441940253
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

+ 3
- 3
unity_Project/Assets/Scripts/magnetGun.cs View File

@ -142,7 +142,7 @@ public class magnetGun : MonoBehaviour {
if (item.tag == "moveable" && Input.GetButtonDown("Quick Push")){
Vector3 direction = (transform.position - item.transform.position).normalized;
item.attachedRigidbody.AddForce(direction * impulsePower * maxPullSpeed,ForceMode.Impulse);
item.attachedRigidbody.AddForce(direction * impulsePower * maxPullSpeed* item.attachedRigidbody.mass,ForceMode.Impulse );
}
}
}
@ -185,7 +185,7 @@ public class magnetGun : MonoBehaviour {
maxPull = camera.transform.position + (camera.transform.rotation * Vector3.forward);
if (Vector3.Distance (gravityWell.transform.position, camera.transform.position) > minDistance || maxPullSpeed<1) {
if ((Vector3.Distance (gravityWell.transform.position, camera.transform.position) > minDistance && Vector3.Distance (gravityWell.transform.position, camera.transform.position) < magnetRange) || maxPullSpeed<1) {
gravityWell.transform.position = Vector3.MoveTowards (gravityWell.transform.position, maxPull, step);
if ((Vector3.Distance (gravityWell.transform.position, camera.transform.position) > magnetRange) && !topScreen)
@ -219,7 +219,7 @@ public class magnetGun : MonoBehaviour {
public void cameraRotateTest(Collider item){
if (item != null) {
Debug.Log ("distance test: " + Vector3.Distance (gravityWell.transform.position, camera.transform.position));
//Debug.Log ("distance test: " + Vector3.Distance (gravityWell.transform.position, camera.transform.position));
if (Vector3.Distance (gravityWell.transform.position, camera.transform.position) <= minDistance) {
playerController.cameraSpeedX = 250.0f;
playerController.cameraSpeedY = 120.0f;

+ 30
- 4
unity_Project/Assets/Scripts/thirdPersonController.cs View File

@ -45,24 +45,36 @@ public class thirdPersonController : MonoBehaviour {
}
void FixedUpdate(){
if (Physics.Raycast (transform.position, -Vector3.up, 1.3f)) {
RaycastHit hit;
Ray ray = new Ray(transform.position, -Vector3.up);
if (Physics.Raycast (ray, out hit, 1.3f)) {
grounded = true;
if (hit.collider.tag == "moveable")
matchVelocity(hit.collider);
} else {
grounded = false;
}
if (active) {
applyMovement();
applyMovement ();
transform.rotation = Quaternion.Euler (new Vector3 (0.0f, camera.transform.rotation.eulerAngles.y, 0.0f));
applyJump(jumpHeight);
applyGrip();
applyJump (jumpHeight);
}
}
}
//}
// Update is called once per frame
void LateUpdate () {
@ -99,6 +111,20 @@ public class thirdPersonController : MonoBehaviour {
}
private void matchVelocity(Collider target){
Debug.Log ("matching velocity");
//Vector3 velocity = rigidbody.velocity;
//velocity = target.attachedRigidbody.velocity;
//rigidbody.velocity = velocity;
//transform.parent = target.transform;
//rigidbody.isKinematic = true;
}
private void applyGrip(){
float localVelX = transform.InverseTransformDirection (rigidbody.velocity).x;
float localVelZ = transform.InverseTransformDirection (rigidbody.velocity).z;

BIN
unity_Project/Assets/Terrain/New Terrain.asset View File


BIN
unity_Project/Assets/_Scenes/MainLevel.unity View File


BIN
unity_Project/Assets/prefabs/Fence.prefab View File


BIN
unity_Project/Assets/prefabs/wall_cube.prefab View File


BIN
unity_Project/ProjectSettings/InputManager.asset View File


Loading…
Cancel
Save