Browse Source

player now picks up item from where there aiming at not center of object.

master
Joshua Reason 9 years ago
parent
commit
4e06eaa79f
6 changed files with 25 additions and 2 deletions
  1. BIN
      unity_Project/Assets/Materials/Player1.mat
  2. +8
    -0
      unity_Project/Assets/Materials/Player1.mat.meta
  3. +9
    -2
      unity_Project/Assets/Scripts/magnetGun.cs
  4. BIN
      unity_Project/Assets/_Scenes/ScafoldingTest.unity
  5. BIN
      unity_Project/Assets/prefabs/pipe_large1.prefab
  6. +8
    -0
      unity_Project/Assets/prefabs/pipe_large1.prefab.meta

BIN
unity_Project/Assets/Materials/Player1.mat View File


+ 8
- 0
unity_Project/Assets/Materials/Player1.mat.meta View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0fbcbaa69a443464d8f92830db4846ad
timeCreated: 1440752527
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

+ 9
- 2
unity_Project/Assets/Scripts/magnetGun.cs View File

@ -20,6 +20,7 @@ public class magnetGun : MonoBehaviour {
public GameObject gravityWell; public GameObject gravityWell;
private Collider GravityTarget; private Collider GravityTarget;
private Vector3 rayHitPoint; private Vector3 rayHitPoint;
private Vector3 targetOffset;
public float objectSpeed; public float objectSpeed;
public float magnetRange = 20; public float magnetRange = 20;
@ -27,6 +28,8 @@ public class magnetGun : MonoBehaviour {
public float rotateSpeed; public float rotateSpeed;
public float minDistance = 3.0f; public float minDistance = 3.0f;
private float maxWalkSpeed;
// Use this for initialization // Use this for initialization
void Start () { void Start () {
if (topScreen) if (topScreen)
@ -34,6 +37,8 @@ public class magnetGun : MonoBehaviour {
else else
playerScreen = -1; playerScreen = -1;
maxWalkSpeed = playerController.movementSpeed;
} }
@ -104,6 +109,8 @@ public class magnetGun : MonoBehaviour {
item.attachedRigidbody.constraints = RigidbodyConstraints.FreezeRotation; item.attachedRigidbody.constraints = RigidbodyConstraints.FreezeRotation;
gravityWell.transform.position = rayHitPoint; gravityWell.transform.position = rayHitPoint;
GravityTarget = item; GravityTarget = item;
targetOffset = GravityTarget.transform.position - rayHitPoint + (Vector3.up * 0.05f);
playerController.movementSpeed = 200.0f; playerController.movementSpeed = 200.0f;
@ -119,7 +126,7 @@ public class magnetGun : MonoBehaviour {
private void moveItem(Collider item){ private void moveItem(Collider item){
if (item != null) { if (item != null) {
float step = objectSpeed * Time.deltaTime; float step = objectSpeed * Time.deltaTime;
Vector3 direction = gravityWell.transform.position - item.transform.position;
Vector3 direction = gravityWell.transform.position - item.transform.position + targetOffset;
direction = Vector3.ClampMagnitude(direction,1.0f); direction = Vector3.ClampMagnitude(direction,1.0f);
item.attachedRigidbody.AddForce(direction * objectSpeed * Time.deltaTime); item.attachedRigidbody.AddForce(direction * objectSpeed * Time.deltaTime);
@ -138,7 +145,7 @@ public class magnetGun : MonoBehaviour {
GravityTarget = null; GravityTarget = null;
playerController.movementSpeed = 5000.0f;
playerController.movementSpeed = maxWalkSpeed;
playerController.cameraSpeedX = 250.0f; playerController.cameraSpeedX = 250.0f;
playerController.cameraSpeedY = 120.0f; playerController.cameraSpeedY = 120.0f;

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


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


+ 8
- 0
unity_Project/Assets/prefabs/pipe_large1.prefab.meta View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c30e3469a139fe646bc1651149e4c505
timeCreated: 1440745563
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

Loading…
Cancel
Save