Diagonal collision line
-
Looking to find a way to create a diagonal/slope collision line in a 2dgame
Between points y.x to y.x -
@waldron Hey mate, good challenge to solve!
What are you wanting to happen when the collision occurs? Assuming this is for a ramp / jump?
The approach will depend on how you are currently handling input, managing your player and scene variables
-
@Tratax I'm using a separate collision array
Wanting to add in sloped rails, slopes and ramps.
I use col and row I'm guessing and plot the points and how I want the player to behave on those points but coding it is the dilemma... -
is there a way i could plot an invisible triangle with collision on my screen that my player will hit ?
-
there's only one way i can make this work,
collision is based on the tile size
i have 3 arrays for my levels
1 being collision 2 being background 3 being foreground
if i decrease my tile size to 1 then it will work but really dont want to go down this route if theres a better way?doing that way will only work on down slopes as my character passes through vertical tiles (side on) another thing i have to address
-
I don't know if this is what you're looking for but here is a simple function that can detect if a circle and a line segment collide/intersect:
// A, B = line segment endpoints // C = center of circle // r = circle radius function segmentCircleIntersect(A, B, C, r) u = B - A v = C - A t = clamp(dot(u, v) / dot(u, u), 0, 1) P = A + t * u d = distance(C, P) return d < r
-
@sahara-min thankyou il give this a go i pretty much abandoned hope but i can see this working