Exemple #1
0
    public void _Remove(ChipmunkShape obj)
    {
        if (obj._handle == IntPtr.Zero)
        {
            Debug.LogError("ChipmunkShape handle is NULL");
            return;
        }

        if (!CP.cpSpaceContainsShape(_handle, obj._handle))
        {
            Debug.LogError("Space does not contain ChipmunkShape.");
            return;
        }

        PostStepFunc del = delegate(){
            //		Debug.Log("Removing shape.");
            CP.cpSpaceRemoveShape(_handle, obj._handle);
        };

        if (locked)
        {
            _AddPostStepCallback(_handle, obj.handle, del);
        }
        else
        {
            del();
        }
    }
Exemple #2
0
 void Start()
 {
     body  = GetComponent <ChipmunkBody>();
     shape = GetComponent <ChipmunkShape>();
     // invokes subclass own starting method
     ownStart();
 }
Exemple #3
0
 void Awake()
 {
     jump   = GetComponent <Jump>();
     patrol = GetComponent <Patrol>();
     shape  = GetComponent <ChipmunkShape>();
     body   = GetComponent <ChipmunkBody>();
 }
Exemple #4
0
 void Awake()
 {
     jump   = GetComponent <Jump>();
     patrol = GetComponent <Patrol>();
     shape  = GetComponent <ChipmunkShape>();
     body   = GetComponent <ChipmunkBody>();
     PauseGameManager.Instance.register(this, gameObject);
 }
Exemple #5
0
    // Use this for initialization
    void Awake()
    {
        fly   = GetComponent <Fly>();
        chase = GetComponent <Chase>();
        body  = GetComponent <ChipmunkBody>();
        shape = GetComponent <ChipmunkShape>();

        PauseGameManager.Instance.register(this, gameObject);
    }
Exemple #6
0
    /// Get references to the two colliding shapes.
    /// The collision types will match the order of the ChipmunkCollisionManager method.
    /// Say you defined a ChipmunkCollisionManager method "ChipmunkBegin_player_enemy".
    /// Then shapeA.collisionType == "player" and shapeB.collisionType == "enemy"
    public void GetShapes(out ChipmunkShape shapeA, out ChipmunkShape shapeB)
    {
        IntPtr _shapeA, _shapeB;

        _cpArbiterGetShapes(_handle, out _shapeA, out _shapeB);

        shapeA = ChipmunkShape._FromHandle(_shapeA);
        shapeB = ChipmunkShape._FromHandle(_shapeB);
    }
    protected void UpdateGrounding()
    {
        bool wasGrounded = _grounded;

        // Reset the grounding values to defaults
        _grounded         = false;
        groundNormal      = new Vector2(0f, -1f);
        groundPenetration = 0f;
        groundBody        = null;
        groundShape       = null;
        groundImpulse     = Vector2.zero;

        // Find the best (most upright) normal of something you are standing on.
        body.EachArbiter(delegate(ChipmunkArbiter arbiter){
            ChipmunkShape player, ground; arbiter.GetShapes(out player, out ground);
            Vector2 n = -arbiter.GetNormal(0);

            // Magic thershold here to detect if you hit your head or not.
            if (n.y < -0.7f)
            {
                // Bumped your head, disable further jumping.
                remainingAirJumps = 0;
                remainingBoost    = 0f;
            }
            else if (n.y > groundNormal.y)
            {
                _grounded         = true;
                groundNormal      = n;
                groundPenetration = -arbiter.GetDepth(0);
                groundBody        = ground.body;
                groundShape       = ground;
            }

            groundImpulse += arbiter.impulseWithFriction;
        });

        // If the player just landed from a significant jump, send a message.
        if (_grounded && !wasGrounded && airTime > landThreshold)
        {
            SendMessage("OnLand");
        }

        // Increment airTime if the player is not grounded.
        airTime = (!_grounded ? airTime + Time.deltaTime : 0f);

        // To be well grounded, the slope you are standing on needs to less than the amount of friction
        float friction = _grounded ? shape.friction * groundShape.friction : 0f;

        wellGrounded = grounded && Mathf.Abs(groundNormal.x / groundNormal.y) < friction;
        if (wellGrounded)
        {
            recentGroundVelocity  = (groundBody != null ? groundBody.velocity : Vector2.zero);
            remainingAirJumps     = maxAirJumps;
            remainingJumpLeniency = jumpLeniency;
        }
    }
