Movement code + AutoJumping

Posted By: 3run

Movement code + AutoJumping - 01/22/16 21:20

A small demo (experiment) of a movement code which combines Superku's gravity code and simple horizontal movement code (I used two different bbox models, one for horizontal movement and another one for vertical). Plus it has some simply animations and 3rd person camera that has collisions. There is an auto-jump thing I was inspired from old school type of games like Zelda on Nintendo 64. To make it work in your games with this code, you have to make sure that the surface from which you want to perform auto-jumping should have FLAG6 set in WED (look into the level setup of this demo via WED). There are a lot of things to tweak actually, so play with the code if you want to. Anyway, I hope someone might find this useful. I want to thank Superku for his awesome gravity code, and MasterQ32 for giving me some math tips tongue

Quote:
CONTROLS:
WASD - movement
SPACE - jump
SHIFT - run
MOUSE RIGHT + MOUSE MOVEMENT - rotate camera
MOUSE WHEEL - zoom


Here it is:
Download link

Useless screen (it looks promissing, I know):


Edit: I've uploaded new version, with a small bug fixes and smoothed Z movement up on stairs (could be tweaked as well).
Edit2: UPDATED! Even more fixes...

Best regards!
Posted By: LawnmowerMan

Re: Movement code + AutoJumping - 01/23/16 16:35

Thank you, it is very useful
Posted By: Superku

Re: Movement code + AutoJumping - 01/23/16 18:33

Pretty solid indeed, good job!
Posted By: 3run

Re: Movement code + AutoJumping - 01/23/16 18:36

Originally Posted By: LawnmowerMan
Thank you, it is very useful
You are welcome! Happy to hear that it's useful.

Originally Posted By: Superku
Pretty solid indeed, good job!
Thank you! To be honest I didn't even hope to get good results at first try, cause I always failed before (I tried for about 3-4 times in the past).

Best regards!
Posted By: Steempipe

Re: Movement code + AutoJumping - 01/23/16 18:49

Good work! I enjoyed running it and it will be a great learning tool later.
Posted By: 3run

Re: Movement code + AutoJumping - 01/23/16 19:04

Thank you! I hope it will be useful!

Edit: I'm working on a movement code that works with native physX (character controller). So maybe soon we'll have another contribution! grin
Edit2: Just a little screenshot:

Quote:
DONE:
* graivity + jumping (to traces)
* simple trigger example
* cloth setup example (almost same as in samples folder)
TO DO:
* crawling

Best regards!
Posted By: tagimbul

Re: Movement code + AutoJumping - 02/10/16 14:53

hey i have a cool adition for your code grin

downside the code line who you have write
Code:
if(heroallowMove == 1)



make this here
Code:
if(my.SPEED_Z > 0)
{
DEBUG_VAR(my.SPEED_Z,30);
vec_set(toVec, vector(my.x, my.y, my.z + 18 ));
// trace UP to it from our origin position:
COLLISION_UP = c_trace(my.x, toVec, TRACE_FLAGS | IGNORE_FLAG2 | SCAN_TEXTURE | USE_BOX);
}
else
{
COLLISION_UP = 0;
}
 
DEBUG_VAR(COLLISION_UP,50);	
if(COLLISION_UP != 0)
my.SPEED_Z = 0;



and in the begin of the action make
Code:
var COLLISION_UP = 0;




its make a trace from he ca. middle to ha higer place and if this trace contact with something above hem if he Z_SPEED = 0 and he fall down

and know have the player collision to the things upside from hem
=)
Posted By: tagimbul

Re: Movement code + AutoJumping - 02/10/16 19:25

A fix:

search this line
Code:
// rotate angle towards the movement input:	
vec_to_angle(LERP_ANGLE.pan, ABS_DIST.x);




and change it to this:

Code:
if(FORCE.x != 0 | FORCE.y != 0)
vec_to_angle(LERP_ANGLE.pan, ABS_DIST.x);


the reason is:
ABS_DIST go, if the player dont move, all three af 0
but vec_to_angle continues
and the my.parent.pan rotate slowly to a false direction
but with this fix is my.parent.pan, after stop moving, on the right direction

