How to Create a Laser Cutter for an FPS in Unity

แชร์
ฝัง
  • เผยแพร่เมื่อ 30 ม.ค. 2025
  • How to Create a Laser Cutter in Unity.
    This has been created within the Unity micro-game template.
    Only Invalid Apps
    iOS
    etherscape - apps.apple.com...
    Origami Decision Maker - apps.apple.com...
    Jigsaw Farm - apps.apple.com...
    Android
    etherscape - play.google.co...
    Origami Decision Maker - play.google.co...
    Jigsaw Farm - play.google.co...
    Twitter:
    / alethowat

ความคิดเห็น • 10

  • @dominator-vk8wt
    @dominator-vk8wt 2 ปีที่แล้ว +3

    that intro is sick tho ❤️

  • @Naruy90
    @Naruy90 2 ปีที่แล้ว +2

    Hi Man, first things...nice job, second things i have a question, i have implemented you code, but there is a little problem, ONLY with QUAD it does work, with other figure like 3D cube etc doesn't work...why?, please che you help me

    • @onlyinvalid8545
      @onlyinvalid8545  ปีที่แล้ว +1

      Sorry for not replying sooner. This is a simple laser cutter & is only designed to work for a quad. It could potentially work for a cube, provided that you only cut through 1 of the faces.

  • @engineerhamza6732
    @engineerhamza6732 ปีที่แล้ว

    Because in this code is not understanding properly because of other codes of shooting sir
    if possible send me sir Thanks..

  • @Markleap
    @Markleap 2 ปีที่แล้ว +2

    can u put the script in comments or description?

    • @fun2run4
      @fun2run4 2 ปีที่แล้ว

      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      namespace Unity.FPS.Game
      {
      // Records the number of holes in a mesh
      public class CuttableMesh : MonoBehaviour
      {
      private IList m_Holes;
      public void AddHole (Vector3[] holeVertices)
      {
      m_Holes.Add(new List());
      for(int i = 0; i < holeVertices.Length; i++)
      {
      m_Holes[m_Holes.Count - 1].Add(holeVertices[i]);
      }
      }
      public List GetControlPoints()
      {
      Mesh cuttableMesh = GetComponent().mesh;
      float minX = cuttableMesh.bounds.min.x;
      float maxX = cuttableMesh.bounds.max.x;
      float minY = cuttableMesh.bounds.min.y;
      float maxY = cuttableMesh.bounds.max.y;
      return new List
      {
      new Vector3(minX, minY, 0),
      new Vector3(minX, maxY, 0),
      new Vector3(maxX, maxY, 0),
      new Vector3(maxX, minY, 0)
      };
      }
      public IList GetHoleAtIndex(int index)
      {
      return m_Holes[index];
      }
      public int NumberOfHoles()
      {
      return m_Holes.Count;
      }
      // Start is called before the first frame update
      void Start()
      {
      m_Holes = new List();
      }
      }
      }

    • @fun2run4
      @fun2run4 2 ปีที่แล้ว

      void HandleShoot()
      {
      int bulletsPerShotFinal = ShootType == WeaponShootType.Charge
      ? Mathf.CeilToInt(CurrentCharge * BulletsPerShot)
      : BulletsPerShot;
      // spawn all bullets with random direction
      for (int i = 0; i < bulletsPerShotFinal; i++)
      {
      Vector3 shotDirection = GetShotDirectionWithinSpread(WeaponMuzzle);
      ProjectileBase newProjectile = Instantiate(ProjectilePrefab, WeaponMuzzle.position,
      Quaternion.LookRotation(shotDirection));
      newProjectile.Shoot(this);
      }
      // muzzle flash
      if (MuzzleFlashPrefab != null)
      {
      GameObject muzzleFlashInstance = Instantiate(MuzzleFlashPrefab, WeaponMuzzle.position,
      WeaponMuzzle.rotation, WeaponMuzzle.transform);
      // Unparent the muzzleFlashInstance
      if (UnparentMuzzleFlash)
      {
      muzzleFlashInstance.transform.SetParent(null);
      }
      Destroy(muzzleFlashInstance, 2f);
      }
      if (HasPhysicalBullets)
      {
      ShootShell();
      m_CarriedPhysicalBullets--;
      }
      m_LastTimeShot = Time.time;
      // play shoot SFX
      if (ShootSfx && !UseContinuousShootSound)
      {
      m_ShootAudioSource.PlayOneShot(ShootSfx);
      }
      // Trigger attack animation if there is any
      if (WeaponAnimator)
      {
      WeaponAnimator.SetTrigger(k_AnimAttackParameter);
      }
      if(ShootType == WeaponShootType.Laser)
      {
      RaycastHit info;
      Physics.Raycast(WeaponMuzzle.position, WeaponMuzzle.forward, out info);
      string comparison = "Cuttable";
      string tag = info.collider.tag;
      if(info.collider != null)
      {
      if(info.collider.tag == "Cuttable")
      {
      m_Cuttable = info.collider.gameObject;
      }
      if(m_Vertices.Count != 0)
      {
      if(Vector3.Distance(m_Vertices[m_Vertices.Count - 1], info.point) > m_CutDistance)
      {
      if (tag == comparison)
      {
      m_Vertices.Add(info.point);
      }
      }
      }
      else
      {
      if (tag == comparison)
      {
      m_Vertices.Add(info.point);
      }
      }
      }
      }
      OnShoot?.Invoke();
      OnShootProcessed?.Invoke();
      }
      public bool TryCut()
      {
      if (m_Cuttable == null)
      return false;
      float extrude = 0.001f;
      Vector3[] localVertices = m_Vertices.ToArray();
      for(int i = 0; i < localVertices.Length; i++)
      {
      GameObject point = new GameObject();
      point.transform.position = m_Vertices[i];
      point.transform.SetParent(m_Cuttable.transform, true);
      localVertices[i] = point.transform.localPosition;
      Destroy(point);
      }
      AutoUnwrapSettings settings = m_Cuttable.GetComponent().faces[0].uv;
      ProBuilderMesh mesh = ProBuilderMesh.Create();
      mesh.CreateShapeFromPolygon(localVertices, extrude, false);
      foreach (Face f in mesh.faces)
      {
      f.uv = settings;
      }
      mesh.GetComponent().material = m_Cuttable.GetComponent().material;
      mesh.transform.position = m_Cuttable.transform.position;
      mesh.transform.localScale = m_Cuttable.transform.localScale;
      mesh.transform.rotation = m_Cuttable.transform.rotation;
      mesh.ToMesh();
      mesh.Refresh();
      //mesh.gameObject.AddComponent().useGravity = true;
      //---------------------------------------------------------------------
      CuttableMesh cuttableMesh = m_Cuttable.GetComponent();
      IList meshHolePoints = new List();
      cuttableMesh.AddHole(localVertices);
      for(int i = 0; i < cuttableMesh.NumberOfHoles(); i++)
      {
      meshHolePoints.Add(cuttableMesh.GetHoleAtIndex(i));
      }
      ProBuilderMesh meshWithHole = ProBuilderMesh.Create();
      List meshControlPoints = m_Cuttable.GetComponent().GetControlPoints();
      meshWithHole.CreateShapeFromPolygon(meshControlPoints, extrude, false, meshHolePoints);
      foreach (Face f in meshWithHole.faces)
      {
      f.uv = settings;
      }
      meshWithHole.ToMesh();
      meshWithHole.Refresh();
      meshWithHole.gameObject.SetActive(false);
      m_Cuttable.GetComponent().mesh = meshWithHole.GetComponent().mesh;
      m_Cuttable.GetComponent().sharedMesh = meshWithHole.GetComponent().mesh;
      m_Vertices.Clear();
      return true;
      }

    • @fun2run4
      @fun2run4 2 ปีที่แล้ว

      I couldn't paste in the whole of the Weapon controller script. Here is the most relevant bit.

    • @Markleap
      @Markleap 2 ปีที่แล้ว

      @@fun2run4 Thanks