how to make a character move?

All about the core api and animation, input, sound, effect, collision and physics engines.
You can also post here your feature requests.

Moderator: Brume Dev Team

how to make a character move?

Postby rubbish on Mon Nov 06, 2006 7:51 am

move speed? turn left or right?
rubbish
Brume user
 
Posts: 183
Joined: Fri Nov 03, 2006 5:05 am

Postby Silmaryls on Mon Nov 06, 2006 9:02 pm

This is an interesting question.

Here is one way to do it :


Code: Select all
human.AnimationStates.PlayMode = BrumeAnimationParams.PLAY_LOOP;
// move
if (BrumeKeyboard.IsPressed(BrumeKey.W))
{
    // if !walking and !running
    if (human.Animation != animations[ANIM_WALK_start] && human.Animation != animations[ANIM_WALK_player] && human.Animation != animations[ANIM_run_player])
    {
        human.Animation = animations[ANIM_WALK_start];
    }
}
else if (BrumeKeyboard.IsPressed(BrumeKey.S))
{
    // if !walking & ! running
    if (human.Animation != animations[ANIM_walk_start_back] && human.Animation != animations[ANIM_walk_back] && human.Animation != animations[ANIM_run_back])
    {
        human.Animation = animations[ANIM_walk_start_back];
    }
}
else if (BrumeKeyboard.IsPressed(BrumeKey.A))
{
    // if not walking left
    if (human.Animation != animations[ANIM_walk_left] && human.Animation != animations[ANIM_run_left])
    {
        if (running)
        {
            human.Animation = animations[ANIM_run_left];
        }
        else
        {
            human.Animation = animations[ANIM_walk_left];
        }
    }
}
else if (BrumeKeyboard.IsPressed(BrumeKey.D))
{
    // if not walking right
    if (human.Animation != animations[ANIM_walk_right] && human.Animation != animations[ANIM_run_right])
    {
        if (running)
        {
            human.Animation = animations[ANIM_run_right];
        }
        else
        {
            human.Animation = animations[ANIM_walk_right];
        }
    }
}
else // no keys
{
    if (human.Animation != animations[ANIM_IDLE_stance])
    {
        human.Animation = animations[ANIM_IDLE_stance];

        // update pos en fontion du root object
        human.UpdatePos(inCar, car);
    }
}
// direction
BrumeVector newDir = camera5.Dir;
newDir.Y = 0.0f;
newDir.Normalize();
human.Orient(newDir, human.Up);


The source is from the GTA Vice City like projet. It quite old now but still interesting.
You can find the entire project here.

It shows how to use LOD, human animations, car physics, dynamic level loading and more. The more interesting to me was that it was really fast and without occlusion culling and streaming.

Once the animation is choosen you will need an event handler to update player's position :

Code: Select all
public void HumanAnimationEnd(BrumeObject sender)
{
    if (sender.Animation != null)
    {
        switch (sender.Animation.Name)
        {
            case "run_player": break;
            case "WALK_player": break;
            case "WALK_start": if (running) sender.Animation = animations[ANIM_run_player]; else sender.Animation = animations[ANIM_WALK_player]; break;
            case "walk_start_back": if (running) sender.Animation = animations[ANIM_run_back]; else sender.Animation = animations[ANIM_walk_back]; break;
            case "Run_stop": break;
            case "run_back": break;
            case "walk_back": break;

        }

        // update pos en fontion du root object
        if (!inCar)
        {
            human.UpdatePos(inCar, car);
        }
    }
}       
User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France

Postby rubbish on Tue Nov 07, 2006 1:20 am

hahaha~
that's what i want~
thx very much
rubbish
Brume user
 
Posts: 183
Joined: Fri Nov 03, 2006 5:05 am

Postby rubbish on Tue Nov 07, 2006 7:31 am

but...
where is the animation files &media files :cry: :cry:
i can't run the GTA Vice City like projet
rubbish
Brume user
 
Posts: 183
Joined: Fri Nov 03, 2006 5:05 am

Postby Silmaryls on Tue Nov 07, 2006 7:41 am

hehe it's normal...Vice City is a commercial game. When I said Vice City clone I was wrong. In fact the prject is reusing Gta objects.
So you will have to buy the game in order to run the project.

If you got the game you must unpack gta.img file using some tool like ImgTool.
Then modify the img paths in the project (should be just one) and run !

If you dont't have the game you can still out the source code and replace the objects by yours.
User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France

Postby rubbish on Tue Nov 07, 2006 8:17 am

for example
i press "w"
the tiny walk forward ,what's the walk speed?
press " d" then turn right and continue forward?how to do that? :roll:
rubbish
Brume user
 
Posts: 183
Joined: Fri Nov 03, 2006 5:05 am

Postby Silmaryls on Tue Nov 07, 2006 9:12 am

You have to compute the speed in a variable.
Tiny's forward animation doesn't include translation keys (if your are using the same model as me).
You will also have to compute a position change for the same reason. You can use the MoveScene method with something like that :

