May 19, 2018 at 8:56 am #14658
Does MX2 have any raycasting functions and if not how would one go about coding one, both for 2d and 3d?May 19, 2018 at 12:17 pm #14659
Chipmunk has 2d raycasting, and also my own timelinefx has collisions with a raycasting function, there’s an example in the samples folder. Not sure about mojo3d but it uses bullet which must have raycasting functions built into it?May 19, 2018 at 12:56 pm #14660
Would I need to import chipmunk, timeline or bullet to access these? If so then, well, it would do what I need, but, I was hoping for a solution that was part of mojo that doesn’t need any extra imports.May 22, 2018 at 1:39 am #14677
For 2D I just use Bresenham Line on an array.
This is MX1 code but you should be able to convert it, it will return an int of a map array (eg the tile):Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172Method CheckCollision:Int(startX:Float, startY:Float, endX:Float, endY:Float)' use Bresenham LineLocal x1:Int = startXLocal y1:Int = startYLocal x2:Int = endXLocal y2:Int = endYLocal deltax:Int = Abs(x2 - x1)Local deltay:Int = Abs(y2 - y1)Local numpixels:Int, d:Int, dinc1:Int, dinc2:Int, xinc1:Int, xinc2:Int, yinc1:Int, yinc2:Int, x:Int, y:Int, i:IntLocal xx:Int, cx:IntLocal yy:Int, cy:IntLocal tile:IntIf deltax >= deltaynumpixels = deltax + 1d = (2 * deltay) - deltaxdinc1 = deltay Shl 1dinc2 = (deltay - deltax) Shl 1xinc1 = 1xinc2 = 1yinc1 = 0yinc2 = 1Elsenumpixels = deltay + 1d = (2 * deltax) - deltaydinc1 = deltax Shl 1dinc2 = (deltax - deltay) Shl 1xinc1 = 0xinc2 = 1yinc1 = 1yinc2 = 1EndIf x1 > x2xinc1 = -xinc1xinc2 = -xinc2EndIf y1 > y2yinc1 = -yinc1yinc2 = -yinc2Endx = x1y = y1For i = 1 To numpixelsxx = Floor(x / TILE_WIDTH)yy = Floor(y / TILE_HEIGHT)tile = map[yy][xx]' exit when we have a collisionIf tile <> 0 Thencx = xcy = yExitEndIf d < 0d = d + dinc1x = x + xinc1y = y + yinc1Elsed = d + dinc2x = x + xinc2y = y + yinc2EndNextReturn tileEndMay 22, 2018 at 2:48 am #14678
you can do it with box2d too.
box2d is not in the form of a module now but it works fine.. the module should be there soonish.
just download the box2d fork and build these to see it working:
Edit: you are looking for a non imort solution so therevils’ code should be better!
You must be logged in to reply to this topic.