Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Diagonal collision line

    Coding
    3
    7
    425
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • waldron
      waldron F last edited by

      Looking to find a way to create a diagonal/slope collision line in a 2dgame
      Between points y.x to y.x

      Tratax 1 Reply Last reply Reply Quote 0
      • Tratax
        Tratax F @waldron last edited by

        @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

        waldron 1 Reply Last reply Reply Quote 0
        • waldron
          waldron F @Tratax last edited by

          @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...

          1 Reply Last reply Reply Quote 0
          • waldron
            waldron F last edited by

            is there a way i could plot an invisible triangle with collision on my screen that my player will hit ?

            1 Reply Last reply Reply Quote 0
            • waldron
              waldron F last edited by waldron

              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

              1 Reply Last reply Reply Quote 0
              • sahara-min
                sahara-min last edited by

                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
                
                waldron 1 Reply Last reply Reply Quote 4
                • waldron
                  waldron F @sahara-min last edited by

                  @sahara-min thankyou il give this a go i pretty much abandoned hope but i can see this working

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post