Kingdom Hearts Movement Tutorial

Posted By: DavidLancaster

Kingdom Hearts Movement Tutorial - 08/16/06 02:08

Introducing the Kingdom Hearts Movement Tutorial for 3DGS. An indepth tutorial which will take you through the process of coding such movement, this tutorial will take you thorugh line by line of code, with a detailed explanation of each section of code. This tutorial features:

-non clipping 3rd person camera
-combat with combos, including airborne combat
-gravity, jumping and falling
-targeting/lock on system
-blending of vertex animations
-enemy dummies

You can download the tutorial here:

The tutorial resources:
Download Tutorial Resources (approx 8.8mb)

The tutorial documentation:
Download Tutorial Documentation (approx 0.9mb)

If those links arn't working, you can download both the resources and documentation here, however the files in this link may not be as up to date as the others above:
Download Tutorial (approx 9.7mb)

Please note the creator of the model has very kindly allowed the model to be used in this tutorial on the condition that the uv mapping on the skin be replaced, this is why the model in the tutorial is green.

If you come across any bugs in the code or tutorial process please let me know and I will fix it as soon as possible.

Thanks to Exile for the awesome model, and Kotakide for the cool animations.

Screens:





Posted By: Why_Do_I_Die

Re: Kingdom Hearts Movement Tutorial - 08/16/06 04:04

Awesome , cant wait to check it out , thnx for the contribution.
Posted By: Captain_Kiyaku

Re: Kingdom Hearts Movement Tutorial - 08/16/06 06:18

OMG Kingdom Hearts is my favorite game EVER. i HAVE to test your tutorial, and will do it now. thanks so much
Posted By: lostclimate

Re: Kingdom Hearts Movement Tutorial - 08/16/06 06:24

i have never played kingdom hearts, and the only response i can give is.... holy crap. lol, i started messing with the demo, and did it for a half an hour before i got off of it. You know what would be really fun, an online fighting game with a system like this were you could challenge your friends.
Posted By: Orange Brat

Re: Kingdom Hearts Movement Tutorial - 08/16/06 07:37

It looks like the link has been removed. Perhaps someone can repost using http://www.yousendit.com/ or some other service?
Posted By: DavidLancaster

Re: Kingdom Hearts Movement Tutorial - 08/16/06 08:09

I just uploaded a newer version and added the following above "if the link isn't working I may be uploading an updated version, if it is inactive for too long please let me know", once I've got people's feedback and fixed most bugs I'll submit it to Acknex Resources.
Posted By: Orange Brat

Re: Kingdom Hearts Movement Tutorial - 08/16/06 08:27

This is excellent. Although, I'll have to play with the code to extend the tilt limitations, the camera is a non-clipper with the current range. The animation blending is great and locking on is good, too. The models had a shimmering emerald green look to them, though, so no skin. I'm using a GeForce 5200 FX 128MB with the latest 91.xx drivers and XP.

The blending code is great...I believe I recall this being posted in my blending thread and I was going to experiment with integrating into it, however there's no need given this is a perfect 3rd person satellite cam.

This is a Holy Grail, Orange Brat approved 3rd person camera. If you've been around here long enough, you'll know what that's all about.
Posted By: frazzle

Re: Kingdom Hearts Movement Tutorial - 08/16/06 08:28


WOW !! And again you keep on amazing me David ^^
This is looking exellent
Nice contribution, again

Cheers

Frazzle
Posted By: DavidLancaster

Re: Kingdom Hearts Movement Tutorial - 08/16/06 08:36

Quote:

The models had a shimmering emerald green look to them.




The model in the tutorial has a green skin, I've added this detail above.

Thanks all for your kind words!

Orange_brat your blending code is the best
Posted By: Orange Brat

Re: Kingdom Hearts Movement Tutorial - 08/16/06 08:38

Quote:

Orange_brat your blending code is the best




I don't know about that, but your version is much easier on the eyes and seems to be better for extending.

Now, you need a gamepad mode.
Posted By: Orange Brat

Re: Kingdom Hearts Movement Tutorial - 08/16/06 08:53

I have found one inconsistency in the scripting. You use c_move and c_scan, but in the player.wdl all of your traces are old trace. I converted over to c_trace and used the same trace modes, but it made the player hover way up in the air for whatever reason. Actually, one of the traces doesn't have a movement mode, so perhaps that's the problem.

EDIT: I see it's in the docs...I'll play with it a bit and see what I can come up with.
Posted By: DavidLancaster

Re: Kingdom Hearts Movement Tutorial - 08/16/06 09:08

I pointed that out in the documentation, I attempted to use c_trace and simply couldn't get it to work, perhaps because of my inexperience with the instruction, if you can figure out how to get it working please let me know.
Posted By: TWO

Re: Kingdom Hearts Movement Tutorial - 08/16/06 09:19

Wow, I never tuched a tutorial, but yours will be the first one *downloading*
Posted By: taipan

Re: Kingdom Hearts Movement Tutorial - 08/16/06 09:59

i heard theres a new religion, axysphenomenism super great contrib for the community
Posted By: Orange Brat

Re: Kingdom Hearts Movement Tutorial - 08/16/06 10:18

Here's a small contrib to the camera. It's the alpha fade from the new templates. Simply add this to the end of the handle_camera function. Also, you can use c_trace in that function without any problems as long as enable_polycollision is greater than 0.5. When the next version of 3DGS is released, this limitation will be lifted(see beta page), and you'll be able to use 0 or 0.5 with trace_hit/c_trace(properly).

Code:

var fade_toggle = 1; //0 = off; 1 = on
var fade_start = 90;
var fade_end = 60;
var temp3[3];

if(fade_toggle == 1)
{
vec_diff(temp.x, my.x, camera.x);
if(fade_start > 0)
{
temp3.x = vec_length(temp.x); // distance from camera to target
if(temp3.x < fade_start)
{
my.transparent = on; // fade to zero depending distance to fade end
player_weapon.transparent = on;
my.shadow = off;
player_weapon.shadow = off;
//NOTE: use 1st max to avoid negative alpha
//use 2nd max to avoid divide by zero
my.alpha = 100 * max(0, ((temp3.x - fade_end) / max(1,(fade_start - fade_end))));
player_weapon.alpha = my.alpha;
}
else
{
my.transparent = off;
player_weapon.transparent = off;
my.shadow = on;
player_weapon.shadow = on;
}
}
}


Posted By: JetpackMonkey

Re: Kingdom Hearts Movement Tutorial - 08/16/06 14:09

wow!! awesome, easy to read and very complete tutorial! though movement scripting isn't really my forte, this tutorial will be very useful for learning about how it all works.

I'd make a little recommendation to make it more readable, though-- switch magic numbers with some more readable defines.. like jumping_mode = 0 or 1 or 2, could be replaced with

define not_jumping, 0
define jump_upwards, 1
define jump_coming_down, 2

so jumping_mode = not_jumping etc!

magic numbers always make me confused


Posted By: TheExpert

Re: Kingdom Hearts Movement Tutorial - 08/20/06 10:59

I've tried it your script :
it's pretty damn good : fantastic
it will deserve to be in the 3DGS official package with teh script of the ninja

thanks a lot for sharing
Posted By: DavidLancaster

Re: Kingdom Hearts Movement Tutorial - 08/20/06 13:04

Good suggestion jetpack, I'll make those changes as soon I can. I'm glad this tutorial has turned out to be useful, thanks for everyones' comments
Posted By: nkl

Re: Kingdom Hearts Movement Tutorial - 09/05/06 06:30

Hi DavidLancaster
I study your tutorial.
This is a very excellent tutorial.
I want to add enemy pain effect and player climb ladder effect.
I add following code in the player.wdl
Code:
  
DEFINE pain,12;
DEFINE knockdown,13;
DEFINE ladder, 14;


I add the pain animation and climb ladder animation in the animation.wdl
Code:
  
FUNCTION handle_animation(animation_speed) {
IF (animation_speed <= 0) { animation_speed = 1; }
IF (my.animblend != blend && my.blendframe != nullframe) { my.animate2 = 0; my.animblend = blend; }
IF (my.animblend == blend) {
IF (my.currentframe == stand) { ent_animate(my,"stand",my.animate,anm_cycle); }
IF (my.currentframe == run) { ent_animate(my,"run",my.animate,anm_cycle); }
IF (my.currentframe == walk) { ent_animate(my,"walk",my.animate,anm_cycle); }
IF (my.currentframe == jump) { ent_animate(my,"jump",my.animate,0); }
IF (my.currentframe == attack_a) { ent_animate(my,"attack_a",my.animate,0); }
IF (my.currentframe == attack_b) { ent_animate(my,"attack_b",my.animate,0); }
IF (my.currentframe == attack_c) { ent_animate(my,"attack_c",my.animate,0); }
IF (my.currentframe == attack_d) { ent_animate(my,"attack_d",my.animate,0); }
IF (my.currentframe == attack_e) { ent_animate(my,"attack_e",my.animate,0); }
IF (my.currentframe == attack_f) { ent_animate(my,"attack_f",my.animate,0); }
IF (my.blendframe == stand) { ent_blend("stand",0,my.animate2); }
IF (my.blendframe == run) { ent_blend("run",0,my.animate2); }
IF (my.blendframe == walk) { ent_blend("walk",0,my.animate2); }
IF (my.blendframe == jump) { ent_blend("jump",0,my.animate2); }
IF (my.blendframe == fall) { ent_blend("jump",60,my.animate2); }
IF (my.blendframe == attack_a) { ent_blend("attack_a",0,my.animate2); }
IF (my.blendframe == attack_b) { ent_blend("attack_b",0,my.animate2); }
IF (my.blendframe == attack_c) { ent_blend("attack_c",0,my.animate2); }
IF (my.blendframe == attack_d) { ent_blend("attack_d",0,my.animate2); }
IF (my.blendframe == attack_e) { ent_blend("attack_e",0,my.animate2); }
IF (my.blendframe == attack_f) { ent_blend("attack_f",0,my.animate2); }

// ******************
// ****************** add new code
IF (my.blendframe == pain) { ent_blend("pain",0,my.animate2); }
IF (my.blendframe == knockdown) { ent_blend("knockdown",0,my.animate2); }
IF (my.blendframe == ladder) { ent_blend("ladder",0,my.animate2); }
// ****************** end add new code
// ******************

my.animate2 += 45 * time;
IF (my.animate2 >= 100) {
my.animate = 0;
my.animblend = my.blendframe;
my.blendframe = nullframe;
}
}

// ******************
// ****************** add new code
IF (my.animblend == pain) {
ent_animate(my,"pain",my.animate,anm_cycle);
my.animate += 5 * animation_speed * time;
my.animate %= 100;
my.currentframe = pain;
}
IF (my.animblend == knockdown) {
ent_animate(my,"knockdown",my.animate,anm_cycle);
my.animate += 5 * animation_speed * time;
my.animate %= 100;
my.currentframe = knockdown;
}
IF (my.animblend == ladder) {
ent_animate(my,"ladder",my.animate,anm_cycle);
my.animate += 5 * animation_speed * time;
my.animate %= 100;
my.currentframe = ladder;
}
// ****************** end add new code
// ******************

IF (my.animblend == stand) {
ent_animate(my,"stand",my.animate,anm_cycle);
my.animate += 5 * animation_speed * time;
my.animate %= 100;
my.currentframe = stand;
}
IF (my.animblend == run) {
ent_animate(my,"run",my.animate,anm_cycle);
my.animate += 8 * animation_speed * time;
my.animate %= 100;
my.currentframe = run;
}
IF (my.animblend == walk) {
ent_animate(my,"walk",my.animate,anm_cycle);
my.animate += 8 * animation_speed * time;
my.animate %= 100;
my.currentframe = walk;
}
IF (my.animblend == jump || my.animblend == fall) {
IF (my.jumping_mode == 3) { my.animate = 60; }
ent_animate(my,"jump",my.animate,0);
my.animate += 10 * animation_speed * time;
my.currentframe = jump;
IF (my.animate >= 60 && my.jumping_mode == 1) { my.jumping_mode = 2; }
IF (my.animate >= 100) {
ent_animate(my,"jump",100,0);
my.animate = 100;
my.blendframe = stand;
IF (my.moving == 1) {
IF (key_shift == 1) { my.blendframe = walk; } ELSE { my.blendframe = run; }
}
}
}
IF (my.animblend == attack_a) {
ent_animate(my,"attack_a",my.animate,0);
my.animate += 20 * animation_speed * time;
my.currentframe = attack_a;
IF (my.animate >= 100) {
ent_animate(my,"attack_a",100,0);
my.animate = 100;
my.blendframe = stand;
IF (my.moving == 1) {
IF (key_shift == 1) { my.blendframe = walk; } ELSE { my.blendframe = run; }
}
IF (combo_continue == 1) {
combo_continue = 0;
my.blendframe = attack_b;
} ELSE {
my.movement_mode = 0;
}
}
}
IF (my.animblend == attack_b) {
ent_animate(my,"attack_b",my.animate,0);
my.animate += 15 * animation_speed * time;
my.currentframe = attack_b;
IF (my.animate >= 100) {
ent_animate(my,"attack_b",100,0);
my.animate = 100;
my.blendframe = stand;
IF (my.moving == 1) {
IF (key_shift == 1) { my.blendframe = walk; } ELSE { my.blendframe = run; }
}
IF (combo_continue == 1) {
combo_continue = 0;
my.blendframe = attack_c;
} ELSE {
my.movement_mode = 0;
}
}
}
IF (my.animblend == attack_c) {
ent_animate(my,"attack_c",my.animate,0);
my.animate += 10 * animation_speed * time;
my.currentframe = attack_c;
IF (my.animate >= 100) {
ent_animate(my,"attack_c",100,0);
my.animate = 100;
my.blendframe = stand;
IF (my.moving == 1) {
IF (key_shift == 1) { my.blendframe = walk; } ELSE { my.blendframe = run; }
}
IF (combo_continue == 1) {
my.jumping_mode = 10;
my.force_z = 12;
my.gravity = 4;
combo_continue = 0;
my.blendframe = attack_d;
} ELSE {
my.movement_mode = 0;
}
}
}
IF (my.animblend == attack_d) {
handle_sword_collision();
ent_animate(my,"attack_d",my.animate,0);
my.animate += 15 * animation_speed * time;
my.currentframe = attack_d;
IF (my.animate >= 100) {
ent_animate(my,"attack_d",100,0);
my.animate = 100;
my.blendframe = stand;
IF (my.moving == 1) {
IF (key_shift == 1) { my.blendframe = walk; } ELSE { my.blendframe = run; }
}
IF (combo_continue == 1) {
combo_continue = 0;
my.blendframe = attack_e;
} ELSE {
my.movement_mode = 0;
}
}
}
IF (my.animblend == attack_e) {
ent_animate(my,"attack_e",my.animate,0);
my.animate += 15 * animation_speed * time;
my.currentframe = attack_e;
IF (my.jumping_mode == 0 && my.animate >= 20 && my.animate < 60) {
my.gravity = 3;
my.jumping_mode = 10;
my.force_z = 15;
}
IF (my.animate >= 100) {
ent_animate(my,"attack_e",100,0);
my.animate = 100;
my.blendframe = stand;
IF (my.moving == 1) {
IF (key_shift == 1) { my.blendframe = walk; } ELSE { my.blendframe = run; }
}
IF (combo_continue == 1) {
combo_continue = 0;
my.blendframe = attack_f;
} ELSE {
my.movement_mode = 0;
}
}
}
IF (my.animblend == attack_f) {
ent_animate(my,"attack_f",my.animate,0);
my.animate += 6 * animation_speed * time;
my.currentframe = attack_f;
IF (my.jumping_mode == 0 && my.animate >= 40 && my.animate < 60) {
my.gravity = 6;
my.jumping_mode = 10;
my.force_z = 12;
}
IF (my.animate >= 100) {
my.movement_mode = 0;
ent_animate(my,"attack_f",100,0);
my.animate = 100;
my.blendframe = stand;
IF (my.moving == 1) {
IF (key_shift == 1) { my.blendframe = walk; } ELSE { my.blendframe = run; }
}
}
}
IF (my.animblend >= attack_a && my.animblend <= attack_f) { handle_sword_collision(); }
IF (my.animblend != blend && my.blendframe != nullframe) { my.animate2 = 0; my.animblend = blend; }
}



How do I add enemy pain effect and player climb ladder effect?
Thanks for any advice.
Thanks already.
Posted By: Locoweed

Re: Kingdom Hearts Movement Tutorial - 09/06/06 21:58

Sweet! Great stuff.

Loco
Posted By: sPlKe

Re: Kingdom Hearts Movement Tutorial - 09/06/06 23:19

sweet stuff...
i have to figure out a few things though, but all in all, if this just gets a little better adaptable, to not rely on the implemented code, one can easily use this as base for a 3rd person game of any kind, like action, fighting, jump and run ect...

as said, i have to play around with it a bit. maybe i find a good way to implementy MY camera with this code, sicne im not very good at coding. then i just have to find out how to implement shooting and im ready to go:-p
Posted By: DavidLancaster

Re: Kingdom Hearts Movement Tutorial - 09/07/06 00:09

@nkl - to add the enemy pain effect you will need the enemies to be animated, call handle_animation(1); from the enemie's while loop, then when the sword strikes the enemy change it's animation to pain. For the ladder climbing, you will need to create a new my.movement_mode state, which only moves the player up and down and animates the player with the ladder animation, it will need to be triggered by approaching a ladder. Easy to say in concept, implementing it requires scripting experience.
Posted By: Ludochrist

Re: Kingdom Hearts Movement Tutorial - 09/08/06 01:39

this is really nice, but i think a chase camera similar to the zelda code would be much more appropriate for a kingdom hearts type game. clicking a mouse for fast combo based combat isnt as intuitive as using a joypad, and also the camera is somthing i should never have to worry about moving while in battle. if you could make a hybrid of this and the zelda code i think it would be a perfect for kindom hearts style gameplay.
Posted By: DavidLancaster

Re: Kingdom Hearts Movement Tutorial - 09/08/06 13:44

It's pretty easy to set up a simple camera that way. The player moves relative to the camera so you pan the camera as the player moves left and right rather than have the camera controlled by the mouse. This may not be the best code to do the job but it works:

Code:

IF (key_w == 1 && key_s == 0 && key_a == 0 && key_d == 0) { temp.x = camera.pan; }
IF (key_s == 1 && key_w == 0 && key_a == 0 && key_d == 0) { temp.x = camera.pan + 180; }
IF (key_a == 1 && key_s == 0 && key_w == 0 && key_d == 0) { temp.x = camera.pan + 90; camera.pan += 5 * time; }
IF (key_d == 1 && key_s == 0 && key_a == 0 && key_w == 0) { temp.x = camera.pan - 90; camera.pan -= 5 * time; }
IF (key_w == 1 && key_a == 1 && key_d == 0 && key_s == 0) { temp.x = camera.pan + 45; camera.pan += 2.5 * time; }
IF (key_w == 1 && key_d == 1 && key_a == 0 && key_s == 0) { temp.x = camera.pan - 45; camera.pan -= 2.5 * time; }
IF (key_s == 1 && key_a == 1 && key_d == 0 && key_w == 0) { temp.x = camera.pan + 135; camera.pan += 6 * time; }
IF (key_s == 1 && key_d == 1 && key_a == 0 && key_w == 0) { temp.x = camera.pan - 135; camera.pan -= 6 * time; }