Code: Select all

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace Brume.Tests
{
    public class Sample : Brume
    {
        private BrumeFPSCamera camera1 = null;
        private BrumeLight directionalLight = null;
        private BrumeLightedObject tiny = null;


        public Sample() : base()
        {
            BrumeFileManager.AddDirForAll("../../../Data/Internal");
            BrumeFileManager.AddDirForAll("../../Data");
        }


        override protected void GameInit()
        {
            camera1 = new BrumeFPSCamera(this, "camera1", new BrumeVector(0, 0, -5.0f), new BrumeVector(0.0f, 0.0f, 1.0f), new BrumeVector(0.0f, 1.0f, 0.0f));
            this.SetActiveCamera(camera1);
            this.BufferClearColor = Color.Black;
            this.GlobalAmbientLight = Color.FromArgb(255, 100, 100, 100);

            directionalLight = new BrumeDirectionalLight(this, "Directionnal Light", new BrumeVector(-1.0f, -1.0f, 1.0f), new BrumeVector(-1.0f, 1.0f, 1.0f), Color.FromArgb(255, 170, 170, 170));
            directionalLight.Specular = Color.FromArgb(255, 255, 255, 255);
            directionalLight.Enabled = true;
            directionalLight.Update();

            BrumeXMesh tinyMesh = new BrumeXMesh(this, "tiny", "tiny_4anim.x", false);
            BrumeAnimationManager.AddAnimationsFromMesh(tinyMesh);
            tiny = new BrumeLightedObject(this, "tiny");
            tiny.Animation = BrumeAnimationManager.GetAnimation("Wave");
            tiny.Mesh = tinyMesh;
            tiny.Size = 0.005f;
            tiny.Pos.Y = -1.5f;
            tiny.Pos.Z = 5.0f;
            tiny.Orient(new BrumeVector(0, 1, 0), new BrumeVector(0, 0, 1));
        }


        static float moveSpeed = 100.0f;
        static float factor = 0.01f;

        protected override void MoveScene(float fElapsedTime)
        {
            directionalLight.Update();

            // Tiny moves

            if (BrumeKeyboard.IsPressed(BrumeKey.UpArrow))
            {
                if (tiny.Animation == null || tiny.Animation.Name != "Walk")
                {
                    tiny.Animation = BrumeAnimationManager.GetAnimation("Walk");
                }
                tiny.Orient(new BrumeVector(0, 1, 0), new BrumeVector(0, 0, -1));
                tiny.Pos += -tiny.Up * factor; // factor is move speed in this case
            }
            else if (BrumeKeyboard.IsPressed(BrumeKey.RightArrow))
            {
                if (tiny.Animation == null || tiny.Animation.Name != "Walk")
                {
                    tiny.Animation = BrumeAnimationManager.GetAnimation("Walk");
                }
                tiny.Orient(new BrumeVector(0, 1, 0), new BrumeVector(-1, 0, 0));
                tiny.Pos += -tiny.Up * factor; // factor is move speed in this case
            }
            else
            {
                if (tiny.Animation == null || tiny.Animation.Name != "Wave")
                {
                    tiny.Animation = BrumeAnimationManager.GetAnimation("Wave");
                    tiny.Orient(new BrumeVector(0, 1, 0), new BrumeVector(0, 0, 1));
                }
            }
           

            // FPS camera move
            BrumeFPSCamera camera = (BrumeFPSCamera)this.ActiveCamera;

            if (camera != null && (this.DebugConsole.debugLevel != 2 || BrumeKeyboard.IsPressed(BrumeKey.Space)))
            {
                camera.FPSOrient((float)MouseDeltaX / (float)2, (float)MouseDeltaY / (float)2);

                // 5 - moving
                if (MouseDeltaZ > 0.0f)
                    moveSpeed *= 0.5f;
                else
                    if (MouseDeltaZ < 0.0f)
                        moveSpeed /= 0.5f;


                if (BrumeKeyboard.IsPressed(BrumeKey.W))
                    camera.FPSMove(camera.Dir * (fElapsedTime / moveSpeed));
                if (BrumeKeyboard.IsPressed(BrumeKey.S))
                    camera.FPSMove(-camera.Dir * (fElapsedTime / moveSpeed));
                if (BrumeKeyboard.IsPressed(BrumeKey.D))
                    camera.FPSMove(camera.Right * (fElapsedTime / moveSpeed));
                if (BrumeKeyboard.IsPressed(BrumeKey.A))
                    camera.FPSMove(-camera.Right * (fElapsedTime / moveSpeed));
            }


            // moving
            base.MoveScene(fElapsedTime);

        }
        protected override void RenderScene()
        {

            base.RenderScene();

        }
        protected override void AfterRendering()
        {
            base.AfterRendering();
            // exit ?
            if (BrumeKeyboard.IsPressed(BrumeKey.Escape))
            {
                this.Close();
                return;
            }

        }

        public static void Main()
        {
            using (Sample game = new Sample())
            {
                game.Play();
            }
        }
       
    }
}


User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France

Postby rubbish on Tue Nov 07, 2006 9:49 am

O THANK YOU VERY MUCH
another question :D

can two animations run in the same time?
tiny "Wave"&"Walk" ?
three ?four?? :roll:
rubbish
Brume user
 
Posts: 183
Joined: Fri Nov 03, 2006 5:05 am

Postby Silmaryls on Tue Nov 07, 2006 11:53 pm

Not at the moment.

BrumeObject has only one Animation property.
User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France

Postby rubbish on Wed Nov 08, 2006 8:43 am

o...

but i want tiny "wave" & "Walk" at the same time....

can't achieve?
rubbish
Brume user
 
Posts: 183
Joined: Fri Nov 03, 2006 5:05 am

Postby Silmaryls on Wed Nov 08, 2006 2:08 pm

Maybe by using an external tool to merge the animations ?

Otherwise you will have to wait for the feature (It's not planned for next release at the moment).
User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France

Postby rubbish on Wed Nov 08, 2006 3:19 pm

what a pity
rubbish
Brume user
 
Posts: 183
Joined: Fri Nov 03, 2006 5:05 am

Postby Silmaryls on Wed Nov 08, 2006 10:55 pm

It's life !

:lol:
User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France


Return to Technical discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron