Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

aabb collision with direction

float player_bottom = player.get_y() + player.get_height();
float tiles_bottom = tiles.get_y() + tiles.get_height();
float player_right = player.get_x() + player.get_width();
float tiles_right = tiles.get_x() + tiles.get_width();

float b_collision = tiles_bottom - player.get_y();
float t_collision = player_bottom - tiles.get_y();
float l_collision = player_right - tiles.get_x();
float r_collision = tiles_right - player.get_x();

if (t_collision < b_collision && t_collision < l_collision && t_collision < r_collision )
{                           
//Top collision
}
if (b_collision < t_collision && b_collision < l_collision && b_collision < r_collision)                        
{
//bottom collision
}
if (l_collision < r_collision && l_collision < t_collision && l_collision < b_collision)
{
//Left collision
}
if (r_collision < l_collision && r_collision < t_collision && r_collision < b_collision )
{
//Right collision
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: csharp datetime string format 
Csharp :: c# random string 
Csharp :: set decimal point c# 
Csharp :: base64 string to byte array c# 
Csharp :: unity 3d sound 
Csharp :: unity instantiate 
Csharp :: loan calculator using windows forms in c# code 
Csharp :: how to make a for loop in c# 
Csharp :: convert int to string in linq query c# 
Csharp :: meta keywords tag mvc .net core 
Csharp :: get item from icollection 
Csharp :: how to check is object by this type c# 
Csharp :: how to split list by date c# 
Csharp :: unity3d random 
Csharp :: unity lock cursor to center 
Csharp :: c# split string for all blank character 
Csharp :: c# download string url 
Csharp :: c# reading months as int 
Csharp :: set object to random color unity 
Csharp :: data annotation c# name 
Csharp :: c# datetimepicker set weeks after today 
Csharp :: c# start file 
Csharp :: wpf restart application c# 
Csharp :: unity custom update 
Csharp :: unity random 
Csharp :: unity how to load a scene 
Csharp :: c# socket listen on port 
Csharp :: c# letters only 
Csharp :: c# to binary 
Csharp :: how to add ground Check in unity 3d 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =