Question about lifting entities

Posted By: Polypfreak1987

Question about lifting entities - 04/05/09 07:53

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.
Posted By: Walori

Re: Question about lifting entities - 04/05/09 08:15

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
Posted By: Polypfreak1987

Re: Question about lifting entities - 04/05/09 10:05

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.
Posted By: flits

Re: Question about lifting entities - 04/05/09 14:12

you are calling the up fucntions more times and use time_step

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

height += 0.02*time_step;
Posted By: Polypfreak1987

Re: Question about lifting entities - 04/05/09 18:56

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.
Posted By: flits

Re: Question about lifting entities - 04/05/09 19:35

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);
	}
}



Posted By: Polypfreak1987

Re: Question about lifting entities - 04/06/09 19:02

Thank you very much. You helped me a lot laugh
Posted By: flits

Re: Question about lifting entities - 04/06/09 20:26

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
Posted By: Polypfreak1987

Re: Question about lifting entities - 04/07/09 18:21

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.
Posted By: flits

Re: Question about lifting entities - 04/07/09 19:56

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
Posted By: Polypfreak1987

Re: Question about lifting entities - 04/08/09 17:50

That was the exact aceleration what I wanted. Thank you.

I have another question. I want to stop the entity when it is on his way up (with the key "s") at every height you may choose.

I thought it was easy with:
Code:
height = height;


But that didn't work.

Thanks in advance.
Posted By: flits

Re: Question about lifting entities - 04/08/09 19:56

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


i geus you want to control it white the keys:
w = up
s = stop
x = down

and

Code:
height = height;

wont make any sense because the while loop is still running and 1=1 and 2=2 so it get increased every frame
© 2024 lite-C Forums