C
C#4mo ago
HouseAdmin

syntax for c# to do this math.

function checkCollision(a, b)
--With locals it's common usage to use underscores instead of camelCasing
local a_left = a.x
local a_right = a.x + a.width
local a_top = a.y
local a_bottom = a.y + a.height

local b_left = b.x
local b_right = b.x + b.width
local b_top = b.y
local b_bottom = b.y + b.height

--Directly return this boolean value without using if-statement
return a_right > b_left
and a_left < b_right
and a_bottom > b_top
and a_top < b_bottom
end
function checkCollision(a, b)
--With locals it's common usage to use underscores instead of camelCasing
local a_left = a.x
local a_right = a.x + a.width
local a_top = a.y
local a_bottom = a.y + a.height

local b_left = b.x
local b_right = b.x + b.width
local b_top = b.y
local b_bottom = b.y + b.height

--Directly return this boolean value without using if-statement
return a_right > b_left
and a_left < b_right
and a_bottom > b_top
and a_top < b_bottom
end
14 Replies
HouseAdmin
HouseAdminOP4mo ago
Im trying to do this in c#, but I dont know what the syntax for it is right now what i got is
c#
static int DetectCollision(Object a,Object b)
{
private int a_left = a.x;

}
c#
static int DetectCollision(Object a,Object b)
{
private int a_left = a.x;

}
Edited
m!ke
m!ke4mo ago
Comments use // in c# (though /**/ for multilines). Give a and b type declarations. Make the method return type a bool, as it uses logic operator. The logic operator for and is &&. I assume “object” in your example code is a placeholder name. You should make it an actual rectangle class/struct, though I assume that is what you mean’t
HouseAdmin
HouseAdminOP4mo ago
thanks be to GOD random person, i thought it was returning int, but i didnt read the comments haha object is for things like player object in my code im gonna check collision between two objects for the method im gonna be using
m!ke
m!ke4mo ago
Did you name a class “Object”?
HouseAdmin
HouseAdminOP4mo ago
no
m!ke
m!ke4mo ago
Ah okay. Then you’re good
HouseAdmin
HouseAdminOP4mo ago
it gives the error
ColiisionRelated.DetectCollision(object, object)': not all code paths return a value
ColiisionRelated.DetectCollision(object, object)': not all code paths return a value
c#
static bool DetectCollision(Object a,Object b)
{
private int a_left = a.x;

}
c#
static bool DetectCollision(Object a,Object b)
{
private int a_left = a.x;

}
for this
m!ke
m!ke4mo ago
Also, access modifiers cannot be used within methods. Simply do: int myInt = 0; Well, you gotta complete the pseudo code
HouseAdmin
HouseAdminOP4mo ago
thanks be to GOD person yeah i was guessing that too but i wasnt sure well thanks be to GOD random person for helping me i will closethe thread now
m!ke
m!ke4mo ago
No worries. Glad I could help. :)
Angius
Angius4mo ago
Also, chances are you don't want to use Object but rather a concrete type
HouseAdmin
HouseAdminOP4mo ago
I thought thats what objects do? i mean are you make objects out of classes using new
Angius
Angius4mo ago
Well, yes You make a class And you instantiate it And wherever is supposed to use that instance, uses that class as the type What you have here is the System.Object type, though, which is basically an any type Unless... you made your own class that's named Object, in which case I'd probably reconsider that name
HouseAdmin
HouseAdminOP4mo ago
i see thanks be to GOD random person
Want results from more Discord servers?
Add your server