Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
3 registered members (NewbieZorro, TipmyPip, 1 invisible), 19,045 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Noob problem #406542
08/23/12 14:51
08/23/12 14:51
Joined: May 2009
Posts: 5,377
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,377
Caucasus
I'm playing with my old movement script, trying to find and fix bugs.
I've found out, that if I do not limit FPS at 60, then I get strange jumping behavior..
I've even found the line which caused that, here it is:
Code:
var gravity = 6;
var slope_fac = 0.5;


absforce.z = -gravity;
move_var = maxv((1 - time_step * friction), 0);
my.dist_z = (time_step * absforce.z) + (move_var * my.dist_z);
absdist.z = my.dist_z * time_step;

if(my_height < bbox_offset){
	if(my_floornormal.z > slopefac / 4){
		absdist.z = -maxv(my_height, -10 * time_step); // this line 
		absdist.z = clamp(absdist.z, -5, 5);
		if((my_height + absdist.z) > 10){
			absdist.z = -my_height -10; 
		}
	}			
	if(force.z > 0){
		jump_target = jump_height - my_height;
	}
}

If I comment that line, jumping stuff disappears.. but without it I lose smooth movement down on slopes.
Any ideas? May be someone already faced something like this. Originally script is taken from A5 movement template.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Noob problem [Re: 3run] #406554
08/23/12 17:50
08/23/12 17:50
Joined: Jul 2002
Posts: 3,208
Germany
Error014 Offline
Expert
Error014  Offline
Expert

Joined: Jul 2002
Posts: 3,208
Germany
What value does my_height have? If it's bigger than zero, then the marked line will quite obviously always return -my_height, which may or may not be something you want.

It probably isn't. Check the signs laugh


Also, what framerate are we talking here? If we use vars, I wouldn't be too shocked if their inaccuracies add up fast here with small values (which time_step tends to have if your FPS goes beyond the insane)


Perhaps this post will get me points for originality at least.

Check out Dungeon Deities! It's amazing and will make you happy, successful and almost certainly more attractive! It might be true!
Re: Noob problem [Re: Error014] #406555
08/23/12 18:03
08/23/12 18:03
Joined: May 2009
Posts: 5,377
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,377
Caucasus
Thank you for the response! laugh "my_height" is distance to ground, which I get from "c_trace" and lowest point of the BBOX:
Code:
vec_set(vecFrom, my.x);
vec_set(vecTo, my.x);
vecTo.z -= 4000;
c_trace(vecFrom, vecTo, trace_mode);  
// get lowest point of BBOX:
vec_for_min(temp_vec, my);
// get distance to ground:
my_height = my.z + temp_vec.z - target.z;

I mostly use variables (such as "my_heigh" etc). But I didn't understand your last question, sorry for my English man.
If you asked what framerate (fps_max) am I aiming for, then I'd say "60" laugh If I don't limit, I get stable 512 fps and jumping behavior.

Edit: BTW, thank you! I guess you were right! When I changed "-10" into positive value in this line:
Code:
absdist.z = -maxv(my_height, -10 * time_step);

Jumping problem disappeared! laugh But now, movement on slopes isn't smooth (it's almost smooth, jerking a little bit).
When I limit max fps by 60, it's very smooth (as it was before changes) on slopes! laugh But still if I try it with 512, it isn't.


EDIT2: I've increased that positive value from 10 into 100, and it's smooth now laugh But I need to test it. Maybe that will affect on something...
Math was always my weak point.. smirk Thank you once again my friend! I appreciate it!

EDIT3: I've found what was causing those little jerking stuff on slopes! laugh That wasn't gravity stuff (I fixed it completely with your help)!!
Problem was with camera Z smoothing script, but it works perfect now! laugh Thanks once again!!!

Last edited by 3run; 08/23/12 18:29.

Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Noob problem [Re: 3run] #406556
08/23/12 18:39
08/23/12 18:39
Joined: May 2009
Posts: 5,377
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,377
Caucasus
Sorry for double post, but now I faced an other strange problem with camera.
I use the following script to make Z movement of camera smoother (on stairs etc):
Code:
vec_set(camera.x, vector(my.x, my.y, camera.z));
vec_set(cam_pos.x, vector(0, 0, 30)); // 30 is Z height of camera
vec_rotate(cam_pos.x, my.pan);
vec_add(cam_pos.x, my.x);
vec_lerp(camera.x, camera.x, cam_pos.x, 0.5 * time_step); // 0.5 smooth factor

If I set camera's position with "vec_set" instead of "vec_lerp", movement is perfectly smooth, other ways it jerks a little bit.
I tried to lerp without "time_step", but I get same results.. Used to make it smoother without "vec_lerp" with this:
Code:
camera.x = cam_pos.x;
camear.y = cam_pos.y;
camera.z -= (camera.z - cam_pos.z) * time_step;

But results are the same.. Camera jerks a little bit, what could cause that? It only happens if I don't limit fps as well.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Noob problem [Re: 3run] #406558
08/23/12 19:04
08/23/12 19:04
Joined: Jul 2002
Posts: 3,208
Germany
Error014 Offline
Expert
Error014  Offline
Expert

Joined: Jul 2002
Posts: 3,208
Germany
Okay, let's talk about your camera code. That used to be my specialty, anyhow. laugh

You set camera.x to the player's position (only not caring about z - probably NOT a wise idea). Then, you calculate another camera position that lies 30 quants above the player. Note that if your player's tilt (and roll) is 0 (as it is in most games), the vec_rotate line will have no effect (apart from making the game slower).
Then, you lerp between those position. The net effect is that you lerp between two coordinates, one taking care of x/y, and the other of z. That's an unusual behaviour.

If you want a first-person perspective, you probably want to go:

Code:
vec_set(camera.x,my.x);
vec_set(camera.pan,my.pan);
camera.z += SOMETHINGSOMETHING; //for instance, "0.9*my.max_z", or 30 in your example



(at least for the simple case of tilt=roll=0).

If you want to smooth it, then simply smooth it! grin

Code:
vec_set(cam_pos.x,my.x);
cam_pos.z += 30; 
vec_diff(temp,cam_pos,camera.x);
vec_scale(temp,clamp(1-0.5*time_step,0,1)); //0.5 being camera speed
//ALTERNATIVELY, if you prefer a constant speed:
//vec_normalize(temp,minv(vec_length(temp),10*time_step)); //10 being camera speed
vec_add(camera.x,temp);

//and something similar with the angles:
camera.pan -= ang(camera.pan-my.pan)*minv(1,0.5*time_step);
camera.tilt = 0;
camera.roll = 0;



I've assumed that your tilt and roll is always zero.

EDIT: I realized later with a creeping horror I didn't talk much about what caused the problem in the first place, and my disappointing take on it is "it's complicated". laugh It's a bit hard to name the one detail that caused it in your game, but your way of handling camera movement still seems a bit strange to me, it's two different ways to do it put together. Since I don#t know the exact placement of the camera code, I'd rather guess that what you see is a relatively accurate "jerking" of the z-coordinate that can come about when you do several micro-adjustments, that tend to change in value, rather strongly so in relative terms. But that's a wild guess, and probably a bad one at that. What kind of "jerking" are we talkin' here?

~
Sidenote:

With the line


camera.z -= (camera.z - cam_pos.z) * time_step;

Remember that for very LOW framerates (<16), time_step is actually bigger than one, and you end up overshooting. So you'll want to correct that, for instance by using minv(1,time_step) - but that's just an aside.


Last edited by Error014; 08/23/12 19:09.

Perhaps this post will get me points for originality at least.

Check out Dungeon Deities! It's amazing and will make you happy, successful and almost certainly more attractive! It might be true!
Re: Noob problem [Re: Error014] #406559
08/23/12 19:22
08/23/12 19:22
Joined: May 2009
Posts: 5,377
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,377
Caucasus
I've found out that increasing "10" into "100" in gravity code affected on stairs movement. Now player can't walk up on slopes, but movement on slopes is extremely smooth. I'm thinking on how to fix that (player can't walk up on even very small stairs). But if I leave it as a negative value (-10) and limit FPS at 60, then everything works perfect (smooth movement on slopes and stairs). About the TILT and ROLL angles of camera. I change camera's TILT for aiming up and down, plus I change ROLL angle for making an explosion effects. I don't change player's TILT and ROLL angles (that's why I tried to use "my.pan" for "vec_rotate" instead of "camera.pan"). I rotate it with player's PAN angle only cause I use blobbing camera effect (see this line: "vec_set(cam_pos.x, vector(0, 0, cam_height));", I use variables for Y and Z additional to cam_height). If I won't use that blobbing effect, I would remove "vec_rotate" cause as you said it's not necessary laugh

