Ejemplo n.º 1
0
    public static int constructor(IntPtr l)
    {
        int result;

        try
        {
            int num = LuaDLL.lua_gettop(l);
            if (num == 1)
            {
                PhysicsMaterial2D o = new PhysicsMaterial2D();
                LuaObject.pushValue(l, true);
                LuaObject.pushValue(l, o);
                result = 2;
            }
            else if (num == 2)
            {
                string name;
                LuaObject.checkType(l, 2, out name);
                PhysicsMaterial2D o = new PhysicsMaterial2D(name);
                LuaObject.pushValue(l, true);
                LuaObject.pushValue(l, o);
                result = 2;
            }
            else
            {
                result = LuaObject.error(l, "New object failed.");
            }
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
Ejemplo n.º 2
0
 // Start is called before the first frame update
 void Start()
 {
     movimentoHabilitado = false;
     rb2d     = GetComponent <Rigidbody2D>();
     collider = GetComponent <CircleCollider2D>();
     material = collider.sharedMaterial;
 }
Ejemplo n.º 3
0
 public override void Reset()
 {
     gameObject        = null;
     physicsMaterial2d = null;
     friction          = null;
     everyFrame        = false;
 }
Ejemplo n.º 4
0
    protected override IEnumerator StartState()
    {
        character.visualsAnimator.SetTrigger("Jump");

        character.movementController.Jump(character.characterProperties.jumpForce, ForceMode2D.Impulse);

        try
        {
            character.rb2d.sharedMaterial = ((PlayerProperties)(character.characterProperties)).OnAirMaterial;
        }
        catch (System.InvalidCastException)
        { }

        PhysicsMaterial2D pMat = new PhysicsMaterial2D();

        pMat.friction   = ((PlayerManager)character).onAirMaterial.friction;
        pMat.bounciness = ((PlayerManager)character).onAirMaterial.bounciness;

        foreach (Collider2D collider in character.gameObject.GetComponents <Collider2D>())
        {
            collider.sharedMaterial = pMat;
        }

        yield return("success");
    }
Ejemplo n.º 5
0
    public void ColliderAssignPoints()
    {
        if (colliderCreation)
        {
            colliderCreation = false;

            if (colliders.Count > 0 && colliderPoints.Count > 0)
            {
                int        collidersLength = colliders.Count - 1;
                GameObject collider        = colliders[collidersLength];
                string     start           = "Start: (" + (int)colliderPoints.First().x + ", " + (int)colliderPoints.First().y + ")";
                string     end             = "End: (" + (int)colliderPoints.Last().x + ", " + (int)colliderPoints.Last().y + ")";
                collider.name = "Collider: " + collidersLength + " - " + start + " - " + end;

                EdgeCollider2D eCollider = collider.GetComponent <EdgeCollider2D>();
                if (eCollider != null)
                {
                    eCollider.points = colliderPoints.ToArray();
                    colliderPoints.Clear();

                    PhysicsMaterial2D physicsMaterial = (PhysicsMaterial2D)Resources.Load("Materials/Grass");

                    if (physicsMaterial != null)
                    {
                        eCollider.sharedMaterial = physicsMaterial;
                    }
                }
            }
        }
        else
        {
            Debug.Log("Not creating currently a new collider, you need to create an active one first to assign points to it.");
        }
    }
Ejemplo n.º 6
0
 public void SetPhysicsMaterial2D(PhysicsMaterial2D mat)
 {
     if (mat != null)
     {
         physicsMat = mat;
     }
 }
Ejemplo n.º 7
0
    private void ChangeFriction(float newFriction)
    {
        PhysicsMaterial2D pm2d = GetComponent <CapsuleCollider2D>().sharedMaterial;

        pm2d.friction = newFriction;
        GetComponent <CapsuleCollider2D>().sharedMaterial = pm2d;
    }
            private void Awake()
            {
                if (unactive == null || active == null)
                {
                    Texture2D tex;
                    tex      = GUIController.Instance.images["magic_circle_b"];
                    unactive = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f));
                    tex      = GUIController.Instance.images["magic_circle_y"];
                    active   = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f));
                }
                sr.sprite = unactive;
                var col = gameObject.AddComponent <BoxCollider2D>();

                col.size = new Vector2(4f, 0.1f);
                var rb = gameObject.AddComponent <Rigidbody2D>();

                rb.bodyType      = RigidbodyType2D.Static;
                gameObject.layer = (int)GlobalEnums.PhysLayers.TERRAIN;
                var mat = new PhysicsMaterial2D();

                mat.friction       = 0.4f;
                mat.bounciness     = 0;
                col.sharedMaterial = mat;

                OpenGate = () =>
                {
                    Logger.LogDebug("Zote Open");
                    FindObjectOfType <ZoteWall>()?.Open();
                };
            }
            private void Awake()
            {
                var go = Instantiate(ObjectLoader.InstantiableObjects["HK_Hconveyor"], transform);

                go.transform.localPosition = new Vector3(0, 2f, -2.4f);

                var cgo = new GameObject("box");

                cgo.transform.SetParent(go.transform);
                cgo.layer = (int)GlobalEnums.PhysLayers.TERRAIN;
                cgo.transform.localScale = Vector3.one;

                var col  = cgo.AddComponent <BoxCollider2D>();
                var conv = cgo.AddComponent <ConveyorBelt>();

                //conv.speed = -8;
                col.size   = new Vector2(10.61741f, 2.202475f);
                col.offset = new Vector2(-0.358706f, -2.418878f);
                col.transform.localPosition = Vector3.zero;

                var mat = new PhysicsMaterial2D();

                mat.friction       = 0.2f;
                mat.bounciness     = 0;
                col.sharedMaterial = mat;

                go.SetActive(true);

                if (SetupMode)
                {
                    gameObject.AddComponent <ShowColliders>();
                }
            }
