Skip to content

Commit b0ca3a5

Browse files
authored
[Community] [3D raycast] Add a condition to cast from the cursor (#1603)
1 parent fc8c1eb commit b0ca3a5

File tree

1 file changed

+61
-2
lines changed

1 file changed

+61
-2
lines changed

extensions/community/Raycaster3D.json

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
"author": "",
33
"category": "General",
44
"extensionNamespace": "",
5-
"gdevelopVersion": ">=5.5.222",
65
"fullName": "3D raycast",
6+
"gdevelopVersion": ">=5.5.222",
77
"helpPath": "",
88
"iconUrl": "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0ibWRpLXJheS1zdGFydC1hcnJvdyIgd2lkdGg9IjI0IiBoZWlnaHQ9IjI0IiB2aWV3Qm94PSIwIDAgMjQgMjQiPjxwYXRoIGQ9Ik0yMywxMkwxOSwxNlYxM0g2LjgzQzYuNDIsMTQuMTcgNS4zMSwxNSA0LDE1QTMsMyAwIDAsMSAxLDEyQTMsMyAwIDAsMSA0LDlDNS4zMSw5IDYuNDIsOS44MyA2LjgzLDExSDE5VjhMMjMsMTJaIiAvPjwvc3ZnPg==",
99
"name": "Raycaster3D",
1010
"previewIconUrl": "https://asset-resources.gdevelop.io/public-resources/Icons/8419f46b76bce482c14b4c03b4141a64d457e4cdc92686f3470381f5d2694abd_ray-start-arrow.svg",
1111
"shortDescription": "Find 3D objects that cross a line.",
12-
"version": "0.1.4",
12+
"version": "0.1.5",
1313
"description": [
1414
"It can be useful to:",
1515
"- Find 3D objects under the pointer",
@@ -29,6 +29,8 @@
2929
"IWykYNRvhCZBN3vEgKEbBPOR3Oc2"
3030
],
3131
"dependencies": [],
32+
"globalVariables": [],
33+
"sceneVariables": [],
3234
"eventsFunctions": [
3335
{
3436
"fullName": "",
@@ -496,6 +498,63 @@
496498
],
497499
"objectGroups": []
498500
},
501+
{
502+
"description": "Sends a ray from the cursor on the camera screen, intersecting the closest object. The intersected object will become the only one taken into account.",
503+
"fullName": "Raycast from cursor",
504+
"functionType": "Condition",
505+
"group": "Collision",
506+
"name": "RaycastFromCameraCursor",
507+
"sentence": "Cast a ray from the cursor on 2D layer: _PARAM2_ to a maximum distance of _PARAM3_ against _PARAM1_",
508+
"events": [
509+
{
510+
"type": "BuiltinCommonInstructions::JsCode",
511+
"inlineCode": [
512+
"const { camera, input } = gdjs.evtTools;",
513+
"",
514+
"const layer2D = eventsFunctionContext.getArgument(\"Layer2D\");",
515+
"",
516+
"const cameraMinX = camera.getCameraBorderLeft(runtimeScene, layer2D, 0);",
517+
"const cameraMaxX = camera.getCameraBorderRight(runtimeScene, layer2D, 0);",
518+
"const cameraMinY = camera.getCameraBorderTop(runtimeScene, layer2D, 0);",
519+
"const cameraMaxY = camera.getCameraBorderBottom(runtimeScene, layer2D, 0);",
520+
"",
521+
"const cursorX = input.getCursorX(runtimeScene, layer2D, 0);",
522+
"const cursorY = input.getCursorY(runtimeScene, layer2D, 0);",
523+
"",
524+
"eventsFunctionContext.returnValue =",
525+
" gdjs.__raycaster3DExtension.raycaster.recastFromCamera(",
526+
" eventsFunctionContext.getObjectsLists(\"Object\"),",
527+
" objects,",
528+
" (cursorX - cameraMinX) / (cameraMaxX - cameraMinX),",
529+
" (cursorY - cameraMinY) / (cameraMaxY - cameraMinY),",
530+
" eventsFunctionContext.getArgument(\"DistanceMax\")",
531+
" );",
532+
""
533+
],
534+
"parameterObjects": "Object",
535+
"useStrict": true,
536+
"eventsSheetExpanded": true
537+
}
538+
],
539+
"parameters": [
540+
{
541+
"description": "Objects to test against the ray",
542+
"name": "Object",
543+
"type": "objectList"
544+
},
545+
{
546+
"description": "2D layer",
547+
"name": "Layer2D",
548+
"type": "layer"
549+
},
550+
{
551+
"description": "Ray maximum distance (in pixels)",
552+
"name": "DistanceMax",
553+
"type": "expression"
554+
}
555+
],
556+
"objectGroups": []
557+
},
499558
{
500559
"description": "the last recast intersection distance.",
501560
"fullName": "Last recast distance",

0 commit comments

Comments
 (0)