Edit: laugh By jerking I mean that camera's Z position moves up and down a little bit while moving down on slopes (fast). If I use "vec_set" without lerping everything works good.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Noob problem [Re: 3run] #406560
08/23/12 19:50
08/23/12 19:50
Joined: Jul 2002
Posts: 3,208
Germany
Error014 Offline
Expert
Error014  Offline
Expert

Joined: Jul 2002
Posts: 3,208
Germany
You probably don't want to change the player's tilt (as is impled with my.tilt) - you should only change the camera's tilt for bobbing. Same with roll and explosion-effects.

Anyway, I'm a bit lost as to what exactly is working and what isn't. My apologies, but could you summarize the situation once more? laugh


Small note: I know you've used the yellow color to make things easier to read, and I think thats very nice of you - its just that I'm using the white colorscheme, and it actually makes it harder to read. You could use red color for that, then I suppose even I could read it just fine. laugh


Perhaps this post will get me points for originality at least.

Check out Dungeon Deities! It's amazing and will make you happy, successful and almost certainly more attractive! It might be true!
Re: Noob problem [Re: Error014] #406571
08/24/12 06:35
08/24/12 06:35
Joined: May 2009
Posts: 5,377
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,377
Caucasus
OK, I didn't know about white color scheme laugh So, to summarize all problems which I've found out:

* gravity problem, I've found out the way to fix that jumping behaviour (when FPS isn't fixed and more than 60).
I've fixed it in this line, by changing negative "-10" into positive value "100":
Code:
absdist.z = -maxv(my_height, -10 * time_step); // caused problem
absdist.z = -maxv(my_height, 100 * time_step); // works smooth

After that gravitation worked smooth enough (no jumping) and movement on slopes was smooth too.
But after some little tests, I've found out that this fix affected on stairs movement, so now I can't walk up on them.
I can't walk up on any small stair or even a small object, which is even one quant higher than ground floor.
So, when I returned negative value in that line above ("-10"), and limited FPS at 60, everything worked smooth (slopes, stairs).
But everything works perfect, only if FPS is limited to 60, if it's higher player stars jumping (even if he doesn't move at all).


* camera problem. I don't change player's TILT and ROLL, only camera's TILT and ROLL changed for effects (blobbing, explosions, recoil).
I need to rotate "cam_pos" vector with player's PAN cause I use blobbing offset for camera's positions (Y and Z). See this line:
Code:
vec_set(cam_pos.x, vector(0, 0, cam_height));

I tried to lerp camera's Z, but as I see it wasn't a good idea. BTW smoothing Z position works perfect when FPS is limited to 60.

SUMMARIZE:
- by fixing jumping behavior on hight FPS I've faced another problem (can't walk up on stairs), by fixing which I face first problem again (jumping behavior).
- I'm a little bit confused that it works on small FPS (60) and jerks off on high one (512).

BTW. I use physX (PH_CHAR) for movement, not "c_move" (I don't really like how it works for FPS).

Edit: Hm... With previous version of GS (8.30.5) after changing "-10" into "100" my character still can climb up the stairs and movement is really smooth.
But if I test the same script with the latest beta (8.40.1), player stucks (lowered "min_z", no results). And I've found really interesting thing:
Originally Posted By: Version 8.30 compatibility notes
The height of a PH_CAPSULE shape was now adapted to the model height. It was smaller in prior versions. This can lead to a slightly different collision behavior.
Could this be somekind of bug (fast implementation or fix)? Or does my script really work wrong...

Last edited by 3run; 08/24/12 07:08.

Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Noob problem [Re: 3run] #406573
08/24/12 07:06
08/24/12 07:06
Joined: Nov 2011
Posts: 274
de
lemming Offline
Member
lemming  Offline
Member

Joined: Nov 2011
Posts: 274
de
Originally Posted By: 3run

- I'm a little bit confused that it works on small FPS (60) and jerks off on high one (512).


I had that problem too. I guess it's because time_step can has values between 0,1 and 10 (at least that's what the manual says). But at 512 fps time_step should have 0,031 as a var (16/512 = 0,03125) which is below 0,1. Limiting to 60 fps helped me there.

Re: Noob problem [Re: lemming] #406574
08/24/12 07:11
08/24/12 07:11
Joined: May 2009
Posts: 5,377
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,377
Caucasus
I've edited previous post mate, if you had any problem with PH_CHAR with latest beta, I guess that the problem.
I will use "minv(1, time_step);" as Error014 said, to prevent such problems. But that won't help on jumping stuff.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1