c# - 2D rectangle should stop moving when colliding -
I have made two rectangles, you can go ahead and jump with one of them, and the other one Still standing on the form As an obstacle, I want the obstacle to work as an obstacle (or if you do the wall), basically I want to run the rectangle when on the left side of the barrier on the right ( And so forth).
How do I find this code No detects conflicts (because it is not easy to detect conflicts) between two rectangles in an article:
< Pre> outside byte = write 1 Down & lt; Recta2 Outside hat = out 1 Tap & gt; Recta2 Outside the outside = rectangle Lift & gt; Rect 2 Right outright = rectangle Fine and lieutenant; Rect2.Left // or do not return (Rect1.Bottom Rect2.Bottom) or (Rect1.Left> Rect2.Right) or (Rect1.Right & Lt; rect2 left))
But I'm not sure how to implement it. I have a bowl called "player1.left" which is correct when I press 'A' on the keyboard Press (to move 'D' to the right, and 'W' to jump), on which the rectangle will actually be moved to 10 pixels (in timeric events).
Edit:
"rect1.Intersects with (rect2)" detects collision but how will I use it (if-inside the details What should I go) If I want to stop running the right rectangle moving on the right hand side of the barrier on the left side (but still jump left and be able to move forward) side (and so forth)? Update
// Assume that you have a class player that receives from the rectangle. Public Relative Relative: Rectangle (// Position in a Cartesian Space Private int _cartesianPositionX; Private Ent _cartesianPositionY; // Personal Characteristics of a Rectangle: int_characterWidth; Private Int Lighter Actor; Private Bool _stopMoving = False; public playing player (en x, int y, int width, int height) {this._cartesianPositionX = x; this._cartesianPositionY = y; this._chacterWidth = width; this._characterHeight = height;} Public Bull Detection Coalition ( Playable Character PC, Playable Character Barrier) {// It Your Position In practice, a test int x = 10; if (pc interceptivity) obstruction (console). Light line ("touched rectangles"); _stopMoving = true ChangeMovingDirection (x); StopMoving (x);}} Private Wide Change Moving Direction (int x) {x * = - 1; cartesianPositionX + = X;} Private zero StopMoving (int x) {x = 0; cartesianPositionX + = x;}
} < / Pre>
In the code I have given you, in a situation when the character is going right, x value which is positive, the character will face the other direction if it moves on the left side If he collides with an obstacle, then he has to face the other direction.
With stop mounting, even if you create scripts which for example in the loop run more than time, this is never a character move.
I think it should be the basis for your work. If there is a problem, please comment on the solution I wrote and I will try my best to help you if it is in my reach.
Comments
Post a Comment