Yeah, I'm using core physics. Raycasting might be the solution. Never done that before but "how hard can it be"? Something like this:
IF HITTING STUFF DETECTED BY RAYCAST:
-----STORE DIRECTION AND SPEED OF HIT
-----USE THIS TO PUSH STUFF
Here's the code for the drumsticks I use to hit stuff:
_sticks:
/*===============================================================================
PLAYER STICKS
===============================================================================*/
Global rightStickGlow as float = 0.0
Global leftStickGlow as float = 0.0
ballDiameter as float = 0.11
Global Stick_right as integer
Stick_right = CreateObjectCylinder (0.35, 0.040, 25)
setObjectColor (stick_right, 0, 0, 0, 255)
Global ball_right as integer
ball_right = CreateObjectSphere (ballDiameter, 32, 25)
setObjectColor (ball_right, 0, 0, 0, 255)
Global stick_left as integer
stick_left = cloneObject (Stick_right)
Global ball_left as integer
ball_left = cloneObject (ball_right)
Create3DPhysicsKinematicBody ( ball_right )
Create3DPhysicsKinematicBody ( ball_left )
SetObjectShapeSphere( ball_right, ballDiameter)
SetObjectShapeSphere( ball_left, ballDiameter)
Global leftStick_speed as float
Global rightStick_speed as float
Global average_number as float // higher value = more extreme average ... use whole numbers
average_number = 5.0
Global leftStick_speed_average as float // an averaged value
Global rightStick_speed_average as float // an averaged value
Global velocityTotal as float = 0.0
Global velocityTotalMax as float = 0.0
return
function sticks_something ()
if AGKVR.RightControllerFound( ) = 1
SetObjectPosition ( Stick_right, AGKVR.GetRightHandX(), AGKVR.GetRightHandY(), AGKVR.GetRightHandZ())
SetObjectRotation ( Stick_right, AGKVR.GetRightHandAngleX(), AGKVR.GetRightHandAngleY(), AGKVR.GetRightHandAngleZ())
//MoveObjectLocalX ( Stick_right, 0)
//MoveObjectLocalY ( Stick_right, 0)
MoveObjectLocalZ ( Stick_right, 0.00)
RotateObjectLocalX ( Stick_right, 90.0)
SetObjectPosition ( ball_right, AGKVR.GetRightHandX(), AGKVR.GetRightHandY(), AGKVR.GetRightHandZ())
SetObjectRotation ( ball_right, AGKVR.GetRightHandAngleX(), AGKVR.GetRightHandAngleY(), AGKVR.GetRightHandAngleZ())
MoveObjectLocalZ ( ball_right, 0.22) // how far away from hand (thumb direction)
MoveObjectLocalY ( ball_right, 0.0002) // how far up-down (drumming direction)
endif
if AGKVR.LeftControllerFound( ) = 1
SetObjectPosition ( stick_left, AGKVR.GetLeftHandX(), AGKVR.GetLeftHandY(), AGKVR.GetLeftHandZ())
SetObjectRotation ( stick_left, AGKVR.GetLeftHandAngleX(), AGKVR.GetLeftHandAngleY(), AGKVR.GetLeftHandAngleZ())
//MoveObjectLocalX ( stick_left, 0)
//MoveObjectLocalY ( stick_left, 0)
MoveObjectLocalZ ( stick_left, 0.00)
RotateObjectLocalX ( stick_left, 90.0)
SetObjectPosition ( ball_left, AGKVR.GetLeftHandX(), AGKVR.GetLeftHandY(), AGKVR.GetLeftHandZ())
SetObjectRotation ( ball_left, AGKVR.GetLeftHandAngleX(), AGKVR.GetLeftHandAngleY(), AGKVR.GetLeftHandAngleZ())
MoveObjectLocalZ ( ball_left, 0.22) // how far away from hand (thumb direction)
MoveObjectLocalY ( ball_left, 0.0002) // how far up-down (drumming direction)
endif
// Right stick update
rightStick_speed = sticks_gimmeSpeed(ball_right)
rightStick_speed_average = ((rightStick_speed_average*average_number) + rightStick_speed)/ (average_number+1.0)
rightStickGlow = rightStickGlow + (rightStick_speed_average*2.5)
rightStickGlow = rightStickGlow - 8.0
if rightStickGlow < 0.0 then rightStickGlow = 0.0
if rightStickGlow > 255.0 then rightStickGlow = 255.0
testValF = rightStickGlow // TESTING
SetObjectColorEmissive (stick_right, rightStickGlow, rightStickGlow, rightStickGlow)
SetObjectColorEmissive (ball_right, rightStickGlow, rightStickGlow, rightStickGlow)
SetObjectColor (stick_right, rightStickGlow, rightStickGlow, rightStickGlow, 255)
SetObjectColor (ball_right, rightStickGlow, rightStickGlow, rightStickGlow, 255)
// Left stick update
leftStick_speed = sticks_gimmeSpeed(ball_left)
leftStick_speed_average = ((leftStick_speed_average*average_number) + leftStick_speed)/ (average_number+1.0)
leftStickGlow = leftStickGlow + (leftStick_speed_average*2.5)
leftStickGlow = leftStickGlow - 8.0
if leftStickGlow < 0.0 then leftStickGlow = 0.0
if leftStickGlow > 255.0 then leftStickGlow = 255.0
//testValF = rightStickGlow // TESTING
SetObjectColorEmissive (stick_left, leftStickGlow, leftStickGlow, leftStickGlow)
SetObjectColorEmissive (ball_left, leftStickGlow, leftStickGlow, leftStickGlow)
SetObjectColor (stick_left, leftStickGlow, leftStickGlow, leftStickGlow, 255)
SetObjectColor (ball_left, leftStickGlow, leftStickGlow, leftStickGlow, 255)
sticks_hitbox ( ball_left )
sticks_hitbox ( ball_right )
endfunction
function sticks_hitbox ( theBox as integer )
CheckContact as integer = 0
BallContact as integer = 0
CheckContact = GetObject3DPhysicsFirstContact( theBox )
if CheckContact > 0 // if the ball collides with sometthing
BallContact = GetObject3DPhysicsContactObjectB()
findContact as integer
For findContact = 0 to boxT.length-1
if boxT[findContact].Mesh = BallContact
testStringA = "FOUND: " + str(findContact)
exit
endif
next
if boxT[findContact].is_it_hit = FALSE
boxT[findContact].is_it_hit = TRUE
setObjectColor (BallContact, 0, 255, 255, 255)
//SetObject3DPhysicsMass( BallContact, 0.01 ) // 5.0 seem to be the default
CheckContact = 0
if theBox = ball_right
AGKVR.RightController_TriggerPulse( 0, 1000 )
else
AGKVR.LeftController_TriggerPulse( 0, 1000 )
endif
// Dirty hack to force it to punch forward (Z) on hit
// removed because Gyfanoff
//SetObject3DPhysicsLinearVelocity( boxT[findContact].Mesh, 0.0, 0.0, 1.0, playerForwardForce*DeltaTime*200.0 ) // 100.0 was too little -- 300.0 too much.
getSpeed as float
getSpeed = sticks_gimmeSpeed(theBox)
if getSpeed > 20.0
PlaySound (playE, 40)
elseif getSpeed > 15.0
PlaySound (playD, 35)
elseif getSpeed > 10.0
PlaySound (playC, 30)
elseif getSpeed > 5.0
PlaySound (playB, 20)
else
PlaySound (playA, 10)
endif
endif
endif
endfunction
// TODO - I'm at bit frustrated that it doesn't know if
function sticks_gimmeSpeed (theObject as integer)
if GetObject3DPhysicsLinearVelocityX( theObject ) < 0
velocityTotal = GetObject3DPhysicsLinearVelocityX( theObject ) * -1
else
velocityTotal = GetObject3DPhysicsLinearVelocityX( theObject )
endif
if GetObject3DPhysicsLinearVelocityY( theObject ) < 0
velocityTotal = velocityTotal + GetObject3DPhysicsLinearVelocityY( theObject ) * -1
else
velocityTotal = velocityTotal + GetObject3DPhysicsLinearVelocityY( theObject )
endif
if GetObject3DPhysicsLinearVelocityZ( theObject ) < 0
velocityTotal = velocityTotal + GetObject3DPhysicsLinearVelocityZ( theObject ) * -1
else
velocityTotal = velocityTotal + GetObject3DPhysicsLinearVelocityZ( theObject )
endif
//print (velocityTotal )
if GetSoundsPlaying( WhopFastSnd ) = 0
if velocityTotal > 30.0
playsound(WhopFastSnd, 30)
endif
endif
if velocityTotal > velocityTotalMax then velocityTotalMax = velocityTotal // Simply used to measure the max value
// 28.0 is a fast speed
// 50.0 is about max
endfunction velocityTotal