greets tom
=)
Posted By: 3run

Re: Movement code + AutoJumping - 02/10/16 21:37

Thank you for your help with improving this man. Keep it up! laugh

Greets!
Posted By: tagimbul

Re: Movement code + AutoJumping - 02/13/16 02:18

hey.

here is a update and i need help:

new functions:
-plattforms
-collision to cover
-slide down to steep slope
https://youtu.be/1n9DDK_NApg

the function works greatly but...

i try to make a climb code
in the video you can see the animation
if the model have hes last frame from the climb animation
i set the position of the position from this last frame

the last frame have the same frame from the stand animation
but if the player set new i can see fragments by moving....

have anyone a idea to make this better?....

here the project zip:
http://www9.zippyshare.com/v/3qazMTOa/file.html

search in the code:
// BUG ZONE

greest tom
Posted By: 3run

Re: Movement code + AutoJumping - 02/13/16 08:16

Hi!

I gave you working example of climbing code, that's all I can help you with. I have to time to support this movement code any farther (and it actually has everything for a basic movement that I wanted to provide), and I don't have any time to work on your project too. Climbing example that I gave you moves player (of cause with his bbox) smoothly, to the top of the edge, not as on your video, where you just play climbing animation, and then set player's position (or something like that). This climbing example was taken and converted into lite-c by me (back in 2013) from from old c-script example called zelda movement code as far as I remember. You just need to implement it into the movement code that you currently have.



Greets
Posted By: tagimbul

Re: Movement code + AutoJumping - 02/24/16 15:55

i have it <3
https://youtu.be/KatbVupcbYM

grin
work steps:

1. i have merge the level in the MED to my player model
2. i make a climb animation for one height
3. write in all frames, the position of the master bone and then delete the position of the master bone in all frames and set it to the same position (only XYZ, not pan tilt roll).
4.save the model
5. in the SED in the HeroXYCollision i add this

Code:
VECTOR climb1_bones_pos[11];
	vec_set(climb1_bones_pos[0],vector(0,0,0));
	vec_set(climb1_bones_pos[1],vector(0.75,0,2.875));
	vec_set(climb1_bones_pos[2],vector(5.875,0,7.375));
	vec_set(climb1_bones_pos[3],vector(7.25,0,13.87));
	vec_set(climb1_bones_pos[4],vector(10.25,0,14.37));
	vec_set(climb1_bones_pos[5],vector(10.25,0,13.37));
	vec_set(climb1_bones_pos[6],vector(10.25,0,14));
	vec_set(climb1_bones_pos[7],vector(10.37,0,15.5));
	vec_set(climb1_bones_pos[8],vector(11.35,0,22.55));
	vec_set(climb1_bones_pos[9],vector(12.36,0,31.03));
	vec_set(climb1_bones_pos[10],vector(15.62,0,31.87));
	
	VECTOR climb1_to_pos[10];
	var ci;
	for (ci=0; ci<10; ci++) // repeat 10 times
	{
		vec_diff (climb1_to_pos[ci],climb1_bones_pos[ci],climb1_bones_pos[ci+1]);
	}



6.
in the end of the while loop in the same function i add this
Code:
if(key_q)
		{

			if(climb_percent < 10 &&  climb_percent >= 0)
			climb_frame = 0;
			if(climb_percent < 20 &&  climb_percent >= 10)
			climb_frame = 1;
			if(climb_percent < 30 &&  climb_percent >= 20)
			climb_frame = 2;		
			if(climb_percent < 40 &&  climb_percent >= 30)
			climb_frame = 3;		
			if(climb_percent < 50 &&  climb_percent >= 40)
			climb_frame = 4;		
			if(climb_percent < 60 &&  climb_percent >= 50)
			climb_frame = 5;		
			if(climb_percent < 70 &&  climb_percent >= 60)
			climb_frame = 6;		
			if(climb_percent < 80 &&  climb_percent >= 70)
			climb_frame = 7;
			if(climb_percent < 90 &&  climb_percent >= 80)
			climb_frame = 8;		
			if(climb_percent < 100 && climb_percent >= 90)
			climb_frame = 9;		
			
			
			
			
			
			
			//derzeitige position
			
			
			
			
			//ziel position
			
			if(climb_percent == 0 ||climb_percent == 10 ||climb_percent == 20 ||climb_percent == 30 ||climb_percent == 40 ||climb_percent == 50 ||climb_percent == 60 ||climb_percent == 70 ||climb_percent == 80 ||climb_percent == 90)
			{
				vec_set(hero_temp1, my.x);
				vec_set(hero_temp2, my.x);
				vec_set(climb1_to_pos_temp, climb1_to_pos[climb_frame]);
				vec_add(hero_temp2, 	vec_rotate(climb1_to_pos_temp, my.parent.pan));
				lerp_time = 0;
			}
			
			
			if(lerp_time <= 10)
			vec_lerp(hero_climb,hero_temp1,hero_temp2,-lerp_time*0.1);
			lerp_time+=1;
			if(climb_percent < 100)
			vec_set(my.x,vector(hero_climb.x,hero_climb.y,hero_climb.z+0.32));
			
			//		climb_dist = vec_dist(hero_temp1,hero_temp2);
			
			DEBUG_VAR(lerp_time,80);
			
			//wenn var mode auf 0 ist dann ist die animation linear und geht von 0 bis 100 und alles über 100 bleibt stehen
			ent_animate(my.parent,"climp", climb_percent ,0);
			climb_percent += 1;
			TX_Pvec(hero_climb);
			
		}
		else
		{
			climb_percent = 0;
			
		}


7. and by this line

Code:
my.z = heroEnt.z + Z_BBOX_SIZE - 8;



i change to this
Code:
if(!key_q)
my.z = heroEnt.z + Z_BBOX_SIZE - 8;




later i change key_q to a variable =)
Posted By: tagimbul

Re: Movement code + AutoJumping - 03/21/16 05:41

i have make a path interpolation code vor vec array's =)

Code:
function vec_arr_pfad_interpolation(VECTOR* v_out, VECTOR* v_arr, var v_arr_length,var zeit, var faktor)
{
	var aktives_segement;
	var integer_aktives_segement;
	aktives_segement = (faktor/zeit)*(v_arr_length -1);
	integer_aktives_segement = integer(aktives_segement);
	vec_lerp(v_out, v_arr[integer_aktives_segement],v_arr[integer_aktives_segement+1], fraction(aktives_segement));
}



i have make more animations for climbing
and this code make my player action smarter wink
Posted By: 3run

Re: Movement code + AutoJumping - 03/21/16 10:05

Great to hear that you are making a nice progress with this code!
Use code tags next time, that way it will be easier to read your code.
[code]YOUR CODE HERE![*/code] - without *

Best regards
Posted By: tagimbul

Re: Movement code + AutoJumping - 03/21/16 16:39

i have edit it =)
Posted By: 3run

Re: Movement code + AutoJumping - 03/21/16 16:47

Now it looks way much better, but you left some other posts on the first page tongue

Best regards!
Posted By: tagimbul

Re: Movement code + AutoJumping - 03/21/16 16:53

ok i have edit ^^
Posted By: tagimbul

Re: Movement code + AutoJumping - 03/25/16 16:57

Code:
function vec_arr_pfad_interpolation(VECTOR* v_out, VECTOR* v_arr, var v_arr_length,var zeit, var faktor)
{
	float aktives_segement;
	var integer_aktives_segement;
	aktives_segement = (faktor/zeit)*(v_arr_length -1);
	integer_aktives_segement = integer(aktives_segement);
	vec_lerp(v_out, v_arr[integer_aktives_segement],v_arr[integer_aktives_segement+1], fraction(aktives_segement));
}



its better with a float...
now its possible to use arrays with a size of 1000+
^^
then floats have a deeper decimal place its important for the fraction by big vector arrays
© 2024 lite-C Forums