Hi All
Being 100% new to 3D I am tinkering around at the moment ,
was looking for a collision between say one bullet and some objects , in this case rectangle boxes
I have used the ObjectSphereCast command , but not 100% accurate , did try the raycast command but could not get that perfect either
wonder if someone knew the right way of doing it without using the physics commands
thought also this would come in handy to all newbies that are having trouble with Object hit detection's
use the WSAD to move small box ( bullet ) the hit rectangles will change to red once hit
if moving bullet left to right the detection seems fine , but as using a sphere detection when moving up and down in a corner of an object
the detection is a bit late , has to overlap a bit.
Thanks
Mick
// Project: 3d collision test
// Created: 2016-06-04
// set window properties
SetVirtualResolution(1280,800)
SetWindowSize( 1280, 800, 0 )
SetDisplayAspect(16.0 / 10.0)
SetScissor(0,0,0,0)
SetOrientationAllowed( 1, 1, 1, 1 )
SetCameraPosition(1,0,0,-150)
SetCameraLookAt(1,0,0,0,0)
type pair
id
x#
y#
endtype
dim boxes[9] as pair
// make our moveable box ( box 1 )
boxes[1].id=1
CreateObjectBox(boxes[1].id,10,10,5)
SetObjectColor(boxes[1].id,255,255,255,100)
SetObjectPosition(boxes[1].id,-90,0,0)
SetObjectCollisionMode(boxes[1].id,0)
// make 8 still rectangles 2-9
for a=2 to 9
boxes[a].id=a
CreateObjectBox(boxes[a].id,10,30,10)
SetObjectColor(boxes[a].id,255,255,255,100)
SetObjectPosition(boxes[a].id,-90+a*20,0,0)
next a
// set the radius of the sphere
radius=5
do
// get player input
joystick_y# = GetJoystickY()*-1
MoveObjectLocalY(boxes[1].id,joystick_y#)
joystick_x# = GetJoystickX()*1
MoveObjectLocalx(boxes[1].id,joystick_x#)
// get postition of box 1
old_x# = GetObjectX(boxes[1].id)
old_y# = GetObjectY(boxes[1].id)
old_z# = GetObjectZ(boxes[1].id)
new_x# = GetObjectX(boxes[1].id)
new_y# = GetObjectY(boxes[1].id)
new_z# = GetObjectZ(boxes[1].id)
// see if box 1 radius wonders into any of the rectangles (2-9)
for a=2 to 9
object_hit = ObjectSphereCast(boxes[a].id,old_x#,old_y#,old_z#,new_x#,new_y#,new_z#,radius)
if object_hit>0
SetObjectColor(boxes[a].id,255,0,0,255)
else
SetObjectColor(boxes[a].id,255,255,255,255)
endif
next a
sync()
loop