Ejemplo n.º 10
0
 // Use this for initialization
 void Awake()
 {
     respawn_position_vec3 = transform.position;
     O_camera              = GameObject.Find("Main Camera");
     b_die                 = false;
     f_jump_speed          = 8.5f;
     f_speed               = 8.0f;
     player_rig            = GetComponent <Rigidbody2D>();
     t_ground_check        = transform.Find("Groundcheck");
     t_ground_check2       = transform.Find("Groundcheck2");
     t_pic                 = transform.Find("pic");
     player_spine_animator = transform.GetChild(0).GetComponent <Animator>();
     player_animator       = gameObject.GetComponent <Animator>();
     player_tra            = gameObject.GetComponent <Transform>();
     jump_vec2             = new Vector2(0, f_jump_speed);
     player_coll           = GetComponent <Collider2D>();
     respawn_position_vec3 = transform.position;
     b_jump                = false;
     i_hp            = 3; i_hp_tmp = 3;
     HP_ui           = GameObject.Find("UI_HP").GetComponent <C_UIHP>();
     player_box      = gameObject.GetComponent <BoxCollider2D>();
     player_material = player_box.sharedMaterial;
     AOE_col         = transform.GetChild(3);
     AOE_col.gameObject.SetActive(false);
     b_AOE_has         = false;
     b_hurting         = b_play_ani = false;
     b_attack_enable   = true;
     f_hurting_time    = f_attack_time = 0;
     skeleton_animator = transform.GetChild(0).GetComponent <SkeletonAnimator>();
     i_hit_number      = 0;
 }
