Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: Updating movement and rotation for Actor Object in a Landscape...  (Read 292 times)
masmas
Community Member
*
Posts: 20


« on: May 04, 2008, 02:23:33 AM »

Hi all this is my first post i hope this will help u developing your games...  Grin

Ok if u need an Actor that move with arrows when up and down make the actor go forward and backward but left and right will make the actor rotate right and rotate left also we will need the camara do it the same to make it feel simple to move arround in the landscape.

The code is c# and works with 6.5 version, we use the fuction Check_Input posting in the tutorials of truevision3D. Our TVActor object is called "jugador" we asume that actor is load and tvengine presets are allready done


-------------------------------------------------------------------------------------------
//============================================================================
//          Writing by M@S++ (mas_more@hotmail.com) April 18
//============================================================================
//Actors moves bool vars
        bool bAnyKey = false;   //To know what our actor is doing
        bool bRun = false;      //To know if the actor is running
        bool bRot = false;      //To know if the actor is rotating
        bool bKick = false;     //To know if the actor is shooting, kicking or whatever
        bool bHitHer = false;   //To know if the actor had been hit, for future use
        bool bMuerto = false;   //To know if the actor is death
        bool bParar = false;    //To know if the actor is doing nothing
        //Angle of we rotate
        float ang=0f;
------------------------------------------------------------------------------------------


        //THIS IS THE CHECK INPUT FUCTION
        //Forgive me if i use spanglish(spanish and english) in my variables :p
        //We will first make changes to Check_Imput to make it more simple to move
        private void Check_Input()
        {
            //We will need a bool var to know is the actor have been kill
            //we will use it in the future
            if (!bMuerto)
            {
                //We will need another bool var to know is the actor had been hit
                if (!bHitHer)
                {
                    //To rotate left we will need to add and Angle float
                    //var to incremet to movement
                    //Rotar a la derecha
                    if(InputEngine.IsKeyPressed(CONST_TV_KEY.TV_KEY_LEFT))
                    {
                        ang = ang + (float)TV.TimeElapsed() * 0.002f;
                        //We will need to know that the actor is not running
                        //but we set in false the bool var so is going to enter
                        //the important thing to know here if is the actor rotating
                        if (!bRun)
                        {
                            //Now we kwon the actor is gona rotate
                            //so we make it more realistic change it the animation
                            if (!bRot)
                            {
                                jugador.SetAnimationByName("walk2");
                                jugador.PlayAnimation();
                            }
                       
                        }
                        //We will need a var to know is the actor stop moving
                        bParar = false;
                        //We use anykey to know what is happening in the loop of the game
                        bAnyKey = true;
                        //To make it realistic and don't had crapy animation
                        //move we know now that the actor is rotate
                        bRot = true;                   
                    }

                    //For the other side we do the same
                    //thing but add a minus to go the other way
                    //Rotar a la izquierda
                    if (InputEngine.IsKeyPressed(CONST_TV_KEY.TV_KEY_RIGHT))
                    {
                        ang = ang - (float)TV.TimeElapsed() * 0.002f;
                        if (!bRun)
                        {
                            if (!bRot)
                            {
                                jugador.SetAnimationByName("walk2");
                                jugador.PlayAnimation();
                            }

                        }
                        bParar = false;
                        bAnyKey = true;
                        bRot = true; 
                   
                    }
                    /*Okay if the actor is not doing rotation maybe is runing up
                    and down we update the position in X and Z we will use
                    Math function Sin and Cos because landscape aren't flat
                    //Ir adelante*/
                    if (InputEngine.IsKeyPressed(CONST_TV_KEY.TV_KEY_UP))
                    {
                        //feel free to change to rotation point to make faster or slower
                        sngPositionX = sngPositionX +
                        (float)(TV.TimeElapsed() * Math.Cos(ang) * 0.12);
                        sngPositionZ = sngPositionZ +
                        (float)(TV.TimeElapsed() * Math.Sin(ang) * 0.12);
                        //We start the run variable to know we where running
                        if (!bRun)
                        {
                            //Don't forge to change animation to make it realistic
                            jugador.SetAnimationByName("run2");
                            jugador.PlayAnimation();
                           
                        }
                        //We turn the bool variables to know what is happend to our actor
                        bParar = false;
                        bAnyKey = true;
                        bRun = true;

                    }
                    //We do the same for the backword
                    if (InputEngine.IsKeyPressed(CONST_TV_KEY.TV_KEY_DOWN))
                    {
                        sngPositionX = sngPositionX -
                                      (float)(TV.TimeElapsed() * Math.Cos(ang) * 0.12);
                        sngPositionZ = sngPositionZ -
                                      (float)(TV.TimeElapsed() * Math.Sin(ang) * 0.12);
                        if (!bRun)
                        {
                            jugador.SetAnimationByName("run2");
                            jugador.PlayAnimation();

                        }
                        bParar = false;
                        bAnyKey = true;
                        bRun = true;

                    }

                    //Probably you will need the actor to
                    //shoot, kick, punch or whatever u imagine. u can repet the bool vars
                    //to make the actor do more this u can make it
                    //better is use swicth for
                    //cases i use bools because they are easy to understand
                    //I make mine actor do a kick
                    if(InputEngine.IsKeyPressed(CONST_TV_KEY.TV_KEY_SPACE))
                    {
                        //We use another bool var for know it is kicking
                        if(!bKick)
                        {
                            //we change the animation for realistic looks
                            jugador.SetAnimationByName("circkick");
                            jugador.PlayAnimation();
                       
                        }
                        //don't forget to set your vars and tell
                        //the loop what is happening to our actor
                        bParar = false;
                        bAnyKey = true;
                        bKick = true;
                       
                    }
                    //Si no presionar ninguna tecla parar
                    //Ok if we are not doing anything with the
                    //actor we change animation for an stand animation
                    if (!bAnyKey)
                    {
                        if (!bParar)
                        {
                            jugador.SetAnimationByName("standard_idle");
                            jugador.PlayAnimation();
                       
                        }
                        //we know the actor is not doing anything so we start
                        bParar = true;
                        bRun = false;
                        bRot = false;
                        bKick = false;
                    }
               
                }
           
           
            }
}
-------------------------------------------------------------------------------------------
//Each time your game loop is running you will need to start anykey
// We loop all of this while the DoLoop is True.
        private void Main_Loop()
        {

            // The main loop

            // We loop all of this while the DoLoop is True.
            while (DoLoop == true)
            {

                bAnyKey = false;

Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks