コード例 #1
0
        // Use this for calculate
        public override void OnCalculate()
        {
            Rigidbody2D rigidbody2D = _Rigidbody2D.value;

            if (rigidbody2D != null)
            {
                _Result.SetValue(rigidbody2D.GetPoint(_Point.value));
            }
        }
コード例 #2
0
ファイル: Rigidbody2DWrap.cs プロジェクト: xophiix/CsToLua
    static int GetPoint(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        Rigidbody2D obj  = LuaScriptMgr.GetNetObject <Rigidbody2D>(L, 1);
        Vector2     arg0 = LuaScriptMgr.GetNetObject <Vector2>(L, 2);
        Vector2     o    = obj.GetPoint(arg0);

        LuaScriptMgr.PushValue(L, o);
        return(1);
    }
コード例 #3
0
    void OnCollisionStay2D(Collision2D col)
    {
        Vector2        point2 = Vector2.zero;
        ContactPoint2D point  = col.GetContact(0);

        point2 = m_Rigidbody2D.GetPoint(point2);
        if (point.point.y < -point2.y)
        {
            grounded = true;
        }
        Debug.Log("p1:" + point.point.y + "p2: " + -point2.y);
    }
コード例 #4
0
 protected override Vector3 get_local()
 {
     return(_rigid.GetPoint(_rigid.position));
 }
コード例 #5
0
    private void FixedUpdate()
    {
        if (do_relative_movement)
        {
            Vector3Int floor_pos = new Vector3Int();
            floor_pos.x = Mathf.RoundToInt(transform.position.x);
            floor_pos.y = Mathf.RoundToInt(transform.position.y);

            Vector3Int floor_pos_floor = new Vector3Int();
            floor_pos_floor.x = Mathf.FloorToInt(transform.position.x);
            floor_pos_floor.y = Mathf.FloorToInt(transform.position.y);

            if (parent_grid != null)
            {
                if (ship_floor_tilemap.GetTile(parent_grid.WorldToCell(transform.position)) != null)
                {
                    on_ship_floor = true;
                }
                else
                {
                    on_ship_floor = false;
                }
            }
            else
            {
                on_ship_floor = false;
            }

            if (floor_tilemap.GetTile(floor_pos_floor) != null)
            {
                on_floor = true;
            }
            else
            {
                on_floor = false;
            }

            if ((parent_rigidbody != null) && (on_ship_floor))
            {
                is_in_space = false;
                if (!has_entered_ship)
                {
                    last_frame_anchor = parent_rigidbody.GetRelativePoint(ship_anchor);
                    Set_Anchor_Point(true);

                    rb.velocity        = parent_rigidbody.velocity;
                    rb.angularVelocity = parent_rigidbody.angularVelocity;

                    is_anchor_point_set = false;
                }

                has_entered_ship = true;
                parent_speed     = parent_rigidbody.velocity.magnitude;

                Vector2 conversion_pos = parent_rigidbody.GetPoint(new Vector2(transform.position.x, transform.position.y));

                if (!on_ship_floor)
                {
                    last_frame_anchor = parent_rigidbody.GetRelativePoint(ship_anchor);
                    Set_Anchor_Point(true);
                }

                if (on_ship_floor)
                {
                    //if (last_frame_anchor != parent_rigidbody.GetRelativePoint(ship_anchor))
                    //{
                    if (is_anchor_point_set)
                    {
                        rb.velocity        = ((parent_rigidbody.GetRelativePoint(ship_anchor) - last_frame_anchor) * anchor_constant);
                        rb.angularVelocity = parent_rigidbody.angularVelocity;
                    }
                    else
                    {
                        is_anchor_point_set = true;
                    }

                    last_frame_anchor = parent_rigidbody.GetRelativePoint(ship_anchor);
                    //}

                    if (Vector2.Distance(parent_rigidbody.GetRelativePoint(ship_anchor), transform.position) > 0.5f)
                    {
                        Set_Anchor_Point(true);
                        is_anchor_point_set = false;
                    }
                }
            }
            else if (!on_floor && !on_ship_floor)
            {
                if (!is_in_space && !has_entered_ship)
                {
                    rb.angularVelocity = rb.angularVelocity / drag_force;
                }

                rb.angularVelocity = 0.0f;
                has_entered_ship   = false;
                is_in_space        = true;
            }
            else
            {
                rb.velocity        = new Vector2(0.0f, 0.0f);
                rb.angularVelocity = 0.0f;
                has_entered_ship   = false;
                is_in_space        = false;
            }
        }
    }