Exemple #8
0
    void Awake()
    {
        dieAnim = GetComponent <GoombaDieAnim>();
        patrol  = GetComponent <Patrol>();
        idle    = GetComponent <Idle>();
        body    = GetComponent <ChipmunkBody>();
        shape   = GetComponent <ChipmunkShape>();

        PauseGameManager.Instance.register(this, gameObject);
    }
    protected void Start()
    {
        body  = GetComponent <ChipmunkBody>();
        shape = GetComponent <ChipmunkShape>();

        if (body == null)
        {
            Debug.LogError("Your SideScrollerController is not configured properly! Add a body!");
        }
    }
Exemple #10
0
    void Awake()
    {
        jump   = GetComponent <Jump>();
        idle   = GetComponent <Idle>();
        crouch = GetComponent <Crouch>();
        shape  = GetComponent <ChipmunkShape>();
        walkAC = AnimateTiledConfig.getByName(gameObject, EnumAnimateTiledName.Walk, true);

        lookingRight = true;
        reset();
    }
Exemple #11
0
    void Awake()
    {
        jump   = GetComponent <Jump>();
        bounce = GetComponent <Bounce>();
        patrol = GetComponent <Patrol>();
        chase  = GetComponent <Chase>();
        _hide  = GetComponent <Hide>();
        shape  = GetComponent <ChipmunkShape>();

        PauseGameManager.Instance.register(this, gameObject);
    }
    void Awake()
    {
        jump   = GetComponent <Jump>();
        bounce = GetComponent <Bounce>();
        patrol = GetComponent <Patrol>();
        chase  = GetComponent <Chase>();
        _hide  = GetComponent <Hide>();
        shape  = GetComponent <ChipmunkShape>();

        patrol.setDir(1f);         // initialize patrol direction
        initialPatrolSpeed = patrol.speed;
    }
Exemple #13
0
 public static void ChipmunkBodyDestroy(ChipmunkBody b, ChipmunkShape s)
 {
     if (s != null)
     {
         s.enabled = false;             // makes the shape to be removed from the space
     }
     if (b != null)
     {
         b.enabled = false;
         // registering a disable body will remove it from the list
         ChipmunkInterpolationManager._Register(b);
     }
 }
Exemple #14
0
    public void _Add(ChipmunkShape obj)
    {
        PostStepFunc del = delegate(){
            //		Debug.Log("Adding shape.");
            CP.cpSpaceAddShape(_handle, obj.handle);
        };

        if (locked)
        {
            _AddPostStepCallback(_handle, obj.handle, del);
        }
        else
        {
            del();
        }
    }
