Changing movement

Get technical support about the C++ source code and about Lua scripts for maps, entities, GUIs, the console, materials, etc. Also covered are the Cafu libraries and APIs, as well as compiling, linking, and the build system.
User avatar
bigjj13
Posts:68
Joined:2010-04-04, 19:16
Location:Germany
Contact:
Changing movement

Post by bigjj13 » 2010-08-05, 20:59

Hi,

I'd like ko change the player movement, so i usualy walk, but if I press shift, im run.
I tried this in the HumanPlayer.cpp:

Code: Select all

// Update Bank
                State.Bank+=PlayerCommands[PCNr].DeltaBank;


                VectorT             WishVelocity;
                bool                WishJump=false;
				[color=#4000FF]char				Runspon=0;
                const double        VelX    =3000.0*LookupTables::Angle16ToSin[State.Heading];     // 6000 == Client.MoveSpeed
                const double        VelY    =3000.0*LookupTables::Angle16ToCos[State.Heading];     // 6000 == Client.MoveSpeed[/color]
                const unsigned long Keys    =PlayerCommands[PCNr].Keys;

                if (Keys & PCK_MoveForward ) WishVelocity=             VectorT( VelX,  VelY, 0);
                if (Keys & PCK_MoveBackward) WishVelocity=WishVelocity+VectorT(-VelX, -VelY, 0);
                if (Keys & PCK_StrafeLeft  ) WishVelocity=WishVelocity+VectorT(-VelY,  VelX, 0);
                if (Keys & PCK_StrafeRight ) WishVelocity=WishVelocity+VectorT( VelY, -VelX, 0);

                if (Keys & PCK_CenterView  ) { State.Pitch=0; State.Bank=0; }
                if (Keys & PCK_Jump        ) WishJump=true;
             // if (Keys & PCK_Duck        ) ;
                [color=#4000FF]if (Keys & PCK_Walk        ) 
				{
					WishVelocity=scale(WishVelocity, 2.0);					//Run
					Runspon=1;
				}[/color]

                VectorT       WishVelLadder;
                const double  ViewLadderZ=-LookupTables::Angle16ToSin[State.Pitch];
                const double  ViewLadderY= LookupTables::Angle16ToCos[State.Pitch];
                const VectorT ViewLadder =scale(VectorT(ViewLadderY*LookupTables::Angle16ToSin[State.Heading], ViewLadderY*LookupTables::Angle16ToCos[State.Heading], ViewLadderZ), 1900.0);

                // TODO: Also take LATERAL movement into account.
                // TODO: All this needs a HUGE clean-up! Can probably put a lot of this stuff into Physics::MoveHuman.
                if (Keys & PCK_MoveForward ) WishVelLadder=WishVelLadder+ViewLadder;
                if (Keys & PCK_MoveBackward) WishVelLadder=WishVelLadder-ViewLadder;
                if (Keys & PCK_Walk        ) WishVelLadder=scale(WishVelLadder, 2.0);

                /*if (Clients[ClientNr].move_noclip)
                {
                    // This code was simply changed and rewritten until it "worked".
                    // May still be buggy anyway.
                    double RadPitch=double(State.Pitch)/32768.0*3.141592654;
                    double Fak     =VectorDot(WishVelocity, VectorT(LookupTables::Angle16ToSin[State.Heading], LookupTables::Angle16ToCos[State.Heading], 0));

                    WishVelocity.x*=cos(RadPitch);
                    WishVelocity.y*=cos(RadPitch);
                    WishVelocity.z=-sin(RadPitch)*Fak;

                    State.Origin=State.Origin+scale(WishVelocity, PlayerCommands[PCNr].FrameTime);

                    // TODO: If not already done on state change (--> "noclip"), set the model sequence to "swim".  ;-)
                }
                else */
                {
                    VectorT XYVel      =State.Velocity; XYVel.z=0;
                    double  OldSpeed   =length(XYVel);
                    bool    OldWishJump=(State.Flags & Flags_OldWishJump) ? true : false;

                    Physics::MoveHuman(State, ClipModel, PlayerCommands[PCNr].FrameTime, WishVelocity, WishVelLadder, WishJump, OldWishJump, 470.0, GameWorld->GetClipWorld());

                    ClipModel.SetOrigin(State.Origin);
                    ClipModel.Register();
                    // The physics world will pick-up our new origin at the next opportunity from getWorldTransform().

                    if (OldWishJump) State.Flags|= Flags_OldWishJump;
                                else State.Flags&=~Flags_OldWishJump;

                    XYVel=State.Velocity;
                    XYVel.z=0;
                    double NewSpeed=length(XYVel);

                   [color=#4000FF] if (OldSpeed<=1000.0 && NewSpeed>1000.0) 
					{
						if (Runspon=1) State.ModelSequNr=3;
						else State.ModelSequNr=4;
					}[/color]
                    if (OldSpeed>=1000.0 && NewSpeed<1000.0) State.ModelSequNr=1;
                }

                // GameWorld->ModelAdvanceFrameTime() is called on client side in Draw().

BigJJ -- SG-O
Image
User avatar
Carsten
Site Admin
Posts:2170
Joined:2004-08-19, 13:46
Location:Germany
Contact:

Re: Changing movement

Post by Carsten » 2010-08-05, 23:07

bigjj13 wrote:I'd like ko change the player movement, so i usualy walk, but if I press shift, im run.
I tried this in the HumanPlayer.cpp:
It's looking good! :cheesy:
Best regards,
Carsten
User avatar
bigjj13
Posts:68
Joined:2010-04-04, 19:16
Location:Germany
Contact:

Re: Changing movement

Post by bigjj13 » 2010-08-06, 18:37

Hi,

Now I have a question:

How can I change the Runmodel (Model 3) into the walkmodel (Model 4)?
I tried this, but it didn't work:

Code: Select all

if (Runspon=1) 
{
      State.ModelSequNr=3;
      else State.ModelSequNr=4;
}
      if (OldSpeed>=1000.0 && NewSpeed<1000.0) State.ModelSequNr=1;
Thanks
BigJJ -- SG-O
Image
User avatar
Carsten
Site Admin
Posts:2170
Joined:2004-08-19, 13:46
Location:Germany
Contact:

Re: Changing movement

Post by Carsten » 2010-08-07, 12:54

Hi BigJJ,
bigjj13 wrote:

Code: Select all

if (Runspon=1) 
{
      State.ModelSequNr=3;
      else State.ModelSequNr=4;
}
      if (OldSpeed>=1000.0 && NewSpeed<1000.0) State.ModelSequNr=1;
The first line probably doesn't do what you want, try == instead of =.
The line with the else clause has no matching if - I'd be surprised if this was legal C++; removing the { and } might help. :up:
Best regards,
Carsten
User avatar
bigjj13
Posts:68
Joined:2010-04-04, 19:16
Location:Germany
Contact:

Re: Changing movement

Post by bigjj13 » 2010-08-13, 10:30

Hi,

Now it works, thanks, I'll just have to change the walk speed, so your feet walk realistic.

Another Question:
How can I reversa a movement?

Thanks,
BigJJ -- SG-O
Image
User avatar
Carsten
Site Admin
Posts:2170
Joined:2004-08-19, 13:46
Location:Germany
Contact:

Re: Changing movement

Post by Carsten » 2010-08-13, 13:20

bigjj13 wrote:How can I reversa a movement?
Uhh... sorry, what do you mean by "reverse"?
Best regards,
Carsten
User avatar
bigjj13
Posts:68
Joined:2010-04-04, 19:16
Location:Germany
Contact:

Re: Changing movement

Post by bigjj13 » 2010-08-13, 14:18

Hi,

sorry, I mean, If I walk back my feet walk back, too.

The walk/run animation is reversed.

Thanks
BigJJ -- SG-O
Image
User avatar
Carsten
Site Admin
Posts:2170
Joined:2004-08-19, 13:46
Location:Germany
Contact:

Re: Changing movement

Post by Carsten » 2010-08-13, 15:19

bigjj13 wrote:sorry, I mean, If I walk back my feet walk back, too.
The walk/run animation is reversed.
Ah, sorry, no, this is currently not supported (as the proper solution would be to have an animation sequence in the model files that properly animates walking backwards).

However, as a work-around, you might try to animate the "forward" walk animation backwards when the player moves backwards, line 718 in Code/HumanPlayer.cpp is probably the best place for this. I don't however know whether this will work or if it will look good.
This and many similar cases are also the reason why one of my main lines of current work include the new model editor...
Best regards,
Carsten
User avatar
bigjj13
Posts:68
Joined:2010-04-04, 19:16
Location:Germany
Contact:

Re: Changing movement

Post by bigjj13 » 2010-08-13, 19:50

Here is the 1st version of the "new" HumanPlayer.cpp and the changed Models.
better human player1.zip
(510.21KiB)Downloaded 258 times
better human player2.zip
(401.99KiB)Downloaded 263 times
I wasn't able to change all of your models, because there 2 different types of *.mdl.

With this change you normaly walk. If you hit shift you'll run.
I tried to use the jump seqence, but there is stil a bug in the changed code.

Thanks
BigJJ -- SG-O
Image
User avatar
Carsten
Site Admin
Posts:2170
Joined:2004-08-19, 13:46
Location:Germany
Contact:

Re: Changing movement

Post by Carsten » 2010-08-16, 10:46

Hi BigJJ,
bigjj13 wrote:With this change you normaly walk. If you hit shift you'll run.
I tried to use the jump seqence, but there is stil a bug in the changed code.
Thank you very much for sharing the code! :-D

Could you also please create a patch from your changes? (Preferably when all bugs are fixed ;-) ) We could submit the patch as a ticket then as well. As a result, the changes would be well documented and very easy to apply by others.

If you cannot create the patch yourself, could you please send me / upload the complete changed files (when you consider them done, bugs fixed, etc.), so that I can create the patch myself?
I wasn't able to change all of your models, because there 2 different types of *.mdl.
I'm not so sure about the models... how exactly did you change them, and what are you changes comprised of? I did a quick binary comparison and found many changed sections that I did not understand. It's not a big problem though, but I'll probably prefer to wait with picking up changed models until the model editor is complete, in order to see things more clearly.

Again, many thanks!
Best regards,
Carsten
User avatar
bigjj13
Posts:68
Joined:2010-04-04, 19:16
Location:Germany
Contact:

Re: Changing movement

Post by bigjj13 » 2010-08-18, 11:56

I'm not so sure about the models... how exactly did you change them, and what are you changes comprised of?
I used FragMotion a 3d animation studio to add a new animation seqence.

But now i have a question:

I'd like to use the jump seqence witch is nr.8 and long jump nr.9.

I tried this in the HumanPlayer.cpp:

Code: Select all

 
                if (Keys & PCK_MoveForward ) WishVelocity=             VectorT( VelX,  VelY, 0);
                if (Keys & PCK_MoveBackward) 
				{
					WishVelocity=WishVelocity+VectorT(-VelX, -VelY, 0);
					Runspon=3; //seq. 77 (walk back)
				}
                if (Keys & PCK_StrafeLeft  ) WishVelocity=WishVelocity+VectorT(-VelY,  VelX, 0);
                if (Keys & PCK_StrafeRight ) WishVelocity=WishVelocity+VectorT( VelY, -VelX, 0);

                if (Keys & PCK_CenterView  ) { State.Pitch=0; State.Bank=0; }
                if (Keys & PCK_Jump        ) 
				{
					WishJump=true;
					Runspon=2; //(Normal Jump)
				}
             // if (Keys & PCK_Duck        ) ;
                if (Keys & PCK_Walk        ) 
				{
					if (Runspon!=3) //no running backward
					{
						WishVelocity=scale(WishVelocity, 2.0);					//Run
						if (Runspon==2) Runspon=4; //Long jump
						else Runspon=1;
					}
				}

                VectorT       WishVelLadder;
                const double  ViewLadderZ=-LookupTables::Angle16ToSin[State.Pitch];
                const double  ViewLadderY= LookupTables::Angle16ToCos[State.Pitch];
                const VectorT ViewLadder =scale(VectorT(ViewLadderY*LookupTables::Angle16ToSin[State.Heading], ViewLadderY*LookupTables::Angle16ToCos[State.Heading], ViewLadderZ), 1900.0);

                // TODO: Also take LATERAL movement into account.
                // TODO: All this needs a HUGE clean-up! Can probably put a lot of this stuff into Physics::MoveHuman.
                if (Keys & PCK_MoveForward ) WishVelLadder=WishVelLadder+ViewLadder;
                if (Keys & PCK_MoveBackward) WishVelLadder=WishVelLadder-ViewLadder;
                if (Keys & PCK_Walk        ) WishVelLadder=scale(WishVelLadder, 2.0);

                /*if (Clients[ClientNr].move_noclip)
                {
                    // This code was simply changed and rewritten until it "worked".
                    // May still be buggy anyway.
                    double RadPitch=double(State.Pitch)/32768.0*3.141592654;
                    double Fak     =VectorDot(WishVelocity, VectorT(LookupTables::Angle16ToSin[State.Heading], LookupTables::Angle16ToCos[State.Heading], 0));

                    WishVelocity.x*=cos(RadPitch);
                    WishVelocity.y*=cos(RadPitch);
                    WishVelocity.z=-sin(RadPitch)*Fak;

                    State.Origin=State.Origin+scale(WishVelocity, PlayerCommands[PCNr].FrameTime);

                    // TODO: If not already done on state change (--> "noclip"), set the model sequence to "swim".  ;-)
                }
                else */
                {
                    VectorT XYVel      =State.Velocity; XYVel.z=0;
                    double  OldSpeed   =length(XYVel);
                    bool    OldWishJump=(State.Flags & Flags_OldWishJump) ? true : false;

                    Physics::MoveHuman(State, ClipModel, PlayerCommands[PCNr].FrameTime, WishVelocity, WishVelLadder, WishJump, OldWishJump, 470.0, GameWorld->GetClipWorld());

                    ClipModel.SetOrigin(State.Origin);
                    ClipModel.Register();
                    // The physics world will pick-up our new origin at the next opportunity from getWorldTransform().

                    if (OldWishJump) State.Flags|= Flags_OldWishJump;
                                else State.Flags&=~Flags_OldWishJump;

                    XYVel=State.Velocity;
                    XYVel.z=0;
                    double NewSpeed=length(XYVel);

                    if (OldSpeed<=1000.0 && NewSpeed>1000.0) 
					{
						if (Runspon==1) State.ModelSequNr=3;
						else	if (Runspon==2) State.ModelSequNr=8; //jump
								else	if (Runspon==3) State.ModelSequNr=77;
										else	if (Runspon==4) State.ModelSequNr=9; //long jump
												else State.ModelSequNr=4;
					}
                    if (OldSpeed>=1000.0 && NewSpeed<1000.0)
					{
						if (Runspon==2) State.ModelSequNr=8;
						else State.ModelSequNr=1;
					}
Thanks
BigJJ -- SG-O
Image
User avatar
Carsten
Site Admin
Posts:2170
Joined:2004-08-19, 13:46
Location:Germany
Contact:

Re: Changing movement

Post by Carsten » 2010-08-18, 14:37

bigjj13 wrote:I used FragMotion a 3d animation studio to add a new animation seqence.
Ah, ok, thanks!
But now i have a question:
I'd like to use the jump seqence witch is nr.8 and long jump nr.9.
And the question is...?
Best regards,
Carsten
User avatar
bigjj13
Posts:68
Joined:2010-04-04, 19:16
Location:Germany
Contact:

Re: Changing movement

Post by bigjj13 » 2010-08-18, 14:54

oops...

The question is: what did I do wrong?

Thanks
BigJJ -- SG-O
Image
User avatar
Carsten
Site Admin
Posts:2170
Joined:2004-08-19, 13:46
Location:Germany
Contact:

Re: Changing movement

Post by Carsten » 2010-08-18, 15:45

bigjj13 wrote:The question is: what did I do wrong?
In what regard? (confused I am)
Best regards,
Carsten
User avatar
bigjj13
Posts:68
Joined:2010-04-04, 19:16
Location:Germany
Contact:

Re: Changing movement

Post by bigjj13 » 2010-08-18, 15:53

Sorry,

I'd like to let my player if he jumps (action) play the jump seqence (nr.8) and if you run and jump, you make a long jump(seq. nr.9).

I tried this (code is in the 11th post). But it didn't work.

Now my question: What is wrong?
BigJJ -- SG-O
Image
Post Reply

Who is online

Users browsing this forum: No registered users and 25 guests