Movatterモバイル変換


[0]ホーム

URL:


Defold logo




Ray casts

Ray casts are used to read the physics world along a linear ray. To cast a ray into the physics world, you provide a start and end position as well asa set of collision groups to test against.

If the ray hits a physics object you will get information about the object it hit. Rays intersect with dynamic, kinematic and static objects. They do not interact with triggers.

functionupdate(self,dt)-- request ray castlocalmy_start=vmath.vector3(0,0,0)localmy_end=vmath.vector3(100,1000,1000)localmy_groups={hash("my_group1"),hash("my_group2")}localresult=physics.raycast(my_start,my_end,my_groups)ifresultthen-- act on the hit (see 'ray_cast_response' message for all values)print(result.id)endend

Ray casts will ignore collision objects that contain the starting point of the ray. This is a limitation in Box2D.


[8]ページ先頭

©2009-2025 Movatter.jp