Ejemplo n.º 11
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        PhysicsMaterial2D material = null;

        if (collision.gameObject.TryGetComponent(out Rigidbody2D body))
        {
            material = body.sharedMaterial;
        }
        else if (collision.gameObject.TryGetComponent(out BoxCollider2D collider))
        {
            material = collider.sharedMaterial;
        }
        else if (collision.gameObject.TryGetComponent(out CircleCollider2D circle))
        {
            material = circle.sharedMaterial;
        }
        else if (collision.gameObject.TryGetComponent(out TilemapCollider2D map))
        {
            material = map.sharedMaterial;
        }
        if (_materials.Contains(material))
        {
            Instantiate(_template, collision.GetContact(0).point, Quaternion.LookRotation(collision.GetContact(0).point, transform.position));
        }
    }
Ejemplo n.º 12
0
    public void loadStuff(float[] cashNeeded, float bouncy, int ballAmount, float size)
    {
        actualKash = cashNeeded;
        bounc      = bouncy;
        for (int i = 0; i < ballAmount; i++)
        {
            createBall(bounc, size);
        }

        int[] kashneeded = new int[4];
        for (int i = 0; i < 4; i++)
        {
            kashneeded[i] = Mathf.FloorToInt(cashNeeded[i]);
        }
        CostHolder.instance.updateCost(kashneeded);
        GameObject[]      balls = GameObject.FindGameObjectsWithTag("Ball");
        PhysicsMaterial2D pm    = balls[0].GetComponent <Collider2D>().sharedMaterial;

        pm.bounciness = bounc;
        foreach (GameObject ball in balls)
        {
            ball.GetComponent <Collider2D>().sharedMaterial  = pm;
            ball.GetComponent <Rigidbody2D>().sharedMaterial = pm;
        }
    }
Ejemplo n.º 13
0
    public override Hashtable EditorDragDrop(object o)
    {
        if (typeof(PhysicsMaterial2D).IsAssignableFrom(o.GetType()))
        {
            PhysicsMaterial2D ac = (PhysicsMaterial2D)o;

            string path = UnityEditor.AssetDatabase.GetAssetPath(ac.GetInstanceID( ));

            int index = path.IndexOf("Resources/");

            if (index > 0)
            {
                path = path.Substring(index + "Resources/".Length);

                int dot = path.LastIndexOf('.');
                if (dot >= 0)
                {
                    path = path.Substring(0, dot);
                }

                Hashtable hashtable = new Hashtable( );
                hashtable["name"] = path;

                return(hashtable);
            }
        }

        return(null);
    }
Ejemplo n.º 14
0
    // Start is called before the first frame update
    void Start()
    {
        if (spawnPlayer)
        {
            player = Instantiate(playerPrefab, spawnPoint.position, Quaternion.identity);
            player.GetComponent <PlayerHealth>().healthSlider = healthSlider;
            player.GetComponent <SpriteRenderer>().sprite     = playerSkins[skinID];
            PhysicsMaterial2D material = player.GetComponent <PolygonCollider2D>().sharedMaterial;
            Destroy(player.GetComponent <PolygonCollider2D>());
            PolygonCollider2D collider = player.AddComponent <PolygonCollider2D>();
            collider.sharedMaterial = material;
        }

        if (addWeapon)
        {
            Transform  playerHand = player.transform.Find("Hand");
            GameObject weapon     = Instantiate(Weapons[weaponID], playerHand.position, Quaternion.identity, playerHand);
            weapon.layer = LayerMask.NameToLayer("PlayerWeapon");
            weapon.GetComponent <SpriteRenderer>().sortingLayerName = "PlayerWeapon";
        }

        playerHealthCanvas.gameObject.SetActive(false);
        if (addPlayerHealthCanvas)
        {
            playerHealthCanvas.gameObject.SetActive(true);
        }

        playerControlCanvas.gameObject.SetActive(false);
        if (addPlayerControlCanvas)
        {
            playerControlCanvas.gameObject.SetActive(true);
        }
    }
Ejemplo n.º 15
0
    public void SetInits(PhysicsMaterial2D material2D, Sprite sprite)
    {
        rb.sharedMaterial = material2D;
        rb.simulated      = true;

        GetComponent <SpriteRenderer>().sprite = sprite;
    }
