Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog

ShiVa3D

Return to Game programming

touching on a item  [SOLVED]

All about the StoneScript

touching on a item

Postby juno1990ahn » 02 Jul 2012, 10:45

Hello everyone I just started using Shiva and I am having problems already hehe.

I'm trying to make it so the AI will detect if the model was clicked or not.
I want to use the onTouchSequenceChange but how do I detect if my touch started from
the model and ended at the model without moving out of the model in between?
I want to make sure the user doesn't drag their finger into the object or out of it while triggering my event.

Code: Select all
if (nTaps0)
    then
   
        local camX, camY, camZ  = object.getTranslation ( application.getCurrentUserActiveCamera ( ), object.kGlobalSpace )
        local nRayPntX, nRayPntY, nRayPntZ = camera.unprojectPoint ( application.getCurrentUserActiveCamera ( ), nX0, nY0, 0 )
        local vX,vY,vZ = math.vectorSubtract ( nRayPntX, nRayPntY, nRayPntZ, camX, camY, camZ )
        local nRayDirX,nRayDirY,nRayDirZ = math.vectorNormalize ( vX, vY, vZ )
       

        local hHitObject, nHitDist, nHitSID = scene.getFirstHitSensor( application.getCurrentUserScene ( ), nRayPntX, nRayPntY, nRayPntZ, nRayDirX, nRayDirY, nRayDirZ, 500)
        if  ( hHitObject )
        then
            this.hTouchedObject ( hHitObject)
        end
    end


This is a code I took from another topic and I'm triggering the event in onTouchSequenceEnd if hTouchedObject is not nil
juno1990ahn
Fresh Boarder
Fresh Boarder
 
Posts: 12

Re: touching on a item  [SOLVED]

Postby capiright » 04 Jul 2012, 22:31

I am using the same code but you have to watch it.
Tip 1: have a special sensor ID for tap interactions and use the getFirstHitSensorwithId method.
Tip 2: put a log call in your if call where you validate the target. Then place a log on the touch end and see what's going on
User avatar
capiright
Platinum Boarder
Platinum Boarder
 
Posts: 518

Re: touching on a item

Postby juno1990ahn » 05 Jul 2012, 17:33

Thanks for the tips. I think I got it :)
juno1990ahn
Fresh Boarder
Fresh Boarder
 
Posts: 12


Return to Game programming

cron