Use that concept, introduce some new variables and you can set up a camera like that pretty easily if you have the experience.
Posted By: TigerTao

Re: Kingdom Hearts Movement Tutorial - 09/15/06 22:52

Just like to add my thanks to David for this contribution. This has helped me from a few tentative baby steps to more confident strides in using this great little program.
Posted By: SusanJ

Re: Kingdom Hearts Movement Tutorial - 09/16/06 16:44

can someone please upload this somewhere so i can download it. it looks realy good and im drooling to try it .

thank you.
Posted By: TWO

Re: Kingdom Hearts Movement Tutorial - 09/16/06 18:42

Look at the first page, there are 3 links; this tut is very very cool!
Posted By: Mythran

Re: Kingdom Hearts Movement Tutorial - 09/25/06 19:24

Did anyone changed the code so that the player may kill monters and die?
If so, can you give me that piece of code?
Thanks for this great code!
&
Thanks in advance.

Posted By: Germanunkol

Re: Kingdom Hearts Movement Tutorial - 10/14/06 14:49

This may be a temporary problem but... i can't download it...:(... looks awesome, I really wanna try it, but I can't download...
?
Thx for giving this to the community!!
Micha


Take that back. I got it from the AUM recources.. thanks!
Posted By: DLively

Re: Kingdom Hearts Movement Tutorial - 10/17/06 03:35

Well... This is the worst code ever... I have never seen anything... - WOW! I Cant say that with a straight face... wow! I love this tut sooooooooooooooooooooooooooooooooo much. You have helped me out soooo much. thanks for the great contribution. PS. Ill be posting up some pics soon of my altered version... lets just say my players sword is a bit... organic... LOL
Posted By: Iglarion

Re: Kingdom Hearts Movement Tutorial - 10/22/06 18:01

I have strange problems - camera go trought terrains, but only with version 6.40 and 6.50.2. With version 6.31 everything work fine. Did someone know what is happening with camera colosion (i also have this problem with old zelda code).
Posted By: Orange Brat

Re: Kingdom Hearts Movement Tutorial - 10/22/06 20:42

It probably has something to do with trace/c_trace conflicts. This code uses both and the 6.31 verson of c_trace is buggy and outdated.
Posted By: DavidLancaster

Re: Kingdom Hearts Movement Tutorial - 10/22/06 22:27

use c_trace in the camera function instead of the old trace:

c_trace(my.x,temp.x,ignore_me|ignore_passable);
Posted By: draculaFactory

Re: Kingdom Hearts Movement Tutorial - 10/22/06 23:03

I am actually trying to change this so that I can use model poly collisions and junk and stuff. Any suggestions? I'm working on it now.
Posted By: DavidLancaster

Re: Kingdom Hearts Movement Tutorial - 10/23/06 01:37

I'm probably stating what you may already know, and I haven't tested it:

Set enable_polycollision
remove the my.z_offset part of the code
replace trace with c_trace and ent_move with c_move.
Make sure in your c_trace you are using the correct trace mode, with use_box etc, and make sure enable_polycollision is set to a working value.

You may do all that and it still may not work, but it's somewhere to start
Posted By: draculaFactory

Re: Kingdom Hearts Movement Tutorial - 10/23/06 02:26

lol yea i got as far as the c_trace and c_move thanks i love this code its organic and highly mobile.

Strange tho. I make my own movement scripts like a point and click thing and i have never had to set enable_polyblahblah before in order to get the poly to collide n stuff i just make sure that the model is my.polygon = on and the player is regular.
Posted By: draculaFactory

Re: Kingdom Hearts Movement Tutorial - 10/23/06 10:11

Oh well, I worked on it all night long and couldn't get any results. Non stop crazy-whacky behavior. I expanded beyond your suggestions. I have never had a problem with this before geez.
Posted By: DavidLancaster

Re: Kingdom Hearts Movement Tutorial - 10/24/06 02:14

Yeah I can't get c_move to work properly, all you gotta do is replace ent_move with:

c_move(my,nullvector,my.move_x,ignore_passable | glide);

It works fine except when 2 ellipoid hulls collide, then it gets stuck (I also added ignore_models to the gravity trace). Yet it doesn't get stuck if I use a simple model instead of the main model, c_move has really disappointed me.
Posted By: draculaFactory

Re: Kingdom Hearts Movement Tutorial - 10/24/06 04:28

actually the problem that i am having is something completely different
im going through the tut bit by bit trying to convert it and it uses c_move but the jump doesnt work
Posted By: DavidLancaster

Re: Kingdom Hearts Movement Tutorial - 11/04/06 00:19

Have you tried using the completed demo of the game and adding c_move from there? Going from scratch may be tedious..
Posted By: DLively

Re: Kingdom Hearts Movement Tutorial - 11/19/06 06:46

Then that would sorta defeat the purpse of the whole learning from the tutorial... by cheating and takin the short way out, you would not learn how to fix thatin a similar situation later on... just what i think...
Posted By: Drew

Re: Kingdom Hearts Movement Tutorial - 12/02/06 20:13

I REALLY wish I had AI for this, even simple enemies that die on contact/hit... I would like to take this moment to please request that if anyone has code for this, please help!!
I'mno coder at all and This is killing me...I've managed to get other AI codes to work with it, doing an ent remove, but always get empty pointers and crashes... PLEASE PLEASE PLEASE hehehe
thanks
Drew
Posted By: DLively

Re: Kingdom Hearts Movement Tutorial - 12/02/06 23:07

i have something at home for that.. ill post it when i can...
Posted By: Serlink

Re: Kingdom Hearts Movement Tutorial - 12/03/06 00:19

I would like to see some AI also. the one I did is real bad
Serlink
Posted By: Drew

Re: Kingdom Hearts Movement Tutorial - 12/03/06 23:00

any luck with that Young_link? I'm dying for some AI for this... I keep checking the thread to see if its arrived

I would really appreciate it and would give all credits
Posted By: molotov

Re: Kingdom Hearts Movement Tutorial - 12/14/06 09:50

Does anyone know how to change the handle_movement function, so that when pressing cul or cur the player turns around it's own axis and not around the camera axis. Thanks anyway for this great contribution
Posted By: DavidLancaster

Re: Kingdom Hearts Movement Tutorial - 12/15/06 13:06

The rotate_entity function handles rotating the player. Change the calling of it from handle_movement so the player is only rotated when pressing A or D.
Posted By: molotov

Re: Kingdom Hearts Movement Tutorial - 12/15/06 15:21

The rotate_entity function works great but is not the solution to my problem. When I press A or D the player rotates and walks in a circle where the camera origin is the center of the circle. How do I make it so that When pressing A or D the player rotates but doesn't walk in a circle around the camera origin. Simple to say I want the camera to turn slowly according the players pan.
Posted By: DavidLancaster

Re: Kingdom Hearts Movement Tutorial - 12/15/06 23:07

If you don't want the player to move when you press A or D, look in the tutorial how the player is moving left and right with these buttons and make the changes.

Then make the camera's pan based on the player's pan and not the mouse:
In handle_camera(), replace:

camera.pan -= mouse_force.x * 12 * time_step;

with:

camera.pan = player.pan;
Posted By: molotov

Re: Kingdom Hearts Movement Tutorial - 12/16/06 10:03

Off course, how logical, spend so much time with the handle_movement that I forgot all about the handle_camera function, thanks anyway.
Posted By: DavidLancaster

Avoidance Camera - 12/26/06 03:09

This only works well in some situations, it's an alright start to a brilliant concept. Make your KH script so that the camera rotates when you move:

Code:

IF (key_w == 1 && key_s == 0 && key_a == 0 && key_d == 0) { temp.x = camera.pan; }
IF (key_s == 1 && key_w == 0 && key_a == 0 && key_d == 0) { temp.x = camera.pan + 180; }
IF (key_a == 1 && key_s == 0 && key_w == 0 && key_d == 0) { temp.x = camera.pan + 90; camera.pan += 5 * time; }
IF (key_d == 1 && key_s == 0 && key_a == 0 && key_w == 0) { temp.x = camera.pan - 90; camera.pan -= 5 * time; }
IF (key_w == 1 && key_a == 1 && key_d == 0 && key_s == 0) { temp.x = camera.pan + 45; camera.pan += 2.5 * time; }
IF (key_w == 1 && key_d == 1 && key_a == 0 && key_s == 0) { temp.x = camera.pan - 45; camera.pan -= 2.5 * time; }
IF (key_s == 1 && key_a == 1 && key_d == 0 && key_w == 0) { temp.x = camera.pan + 135; camera.pan += 6 * time; }
IF (key_s == 1 && key_d == 1 && key_a == 0 && key_w == 0) { temp.x = camera.pan - 135; camera.pan -= 6 * time; }



Now add the following code at the beginning of handle_camera. You will need to define the variable result2 or use a different variable.

Code:

result2 = 0; //trace 30 degrees to both sides of the camera and determine if it should move closer to the player
vec_diff(temp.x,camera.x,my.x);
vec_to_angle(temp2.pan,temp.x);

temp2.pan += 45; //45 degrees
vec_set(temp.x,vector(my.x + fcos(temp2.pan,camera_distance),my.y + fsin(temp2.pan,camera_distance),camera.z));
c_trace(my.x,temp.x,ignore_me|ignore_passable|ignore_models);
IF (result > 0) { result2 -= (camera_distance - result)/camera_distance; }

temp2.pan -= 90; //-45 degrees
vec_set(temp.x,vector(my.x + fcos(temp2.pan,camera_distance),my.y + fsin(temp2.pan,camera_distance),camera.z));
c_trace(my.x,temp.x,ignore_me|ignore_passable|ignore_models);
IF (result > 0) { result2 += (camera_distance - result)/camera_distance; }


temp2.pan += 75; //30 degrees
vec_set(temp.x,vector(my.x + fcos(temp2.pan,camera_distance),my.y + fsin(temp2.pan,camera_distance),camera.z));
c_trace(my.x,temp.x,ignore_me|ignore_passable|ignore_models);
IF (result > 0) { result2 -= ((camera_distance - result)/camera_distance) * 2; }

temp2.pan -= 60; //-30 degrees
vec_set(temp.x,vector(my.x + fcos(temp2.pan,camera_distance),my.y + fsin(temp2.pan,camera_distance),camera.z));
c_trace(my.x,temp.x,ignore_me|ignore_passable|ignore_models);
IF (result > 0) { result2 += ((camera_distance - result)/camera_distance) * 2; }


temp2.pan += 45; //15 degrees
vec_set(temp.x,vector(my.x + fcos(temp2.pan,camera_distance),my.y + fsin(temp2.pan,camera_distance),camera.z));
c_trace(my.x,temp.x,ignore_me|ignore_passable|ignore_models);
IF (result > 0) { result2 -= ((camera_distance - result)/camera_distance) * 10; }

temp2.pan -= 30; //-15 degrees
vec_set(temp.x,vector(my.x + fcos(temp2.pan,camera_distance),my.y + fsin(temp2.pan,camera_distance),camera.z));
c_trace(my.x,temp.x,ignore_me|ignore_passable|ignore_models);
IF (result > 0) { result2 += ((camera_distance - result)/camera_distance) * 10; }

camera.pan += result2 * 0.2;



Now the camera will pan based on obstacles around it, in a sense it's as though the camera moves to gt a better angle. It works really well in some cases and not so well in others. It will work well if the level design suits it, should require some tweaking but there's some code for a start. Based on this cool gamasutra article:

http://www.gamasutra.com/gdc2004/features/20040325/giors_02.shtml

Orange Brat posted here:

http://www.coniserver.net/ubbthreads/sho...true#Post681972
Posted By: Orange Brat

Re: Avoidance Camera - 12/26/06 03:14

Yeah, I think that system is more like the Max Payne style camera system. However, your Kingdom Hearts code takes care of the wall clipping issue nicely. I've never seen another publically available one do it (templates included), so it's the ultimate one; thus everyone should at least use the wall collision code if they want a pro style camera. Anyway, I'll test out this implementation later one. Thanks for your continued camera contribs.
Posted By: DavidLancaster

Re: Avoidance Camera - 12/26/06 05:14

Also with that code above, it seems to work best if you only activate it if the player is moving, that way if you stand idle next to a wall the camera wont move as you try and line it up for a jump etc.

You're very welcome Orange Brat

Your information and input on these forums is much appreciated and helped me lots. Your adventure thread is very interesting and informative.
Posted By: molotov

Re: Avoidance Camera - 01/29/07 13:36

Hey DavidLancaster, when I use your camera from the kingdom Hearts Tutorial, and walk up some stairs, the camera starts to shock a bit. Do you have a solution to fix this? Thanks anyway.
Posted By: DavidLancaster

Re: Avoidance Camera - 02/02/07 13:32