Ejemplo n.º 16
0
 private void SetCapsuleMaterial(PhysicsMaterial2D mate)
 {
     if (useFZero)
     {
         capsuleColl.sharedMaterial = mate;
     }
 }
Ejemplo n.º 17
0
        private static void InitializePhysicsMaterialsV1()
        {
            Util.CreateAssetFolder("Assets/Data", "Physics");
            Util.CreateAssetFolder("Assets/Data/Physics", "Materials");

            // 2D frictionless material
            PhysicsMaterial2D frictionless2D = new PhysicsMaterial2D
            {
                friction   = 0.0f,
                bounciness = 0.1f,
            };

            Util.CreateAsset(frictionless2D, "Assets/Data/Physics/Materials/frictionless.physicMaterial");

            // 3D frictionless material
            PhysicMaterial frictionless3D = new PhysicMaterial
            {
                staticFriction  = 0.0f,
                dynamicFriction = 0.0f,
                bounciness      = 0.1f,
                bounceCombine   = PhysicMaterialCombine.Minimum,
                frictionCombine = PhysicMaterialCombine.Minimum
            };

            Util.CreateAsset(frictionless3D, "Assets/Data/Physics/Materials/frictionless2D.physicsMaterial2D");
        }
Ejemplo n.º 18
0
    void Start()
    {
        gm   = GameManager.instance;
        rb   = GetComponent <Rigidbody2D>();
        anim = GetComponent <Animator>();

        cam      = FindObjectOfType <CinemachineVirtualCamera>();
        composer = cam.GetCinemachineComponent <CinemachineFramingTransposer>();

        if (gm.resetCount == 0)
        {
            GameManager.instance.lastCheckpos = transform.position;
        }
        else if (gm.resetCount > 0) //ya no sirve, pero dejemoslo por las dudas
        {
            transform.position = GameManager.instance.lastCheckpos;
        }

        PhysicsMaterial2D physicMaterial = new PhysicsMaterial2D(gameObject.name);

        physicMaterial.bounciness = 0;
        physicMaterial.friction   = 0;

        rb.sharedMaterial = physicMaterial;
    }
Ejemplo n.º 19
0
    void Awake()
    {
        rigid = GetComponent <Rigidbody2D> ();

        side   = GetComponent <BoxCollider2D> ();
        bottom = GetComponent <CircleCollider2D> ();

        anim = GetComponent <Animator> ();

        slippery = Resources.Load("Materials/Physics/SlipperyPlayer") as PhysicsMaterial2D;
        friction = Resources.Load("Materials/Physics/FrictionPlayer") as PhysicsMaterial2D;

        movespeed = 3f;
        jumpSpeed = 4f;

        InSlowMotion = false;

        hits = new List <Hit> ();

        height = Mathf.Abs(bottom.bounds.min.y - side.bounds.max.y);
        width  = Mathf.Abs(side.bounds.min.x - side.bounds.max.x);

        IceMove = false;

        //get player bounds
        boundingbox = boundingObject.GetComponent <SpriteRenderer>().bounds;

        InitializeRaycaster();

        horizontal_set = false;
    }
Ejemplo n.º 20
0
 void Start()
 {
     wheel              = GetComponent <CircleCollider2D>();
     wheelMaterial      = GameAssets.Instance.WheelMaterial;
     wheelBrakeMaterial = GameAssets.Instance.WheelBrakeMaterial;
     gearAnimator       = GetComponent <Animator>();
 }
Ejemplo n.º 21
0
    private void CheckJump()
    {
        canJump = false;
        PhysicsMaterial2D material = rb.sharedMaterial;

        material.friction = 0;
        CheckSize         = new Vector2(0.98f, 0.5f);
        Vector2 groundCheck = new Vector2(transform.position.x, transform.position.y);

        Collider2D[] collisions = Physics2D.OverlapBoxAll(new Vector2(groundCheck.x, groundCheck.y - 0.275f), CheckSize, 0);
        foreach (var collision in collisions)
        {
            if (collision.transform != null)
            {
                if (collision.name != transform.name)
                {
                    if (Dangerous(collision.tag, collision.name))
                    {
                        GameOver();
                    }
                    canJump = true;
                    if (!collision.name.Contains("Player") && !collision.name.Contains("Movable"))
                    {
                        material.friction = 10;
                    }
                }
            }
        }
        rb.sharedMaterial = material;
    }
Ejemplo n.º 22
0
    void Awake()
    {
        _instance = this;
        rigid     = this.GetComponent <Rigidbody2D>();
        if (rigid == null)
        {
            rigid                         = this.gameObject.AddComponent <Rigidbody2D>();
            rigid.constraints             = RigidbodyConstraints2D.FreezeRotation;
            rigid.sharedMaterial          = new PhysicsMaterial2D();
            rigid.sharedMaterial.friction = 0;
            rigid.collisionDetectionMode  = CollisionDetectionMode2D.Continuous;
            rigid.interpolation           = RigidbodyInterpolation2D.Extrapolate;
            rigid.freezeRotation          = true;
        }

        PhysicsMaterial2D material = new PhysicsMaterial2D();

        material.friction = 0;
        this.GetComponent <Collider2D>().sharedMaterial = material;

        anim = this.GetComponent <Animator>();
        if (anim == null)
        {
            anim = this.gameObject.AddComponent <Animator>();
        }

        render = this.GetComponent <SpriteRenderer>();
        if (render == null)
        {
            render = this.gameObject.AddComponent <SpriteRenderer>();
        }
    }
Ejemplo n.º 23
0
        private void Awake()
        {
            // Setting up references.
            m_GroundCheck  = transform.Find("GroundCheck");
            m_CeilingCheck = transform.Find("CeilingCheck");
            m_Anim         = GetComponent <Animator>();
            m_Rigidbody2D  = GetComponent <Rigidbody2D>();

            //Set initital speed, jump force and strength values
            currentSpeed     = m_MaxSpeed;
            currentJumpForce = m_JumpForce;
            health           = m_MaxHealth;
            material         = m_Rigidbody2D.sharedMaterial;

            crates = GameObject.FindGameObjectsWithTag("Crate");

            UpdateAnimClipTimes();

            playerTrans = this.GetComponent <Transform>();

            if (PlayerPrefs.HasKey("audio"))
            {
                jumpingsound.volume    = PlayerPrefs.GetFloat("audio");
                grabbingsound.volume   = PlayerPrefs.GetFloat("audio");
                collectingsound.volume = PlayerPrefs.GetFloat("audio");
                runningsound.volume    = PlayerPrefs.GetFloat("audio");
            }
        }
Ejemplo n.º 24
0
    public virtual void Setup(BaseCreature creatureData)
    {
        data           = creatureData;
        data.currentHp = data.hp;
        rb             = GetComponent <Rigidbody2D>();
        rb.angularDrag = data.angularDrag;
        rb.drag        = data.drag;
        rb.mass        = data.mass;
        var coll = GetComponent <Collider2D>();
        var mat  = new PhysicsMaterial2D();

        mat.bounciness       = data.bounciness;
        mat.friction         = data.friction;
        coll.sharedMaterial  = mat;
        transform.localScale = Vector3.one * creatureData.scale;
        view.sprite          = SpriteBase.GetSprite(data.view + data.teamId);
        teamId = data.teamId;
        progressBar.gameObject.SetActive(true);
        if (data.Action != null)
        {
            actionReceiver = gameObject.AddComponent(data.Action.GetType()) as IActionReceiver;
            actionReceiver.Setup(data.Action as IActionReceiver);
        }

        if (data.HitAction != null)
        {
            hitActionReceiver = gameObject.AddComponent(data.HitAction.GetType()) as IActionReceiver;
            hitActionReceiver.Setup(data.HitAction as IActionReceiver);
        }

        MatchManager.OnEndTurn += OnEndTurn;
    }
Ejemplo n.º 25
0
 // Start is called before the first frame update
 void Start()
 {
     rb              = GetComponent <Rigidbody2D>();
     startingDrag    = rb.drag;
     startingAngular = rb.angularDrag;
     matAsPick       = rb.sharedMaterial;
 }
Ejemplo n.º 26
0
    List <Path> Cast(Vector3 x0, Vector3 v0, PhysicsMaterial2D pA, LayerMask ignoreMask)
    {
        int         bounce = 0;
        float       t      = 0;
        PathHitInfo pathHitInfo;
        float       speedPow2 = this.minSpeed * this.minSpeed;
        List <Path> paths     = new List <Path>();

        while (Vector3.Dot(v0, v0) >= speedPow2 && bounce <= this.maxBounce)
        {
            pathHitInfo = this.CalculateSingle(x0, v0, ignoreMask);
            paths.Add(new Path()
            {
                x0 = x0, v0 = v0, t = pathHitInfo.t
            });

            float elast = (pA.bounciness + pathHitInfo.pB.bounciness) / 2;
            float frict = (pA.friction + pathHitInfo.pB.friction) / 2;
            float dot   = 1 - Mathf.Abs(Vector3.Dot(v0.normalized, pathHitInfo.normal));

            v0      = Vector3.Reflect(this.getVelocity(v0, t), pathHitInfo.normal) * elast + v0 * frict;
            bounce += 1;
        }

        return(paths);
    }
Ejemplo n.º 27
0
    /// <summary>
    /// In the Tiled layer add a custom property called 'physicsMaterial2D' to be used in the handler
    /// The value of the property must be a valid PhysicsMaterial2D located in the Assets/Materials/PhysicsMaterial/
    /// </summary>
    public void HandleCustomProperties(GameObject gameObject,
                                       IDictionary <string, string> props)
    {
        //Se não existir o custom property já saimos
        if (!props.ContainsKey("physicsMaterial2D"))
        {
            return;
        }

        string materialName = props["physicsMaterial2D"] + ".physicsMaterial2D";
        string materialPath = "Assets/Materials/PhysicsMaterial/" + materialName;


        // Verificamos se o material existe, se não existir disparamos o erro e retornamos
        PhysicsMaterial2D material = AssetDatabase.LoadAssetAtPath(materialPath, typeof(PhysicsMaterial2D)) as PhysicsMaterial2D;

        if (material == null)
        {
            Debug.LogError(String.Format("Could not find material: {0}", materialName));
            return;
        }

        //O tiled2unity sempre exporta o collider como PolygonCollider, se mudar temos que refazer essa parte
        if (gameObject.GetComponentInChildren <PolygonCollider2D>() != null)
        {
            gameObject.GetComponentInChildren <PolygonCollider2D>().sharedMaterial = material;
        }
    }
Ejemplo n.º 28
0
 // Start is called before the first frame update
 void Start()
 {
     rigidbody        = GetComponent <Rigidbody2D>();
     collider         = GetComponent <CircleCollider2D>();
     originalMaterial = collider.sharedMaterial;
     slowDown         = false;
 }
Ejemplo n.º 29
0
 // Start is called before the first frame update
 void Start()
 {
     if (shouldChangeMaterial == true)
     {
         trapMaterial = GetComponent <Collider2D>().sharedMaterial;
     }
 }
Ejemplo n.º 30
0
 public StateFalling(Fsm fsm) : base(fsm)
 {
     _material   = Resources.Load <PhysicsMaterial2D>("NoFriction");
     _collider   = Fsm.gameObject.GetComponent <Collider2D>(); _collider.sharedMaterial = null;
     _locomotion = Fsm.gameObject.GetOrAdd <ManagerLocomotion>(); _locomotion.Rigidbody.gravityScale = 11f;
     _input      = Fsm.gameObject.GetComponent <IManagerInput>();
 }