Gamestudio Links
Zorro Links
Newest Posts
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
M1 Oversampling
by 11honza11. 04/20/24 20:57
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (rki, AndrewAMD), 426 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Question about lifting entities #259271
04/05/09 07:53
04/05/09 07:53
Joined: Aug 2006
Posts: 96
Netherlands
P
Polypfreak1987 Offline OP
Junior Member
Polypfreak1987  Offline OP
Junior Member
P

Joined: Aug 2006
Posts: 96
Netherlands
Hello all,

I have an entity wich I want to lift with a constant speed. How do I do this? I have the following code already. But it's speed is going up.



Code:
var height = 256.000;

function up() {
	while(height <= 1531) {
		//if(height <= 1531.000) {
			height += 0.002;
		//}
		wait(1);
	}
}

action molen {
	while(my) {
	my.z = height;
		...
		if(key_w == 1) {
			up();
		}
		...
	}
}

So if I pres the key W once, the entity need to move up at a constant speed.

I hope you can help me.

Kind regards.

Re: Question about lifting entities [Re: Polypfreak1987] #259274
04/05/09 08:15
04/05/09 08:15
Joined: Mar 2009
Posts: 88
Walori Offline
Junior Member
Walori  Offline
Junior Member

Joined: Mar 2009
Posts: 88
The reason why the speed is increasing all the time is that the +z increase (could be in your function or action) is called again and again, making your speed increase ^2 all the time.

personally I'd try change the code to:
Code:
if(key_w == 1 && height <= 1531.00){
up();
}

Code:
function up() {
	while(height <= 1531) { 
			height += 0.002;
		wait(1);
	}
}


and move that my.z out of the while loop, because it does put my to 256 on each loop cycle.

Hopefully this helps smile
-Walori

EDIT: Replacing a code, sorry. Just realized you wanted the enitity to move contantly (learn to read <-) which mine did not. with this however it should work, just move the height out from the loop in the action and it should do the trick
-Walori

Last edited by Walori; 04/05/09 08:22.
Re: Question about lifting entities [Re: Walori] #259287
04/05/09 10:05
04/05/09 10:05
Joined: Aug 2006
Posts: 96
Netherlands
P
Polypfreak1987 Offline OP
Junior Member
Polypfreak1987  Offline OP
Junior Member
P

Joined: Aug 2006
Posts: 96
Netherlands
Well, that was not exactly what I mean. Maybe I wasn't clear enough in my first post. When you touch the key (w) and release it again the entity need to go up untill 1531 it reached. And with a constant speed.

Re: Question about lifting entities [Re: Polypfreak1987] #259330
04/05/09 14:12
04/05/09 14:12
Joined: Jul 2007
Posts: 959
nl
F
flits Offline
User
flits  Offline
User
F

Joined: Jul 2007
Posts: 959
nl
you are calling the up fucntions more times and use time_step

if(!proc_status(up))
{
up():
}

height += 0.02*time_step;


"empty"
Re: Question about lifting entities [Re: flits] #259376
04/05/09 18:56
04/05/09 18:56
Joined: Aug 2006
Posts: 96
Netherlands
P
Polypfreak1987 Offline OP
Junior Member
Polypfreak1987  Offline OP
Junior Member
P

Joined: Aug 2006
Posts: 96
Netherlands
Thank you. You helped me a lot. Now I have another question about this. The entity need to come down again. I have the following code for up and down.

Code:
function up() {
	while(height <= 1531) {
		height += 1.5*time_step;
		wait(1);
	}
}

function down() {
	while(height >= 256) {
		height -= 1.5*time_step;
		wait(1);
	}
}

action molen {
	while(my) {
		my.z = height;
		if(key_w == 1) {
			if(!proc_status(up)) {
				up();
			}
		}
		if(key_s == 1) {
			if(!proc_status(down)) {
				down();
			}
		}
		wait(1);
	}
}

This is the problem. When I press the key W it goes up. But when I press the key S when the entity is on his way up, the entity will stop en not comming down. How can I fix this?

Thanks in advance.

Re: Question about lifting entities [Re: Polypfreak1987] #259379
04/05/09 19:35
04/05/09 19:35
Joined: Jul 2007
Posts: 959
nl
F
flits Offline
User
flits  Offline
User
F

Joined: Jul 2007
Posts: 959
nl
simple soultion

Code:

function up() {
	while(height <= 1531 && !key_w) {
		height += 1.5*time_step;
		wait(1);
	}
}

function down() {
	while(height >= 256 && !key_s) {
		height -= 1.5*time_step;
		wait(1);
	}
}





"empty"
Re: Question about lifting entities [Re: flits] #259577
04/06/09 19:02
04/06/09 19:02
Joined: Aug 2006
Posts: 96
Netherlands
P
Polypfreak1987 Offline OP
Junior Member
Polypfreak1987  Offline OP
Junior Member
P

Joined: Aug 2006
Posts: 96
Netherlands
Thank you very much. You helped me a lot laugh

Re: Question about lifting entities [Re: Polypfreak1987] #259592
04/06/09 20:26
04/06/09 20:26
Joined: Jul 2007
Posts: 959
nl
F
flits Offline
User
flits  Offline
User
F

Joined: Jul 2007
Posts: 959
nl
np but i think that this is not the nicest way to do this maby you can explain your think you want to do and maby i can make somthing nicer else this will do also


"empty"
Re: Question about lifting entities [Re: flits] #259794
04/07/09 18:21
04/07/09 18:21
Joined: Aug 2006
Posts: 96
Netherlands
P
Polypfreak1987 Offline OP
Junior Member
Polypfreak1987  Offline OP
Junior Member
P

Joined: Aug 2006
Posts: 96
Netherlands
It is indeed not the nicest way. If I press the "W"-key. The entity suddenly go up. But I want to speed up to a maximum speed. This is the function right now:

Code:
function up() {
	while(height <= 1531 && !key_x) {
		height += 2*time_step;
		wait(1);
	}
}


The 2 is the maximum speed which is needed.

I hope you understand me.

Thanks in advance.

Re: Question about lifting entities [Re: Polypfreak1987] #259808
04/07/09 19:56
04/07/09 19:56
Joined: Jul 2007
Posts: 959
nl
F
flits Offline
User
flits  Offline
User
F

Joined: Jul 2007
Posts: 959
nl
Code:
function up() {
	var i = 0;
	while(height <= 1531 && !key_x) {
		i += 0.1*time_step;
		i = clamp(i,0,2);
		height += i*time_step;
		wait(1);
	}
}


dont know what type fo aceleration you are seaching for but his is the most easly thing to use


"empty"
Page 1 of 2 1 2

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

Gamestudio download | chip programmers | 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