Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog

ShiVa3D

Return to Game programming

Directional Controls help needed  [SOLVED]

All about the StoneScript

Directional Controls help needed

Postby James92190 » 24 May 2012, 19:40

I have a very basic game with a ball that moves through a maze. I finally got the arrow keys to be the controls over the ball and I have a Camera that follows behind the ball, I called it a ChaseCam. I want to be able to get the controls to be from the view of the camera.
James92190
Fresh Boarder
Fresh Boarder
 
Posts: 17

Re: Directional Controls help needed

Postby freezer » 24 May 2012, 20:31

either get a handle to the cam and apply your transforms to that or do it in its own ai...

but basically its exactly the same, only doing it too the cam, but then youll need to manage the ball...
freezer
Gold Boarder
Gold Boarder
 
Posts: 216

Re: Directional Controls help needed  [SOLVED]

Postby James92190 » 24 May 2012, 20:38

Currently, I have the MainAI wrote like this...
Code: Select all
--------------------------------------------------------------------------------
--  Handler.......... : onKeyboardKeyDown
--  Author........... :
--  Description...... :
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
function MainAI.onKeyboardKeyDown ( kKeyCode )
--------------------------------------------------------------------------------
   
local hBall = application.getCurrentUserSceneTaggedObject ( "Ball" )
    if ( hBall )
    then
   if (kKeyCode == input.kKeyUp) then
        object.sendEvent ( hBall, "BallAI", "onMoveForward", true )
        log.message ( "key up" )
        --1 forward, 0 stand still, -1 backward
    elseif (kKeyCode == input.kKeyDown) then
        object.sendEvent ( hBall, "BallAI", "onMoveBackward", true )
        log.message ( "key Down" )
        --1 forward, 0 stand still, -1 backward
    elseif (kKeyCode == input.kKeyLeft) then
        object.sendEvent ( hBall, "BallAI", "onMoveLeft", true )
        log.message ( "key Left" )
        --1 forward, 0 stand still, -1 backward
    elseif (kKeyCode == input.kKeyRight) then
        object.sendEvent ( hBall, "BallAI", "onMoveRight", true )
        log.message ( "key Right" )
        --1 forward, 0 stand still, -1 backward
    end
end
   
--------------------------------------------------------------------------------
end
--------------------------------------------------------------------------------



and under my BallAI...I have it wrote like this...

Code: Select all
if( not this.bInPlay ( ) ) then
        dynamics.enableDynamics ( this.hBall ( ), true )
        dynamics.addLinearImpulse ( this.hBall ( ), 0, 0, -this.nImpulse ( ), object.kGlobalSpace )
        this.bInPlay ( true )
    end
   
    if( this.bInPlay ( ) ) then
        dynamics.enableDynamics ( this.hBall ( ), true )
        dynamics.addLinearImpulse ( this.hBall ( ), 0, 0, -this.nImpulse ( ), object.kGlobalSpace )
        this.bInPlay ( true )
    end


And right, left, and backward are basically the same. I dont know how else to right it. my camera is as follows....

Code: Select all
if( dynamics.isIdle ( this.hTarget ( ) ) ) then
   
    else
        local targetX, targetY, targetZ = object.getTranslation ( this.hTarget ( ), object.kGlobalSpace )
        local vX, vY, vZ = dynamics.getLinearVelocity ( this.hTarget ( ), object.kGlobalSpace )
       
        vX, vY, vZ = math.vectorNormalize ( vX, vY, vZ )
        vX, vY, vZ = math.vectorScale ( vX, vY, vZ, -10 )
        local x,y,z = math.vectorAdd ( targetX, targetY, targetZ, vX, vY, vZ )
       
        object.translateTo ( this.hCam ( ), x,y,z, object.kGlobalSpace, 0.2 )
        object.lookAt ( this.hCam ( ), targetX, targetY, targetZ, object.kGlobalSpace, 0.2 )
    end
James92190
Fresh Boarder
Fresh Boarder
 
Posts: 17

Re: Directional Controls help needed

Postby freezer » 24 May 2012, 20:43

q. is the ball just turning the wrong way?
freezer
Gold Boarder
Gold Boarder
 
Posts: 216

Re: Directional Controls help needed

Postby James92190 » 24 May 2012, 20:47

when you load up the scene, the ball moves in the x, y, z directions of the ground, but i want it to move in the direction from the view of the camera. The camera stays behind the ball. example: when I hit up arrow, the ball moves -z direction, when i hit down arrow, its z direction, it does that no matter what direction the camera is facing. I would like to make it so that the up arrow is going forward at all times from the view of the camera and so on.
James92190
Fresh Boarder
Fresh Boarder
 
Posts: 17

Re: Directional Controls help needed

Postby freezer » 24 May 2012, 20:50

are you rotating the ball on left and right press?
freezer
Gold Boarder
Gold Boarder
 
Posts: 216

Re: Directional Controls help needed

Postby James92190 » 24 May 2012, 20:53

Currently no. I would like to get the movement down first, then i was going to worry about the rotation of the ball.
James92190
Fresh Boarder
Fresh Boarder
 
Posts: 17

Re: Directional Controls help needed

Postby freezer » 24 May 2012, 21:22

unless you rotate it will be just +/- z
freezer
Gold Boarder
Gold Boarder
 
Posts: 216

Re: Directional Controls help needed

Postby James92190 » 24 May 2012, 22:14

rotate it how exactly?
James92190
Fresh Boarder
Fresh Boarder
 
Posts: 17


Re: Directional Controls help needed

Postby James92190 » 24 May 2012, 22:33

and this would go under the camera's AI right? or the BallAI?
James92190
Fresh Boarder
Fresh Boarder
 
Posts: 17

Re: Directional Controls help needed

Postby freezer » 24 May 2012, 22:47

you are wanting to rotate the ball
freezer
Gold Boarder
Gold Boarder
 
Posts: 216

Re: Directional Controls help needed

Postby James92190 » 25 May 2012, 13:34

I got the ball to rotate, and the controls are a lot smoother, but they controls are still not controlled from the camera's view point.
James92190
Fresh Boarder
Fresh Boarder
 
Posts: 17


Return to Game programming