Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Hey Chili!
 Post Posted: August 2nd, 2017, 8:37 pm 
User avatar

Joined: June 9th, 2017, 11:30 pm
Posts: 68
Hey Chili, I want to add colliding physics to this. How do I go about doing that? I have tried different things but none worked. I left the code in for you.


Attachments:
New folder.zip [4.46 MiB]
Downloaded 8 times


Last edited by goldengamesTM on August 2nd, 2017, 11:46 pm, edited 1 time in total.
Top 
 Profile  
Reply with quote  
 Post subject: Re: Hey Chili!
 Post Posted: August 2nd, 2017, 11:20 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2844
Location: Oklahoma, United States
You need more than the .sln file to open the project. You need to upload the entire solution folder, or create a GitHub account, upload your project to your GitHub account and share the link. You can check chili's videos on how to create a repository on GitHub.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post subject: Re: Hey Chili!
 Post Posted: August 2nd, 2017, 11:33 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2844
Location: Oklahoma, United States
For rectangle collision,


Code:
// Not real code, can't copy and paste this shit and expect it to work.  You'll have to come up with the real code yourself.
rect_a
rect_b

if
rect_a.left <= rect_b.right and rect_a.right > rect_b.left and
rect_a.top <= rect_b.bottom and rect_a.bottom > rect_b.top then
collision = true;


If you don't have a rect class, then left is usually the xPosition, right is the xPosition + width, top is yPosition and bottom is yPosition + height.

That is collision detection. The correction part is still a mystery to me lol. If rect_a is coming from the top, then push up ( yPosition += rect_b.top - rect_a.bottom ), if coming from the left add the difference of overlap along the left of B and the right of A to the xPosition. When coming from the corners ( overlap on top or bottom and one of the sides ) one way of doing it would be to get the opposite direction the moving object was going in and move it until there is no overlap.

_________________
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com


Top 
 Profile  
Reply with quote  
 Post subject: Re: Hey Chili!
 Post Posted: August 2nd, 2017, 11:48 pm 
User avatar

Joined: June 9th, 2017, 11:30 pm
Posts: 68
albinopapa wrote:
For rectangle collision,


Code:
// Not real code, can't copy and paste this shit and expect it to work.  You'll have to come up with the real code yourself.
rect_a
rect_b

if
rect_a.left <= rect_b.right and rect_a.right > rect_b.left and
rect_a.top <= rect_b.bottom and rect_a.bottom > rect_b.top then
collision = true;



If you don't have a rect class, then left is usually the xPosition, right is the xPosition + width, top is yPosition and bottom is yPosition + height.

That is collision detection. The correction part is still a mystery to me lol. If rect_a is coming from the top, then push up ( yPosition += rect_b.top - rect_a.bottom ), if coming from the left add the difference of overlap along the left of B and the right of A to the xPosition. When coming from the corners ( overlap on top or bottom and one of the sides ) one way of doing it would be to get the opposite direction the moving object was going in and move it until there is no overlap.

I Added The Solution So You Can Look At The Code Yourself And See The Dumb Way I Did That.


Top 
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 4 posts ] 

Board index » Everything


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for: