Skip to content

Commit

Permalink
Added laser grappling hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Legorobotdude committed Apr 16, 2018
1 parent 5f803ea commit ed08d1f
Show file tree
Hide file tree
Showing 8 changed files with 429 additions and 164 deletions.
480 changes: 321 additions & 159 deletions Assets/Scenes/Level1.unity

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Assets/Scripts/Gun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ IEnumerator Reload () {

void ShootAbstract () {
audioSource.PlayOneShot (fireSound, UnityEngine.Random.Range (0.7f, 1f));
//player.GetComponent<Rigidbody>().AddForce(transform.forward*firingForce);
player.GetComponent<Rigidbody>().AddForce(transform.forward*firingForce);

}

Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/GunRaycast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected override void Shoot()
hit.transform.GetComponent<Rigidbody>().AddForce(-hit.normal * impactForce);

}
player.playerController.SetHitAttraction(hit.point);
//player.playerController.SetHitAttraction(hit.point);
//ToDo: Play impact sounds

GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
Expand Down
89 changes: 89 additions & 0 deletions Assets/Scripts/LaserGrapple.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LaserGrapple : MonoBehaviour {


LineRenderer laserLine;
public Transform startPoint;
public Transform endPoint;
public Camera fpsCam;
public float impactForce = 100f;
public float range = 100f;
private Player player;
private Vector3 lastPosition;
private Rigidbody hitRigidbody;

// Use this for initialization
void Start () {
laserLine = GetComponent<LineRenderer>();
//laserLine.SetWidth(.2f, .2f);
player = transform.root.GetComponent<Player>();

}

// Update is called once per frame
void Update () {

if (Input.GetButton("Fire2"))
{
//player.playerController.SetHitAttraction(hit.point);
if (Input.GetButtonDown("Fire2"))
{


RaycastHit hit;
if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
{




if (hit.transform.GetComponent<Rigidbody>() != null)
{
hit.transform.GetComponent<Rigidbody>().AddForce(hit.normal * impactForce);
hitRigidbody = hit.transform.GetComponent<Rigidbody>();

}
else
{
hitRigidbody = null;
}
player.playerController.SetHitAttraction(hit.point);
laserLine.enabled = true;
laserLine.SetPosition(0, startPoint.position);
laserLine.SetPosition(1, hit.point);
lastPosition = hit.point;

}
else
{
laserLine.enabled = false;
}
}
else{
laserLine.SetPosition(0, startPoint.position);
if (hitRigidbody == null)
{

player.playerController.SetHitAttraction(lastPosition);
}
else
{

player.playerController.SetHitAttraction(hitRigidbody.position);
laserLine.SetPosition(1, hitRigidbody.position);
}

}

}
else
{
laserLine.enabled = false;
}
}

}

13 changes: 13 additions & 0 deletions Assets/Scripts/LaserGrapple.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Assets/Scripts/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void Update()

public void SetHitAttraction(Vector3 hit){

playerRigidbody.AddForce(Vector3.Normalize(hit - playerRigidbody.position) * tetherStrength);
playerRigidbody.AddForce(Vector3.Normalize(hit - playerRigidbody.position) * tetherStrength*Time.deltaTime);

}

Expand Down
3 changes: 2 additions & 1 deletion Assets/To-Do.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ Slingshot force towards enemies
Jetpack controls
Laser beam particles for shooting
Light on contact with walls/collisions
Lasso/Grappling Hook
Lasso/Grappling Hook
Turrets
2 changes: 1 addition & 1 deletion ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
m_EditorVersion: 2017.3.1f1
m_EditorVersion: 2017.4.0f1

0 comments on commit ed08d1f

Please sign in to comment.