private void InstantiateNewGrappleProjectile() { GameObject projectile = Instantiate(grappleProjectilePrefab); grabPoint = projectile.GetComponent <Rigidbody>(); grappleProjectile = projectile.GetComponent <GrappleProjectile>(); grappleProjectile.parentGrappler = this; }
private void Shoot() { Vector2 playerPos = owner.gameObject.transform.position; //account for direction the player is facing int xPosFactor; if (owner.isFacingRight) { xPosFactor = 1; } else { xPosFactor = -1; } Vector2 spawnPos = new Vector2(playerPos.x + (distanceFromPlayer * xPosFactor), playerPos.y); Vector2 size = new Vector2(.5f, .5f); if (existingProjectile == null) // FIRE HOOK { //spawn bullet GameObject projectileObject = Instantiate(projectilePrefab, spawnPos, Quaternion.identity); existingProjectile = projectileObject; GrappleProjectile projectile = projectileObject.GetComponent <GrappleProjectile>(); projectile.owner = owner; grappleFire.Stop(); grappleFire.Play(); //setup bullet properties projectile.SetupProjectile(projectileLifetime, projectileDamage, projectileSpeed, owner.isFacingRight, grappleHit, grapplePull, grappleFire, jumpSound); //delay to avoid shooting once per frame owner.DecreaseHealth(energyCostPerTick, false); if (armSide == ArmSide.ARMONE) { hookVisualOne.SetActive(false); } else { hookVisualTwo.SetActive(false); } } else { Debug.Log("BM_Grapple -> Shoot() -> No Grapple Hook fired because of a lack of space"); } }
// Update is called once per frame void Update() { if (isRetract) { float step = flySpeed * Time.deltaTime; player.transform.position = Vector3.MoveTowards(player.transform.position, flyTarget, step); if (player.transform.position == flyTarget) { isRetract = false; firedGrapple = GameObject.FindGameObjectWithTag("FiredGrapple"); Destroy(firedGrapple); } } if (Input.GetMouseButtonDown(0)) { if (didFireGrapple) { // tell the player FPS controller to move towards the firedGrapple // Debug.Log(firedGrapple.transform.position); if (firedGrappleController.didHitTarget) { Debug.Log("destroy fired grapple"); didFireGrapple = false; isRetract = true; // player.transform.position = firedGrappleController.hitPosition; flyTarget = firedGrappleController.hitPosition; } } else { Instantiate(grapple, cannon.transform.position, cannon.transform.rotation); // Instantiate (rope, cannon.transform.position, cannon.transform.rotation); didFireGrapple = true; firedGrappleController = GameObject.FindGameObjectWithTag("FiredGrapple").GetComponent <GrappleProjectile>(); } } }
public void ConfigureDelegateForceGrabTarget(GrappleProjectile delegateForceGrabTarget) { rb = delegateForceGrabTarget.GetComponent <Rigidbody>(); rb.velocity = Vector3.zero; rb.isKinematic = true; rb.freezeRotation = true; CharacterJoint characterJoint = delegateForceGrabTarget.gameObject.AddComponent <CharacterJoint>(); // Serialize the newly created component. // UnityEvents are null when the component is created via AddComponent() // Solution: https://forum.unity.com/threads/unity-event-is-null-right-after-addcomponent.819402/#post-5427855 // // The unity namespace isn't available during builds however, so we need to wrap it in compiler flags // https://answers.unity.com/questions/576746/build-error-the-type-or-namespace-name-unityeditor.html #if UNITY_EDITOR SerializedObject so; so = new SerializedObject(characterJoint); so.Update(); #endif characterJoint.connectedBody = limbRigidbody; }