Exemple #15
0
    /**
     * Set the layer to the shape and also ot their chidlren shapes.
     */
    public static void setLayerForShapes(GameObject go, uint mask)
    {
        // first: set game object's shape layer
        ChipmunkShape s = go.GetComponent <ChipmunkShape>();

        if (s != null)
        {
            s.layers = mask;
        }

        // second: set chidlren's shape layer
        ChipmunkShape[] shapes = go.GetComponentsInChildren <ChipmunkShape>();
        for (int i = 0, c = shapes.Length; i < c; ++i)
        {
            shapes[i].layers = mask;
        }
    }
    protected void Update()
    {
        // Works for the mouse or a single touch. If doing multitouch, replace with with a loop over Input.touches
        // and adapt accordingly
        if (Input.GetMouseButtonDown(0))
        {
            //Debug.Log ("mouse: "+ Input.mousePosition + " position: " + GetPosition(Input.mousePosition));

            ChipmunkNearestPointQueryInfo info;
            Chipmunk.NearestPointQueryNearest(mouseBody.position, fingerThickness, out info);
            //Debug.Log ("Grabbed shape: " + info.shape);

            if (info.shape != null)
            {
                if (info.shape.body == null)
                {
                    // We clicked on a static shape. You can't drag those!
                    return;
                }

                grabbedShape = info.shape;

                mouseConstraint       = mouseBody.gameObject.AddComponent(typeof(ChipmunkPivotJoint)) as ChipmunkPivotJoint;
                mouseConstraint.bodyB = grabbedShape.body;
                mouseConstraint.pivot = Vector2.zero;

                // high but not infinite. You can push heavy things, but not force yourself through things.
                mouseConstraint.maxForce = 1e3f;

                // 60f = the approximate intended frame rate
                mouseConstraint.errorBias = Mathf.Pow(1.0f - 0.15f, 60f);
            }
        }

        if (Input.GetMouseButtonUp(0))
        {
            // remove mouse constraint.
            Destroy(mouseConstraint);
        }
    }
    private void updateGrounding()
    {
        // reset the grounding values to defaults
        _grounded = false;
        Vector2 groundNormal = GROUND_NORMAL;

        groundPenetration = 0f;
        ChipmunkBody  groundBody  = null;
        ChipmunkShape groundShape = null;

        // find the best (most upright) normal of something you are standing on
        body.EachArbiter(delegate(ChipmunkArbiter arbiter){
            ChipmunkShape component, ground;
            arbiter.GetShapes(out component, out ground);
            Vector2 n = -arbiter.GetNormal(0);
            // magic threshold here to detect if you hit your head or not
            if (GameObjectTools.isCeiling(arbiter))
            {
                // bumped your head, disable further jumping or whatever you need
            }
            else if (n.y > groundNormal.y)
            {
                _grounded         = true;
                groundNormal      = n;
                groundPenetration = -arbiter.GetDepth(0);
                groundBody        = ground.body;
                groundShape       = ground;
            }
        });

        // To be well grounded, the slope you are standing on needs to be less than the amount of friction
        float friction = _grounded ? shape.friction * groundShape.friction : 0f;

        wellGrounded = grounded && Mathf.Abs(groundNormal.x / groundNormal.y) < friction;
        if (wellGrounded)
        {
            recentGroundVelocity = (groundBody != null ? groundBody.velocity : VECTOR_ZERO);
        }
    }
Exemple #18
0
    /// Return only information about the nearest shape to the query point.
    /// Shapes are filtered using the group and layers in the same way as collisions.
    public static ChipmunkShape NearestPointQueryNearest(Vector2 point, float maxDistance, uint layers, string group, out ChipmunkNearestPointQueryInfo info)
    {
        IntPtr handle = manager._space._handle;

        return(ChipmunkShape._FromHandle(cpSpaceNearestPointQueryNearest(handle, point, maxDistance, layers, ChipmunkBinding.InternString(group), out info)));
    }
Exemple #19
0
 void Awake()
 {
     body  = GetComponent <ChipmunkBody>();
     shape = GetComponent <ChipmunkShape>();
 }
Exemple #20
0
    /// Return only the first shape struck by the segment query as it goes from start to end.
    /// Shapes are filtered using the group and layers in the same way as collisions.
    public static ChipmunkShape SegmentQueryFirst(Vector2 start, Vector2 end, uint layers, string group, out ChipmunkSegmentQueryInfo info)
    {
        IntPtr handle = manager._space._handle;

        return(ChipmunkShape._FromHandle(cpSpaceSegmentQueryFirst(handle, start, end, layers, ChipmunkBinding.InternString(group), out info)));
    }
Exemple #21
0
    public void _AddMassForShape(ChipmunkShape shape)
    {
        CP.cpBodyAddMassForShape(this.handle, shape.handle, 1f);
//		Debug.Log("Added shape to body. mass: " + mass + " moment: " + moment + ")");
    }