The only reason I can think why the camera would shake is because of the way the player is moving up the stairs (ie it's not moving smoothly)...other than that it shouldn't shake, I think, unless you can give me more details.
Posted By: molotov

Re: Avoidance Camera - 02/02/07 14:51

Hey DavidLancaster, the camera is shaking when I move up the stairs but not when I go down the stairs. The movement is running smoothly/perfectly. Also the camera is working great except when I'm moving up a stairway. The stairs is just made of blocks. Don't know how to give more details.
Posted By: DavidLancaster

Re: Avoidance Camera - 02/04/07 03:11

This demo has stairs:

http://www.coniserver.net/ubbthreads/showflat.php/Cat/0/Number/707960/an/0/page/1#Post707960

Camera doesn't shake when running up those...could be the way they are designed though..
Posted By: molotov

Re: Avoidance Camera - 02/04/07 13:29

Hey DavidLancaster, I found out it was the way my stairs were designed. My stairs used too large parts. Thanks for your help.
Posted By: mpdeveloper_B

Re: Avoidance Camera - 02/04/07 13:48

David, this is a great tutorial, i'll be implementing this into PreVa
Posted By: DavidLancaster

Re: Avoidance Camera - 02/04/07 23:38

PreVa rocks, I liked the dodging movement Fun game
Posted By: mpdeveloper_B

Re: Avoidance Camera - 02/05/07 16:06

lol i was supposed to commenting you
Posted By: frozenbaby

Re: Kingdom Hearts Movement Tutorial - 03/21/07 20:13

Firstly, let me say after some time being away from 3dgs, is good to see quality people still giving back to the community. David, good job and I for one appreciate the sharing!

So, I decided to stick your model and scripts into a level I've been toying with for some time - a cavern system of tunnels. They are complex and quite narrow at times. I noted some behaviors of the player script that I have documented with screenies (these were "taken" in windowed mode, using the latest release of 3dgs [v6.50.6]) and running your player script as is:

First one is working just fine - but posted here so you can see how "tight" the space is he has to navigate:


Second - further down that corridor he just "floated" outside:

note the shadow as well. Could that be the cause - casting shadows in tight spaces?

Third, here as he was navigating a corner, the camera did not detect the walls and positioned itself outside - again, note the shadow:


Finally, three shots of both the left and right walls "gone". Note in both wall gone screenies, the sword is piercing the wall (improper scan for collision?):




I really like the player movement ALOT. Thought I would post these here to help in the development of the script. I haven't yet looked through the code closely and run some modification to see if I can help with it's development. But if you have any ideas as to what might help fix it - please post.

Thanks again for the excellent contribution.

-myKael.
Posted By: ambe

Re: Kingdom Hearts Movement Tutorial - 03/21/07 20:39

that model, as you can see(if you press F11 (two times)) steps out of his collision box alot, maby this is the problem?
Posted By: DavidLancaster

Re: Kingdom Hearts Movement Tutorial - 03/22/07 00:10

Thanks for your kind words frozen baby.

If you're using ent_move the collision hull will move through the wall if the player walks into a wall and it is sloping at an angle lower than 90 degrees, it has to be upright or if it slopes it needs invisible collision walls. It's a bug with ent_move or the way the gravity is set up.

Try this code here as it's using c_move with a separate simple entity for the hull:

http://www.coniserver.net/ubbthreads/showflat.php/Cat/0/Number/707960/an/0/page/2#Post707960

If you're worried about the sword going outside the collision box, then you gotta look in the 3DGS manuel about c_move and ent_move, sure it can be done but you will get a huge collision hull and will work in some places and in others not so much.
Posted By: frozenbaby

Re: Kingdom Hearts Movement Tutorial - 03/22/07 17:48

First - thanks David for the link to the lock on code. Tried it out and indeed it did solve problems with collision detection. Our little friend now stays in the corridors. But two "quirks" has developed. No matter where I place him, he sinks into the floor. Even if I place him several quants above the floor, he drops down into the floor. On inclines when walking or running, he rises to floor level, but on flat surfaces while walking or running, sinks again.



This is irregardless of using the p_collide.mdl assigning it player_action as in example level or assigning the action directly to player.mdl.

The second is at times when running, his sword "slips" out of his hand. It catches up but doesn't always stay attached.

EDIT:

I tried him in a simple room with a few objects for collision. He still sinks in and if I used the jump command (space bar) he jumps through the ceiling:



When I walk him out the door, he should fall, but continues walking as if on some invisible plane with no gravity:



Again - GREAT code. I will look through later and try a few things and of course post here if I find any solutions that work to others may benefit.
Posted By: DavidLancaster

Re: Kingdom Hearts Movement Tutorial - 03/25/07 11:07

Does he drop down into the floor in the level the download comes with? Try adding basic blocks to your level and see if you can reproduce the jumping errors you run into.
Posted By: Pappenheimer

Re: Kingdom Hearts Movement Tutorial - 03/25/07 12:19

Quote:

When I walk him out the door, he should fall, but continues walking as if on some invisible plane with no gravity:




That's no problem, because any finished/released level shouldn't have a such 'nowhere'.

It is like this, because underneath is only a block of the skybox or any other block with the passable flag set. This means that the trace which searchs for the ground gets the value zero from the ground, because there is no solid ground. But, zero is the same value as being on ground, ergo: no falling!
Posted By: sPlKe

Re: Kingdom Hearts Movement Tutorial - 03/25/07 13:21

i have a funny problem. sometimes the player in my level (i use this code) falls through a solid floor and walks beneath it, and then walsk up to the zero level like a ramp. anther funny thing is that sometimes the player walks up a ramp like intended but then suddenly gets pushed upwards and then stands in the air. when i leave the ramp, its okay though...
Posted By: DavidLancaster

Re: Kingdom Hearts Movement Tutorial - 03/29/07 09:58

I know that can happen with certain bsp design, I haven't seen anything to suggest the code would cause it.
Posted By: sPlKe

Re: Kingdom Hearts Movement Tutorial - 03/29/07 16:07

fine, now i know i only have to change the palcements of my blocks^^
thanx^^
© 2024 lite-C Forums