My movement script isn't working correctly, please help me. :)

Posted By: Max_Prower

My movement script isn't working correctly, please help me. :) - 03/01/09 09:38

Hey all, I'm having a little bit of trouble with this movement script. Basically what I've done is added a variable for movement speed (as variables automatically have an XYZ value) and given them a default value of zero. After that I added an ent_move function with relative movement as my move variable.

Then I made a while loop that changes move_var's y value to 20 while the W key is pressed which moves it forward. But when I try to copy the while loop and assign it to a different key (so that I can make it move in all directions) it either only moves forward when I press W (as if ignoring the new while loop), or stops the movement working all-together.

I simply can not figure out what I should do. I would be deeply appreciative if you could help me sort this out. Here is my script so far (the one that works):

Code:
var move_var;

action PlayerAct
{
	move_var.x = 0;
	move_var.y = 0;
	move_var.z = 0;
	move_mode = GLIDE;
	while(1)
	{
		ent_move (move_var, nullvector);
		wait(1);
	while(!key_w)
	{
		move_var.y = 20;
		wait(1);
	}
	}
	}


And here is where it doesn't work:
Code:
var move_var;

action PlayerAct
{
	move_var.x = 0;
	move_var.y = 0;
	move_var.z = 0;
	move_mode = GLIDE;
	while(1)
	{
		ent_move (move_var, nullvector);
		wait(1);
	while(!key_w)
	{
		move_var.y = 20;
		wait(1);
	}
	
	while(!key_s)
	{
		move_var.y = -20; //This one doesn't work, and stops the other one from working as well.
		wait(1);
	}
	}
	}

Posted By: MPQ

Re: My movement script isn't working correctly, please help me. :) - 03/01/09 10:23

the second script cannot work:

if key w is not pressed (!key_w), your player will move 20Q

coincident if key s is not pressed (!key_s), your player will move -20Q

This combination cannot work. Which kind of movement do you want? The movement does not seem to be functionally!

Code:
while (1)
{
   if (key_w)
      move_var.y += 20;
   if (key_s)
      move_var.y -= 20;
}




Posted By: Max_Prower

Re: My movement script isn't working correctly, please help me. - 03/01/09 10:45

Any movement that moves whilst I hold a key down and not at any other time is the kind I'm looking for.

Code:
while (key_w == on)
		{
move_var.y = 20;
wait(1);
}


For some reason, this makes it so that when I press W and let go, it moves until I hold it down again.
Posted By: MPQ

Re: My movement script isn't working correctly, please help me. - 03/01/09 11:00

use my code i ve written in the last post without the "+" and "-".




Posted By: Max_Prower

Re: My movement script isn't working correctly, please help me. - 03/01/09 11:08

It doesn't work. Perhaps I should just scrap the whole variable idea and use c_move because that seems to work? Or is there some advantage in using variables?
Posted By: MPQ

Re: My movement script isn't working correctly, please help me. - 03/01/09 11:21

try this (maybe there are mistakes^^) i did not test it
Code:
VECTOR move_vector;

action PlayerAct
{
	VECTOR* move_vector = nullvector;

	
	while(1)
	{
		if (key_w) 
			move_var.y = 20;//move 20, if key w is pressed
		
		if (key_s)
			move_var.y = -20;//move -20, if key s is pressed
		
		if ((!key_w && !key_s) || (key_w && key_s)) //if both keys are pressed or not pressed!!
			move_car.y = 0; // if no key is pressed, set 0
		
		c_move (my, move_vector, nullvector, GLIDE);
		
		wait(1);
	}
}

Posted By: Max_Prower

Re: My movement script isn't working correctly, please help me. - 03/01/09 11:27

Thank-you, but I already worked out a working script. smile
Posted By: MPQ

Re: My movement script isn't working correctly, please help me. - 03/01/09 11:31

ok ;), what kind of game do you program?
Posted By: Max_Prower

Re: My movement script isn't working correctly, please help me. - 03/01/09 11:33

I'm trying to program my first game without templates, a third person shooter. The gameplay and graphics will be similar to American Mcgee's Alice. But the plot will be differnt and all that. It will follow the same principle though: The world's gone up-side down, the hero has to set it right.

At the moment, I'm trying to make a script that jumps when I press space; but I don't know how to do that. >.<
Posted By: MPQ

Re: My movement script isn't working correctly, please help me. - 03/01/09 11:48

this is not so difficult as it looks^^, think about it...
Posted By: Max_Prower

Re: My movement script isn't working correctly, please help me. - 03/01/09 11:53

Well I was thinking of something to do with c_trace, say, if it wasn't touching the floor you couldn't jump again.
Posted By: MPQ

Re: My movement script isn't working correctly, please help me. - 03/01/09 12:04

why, at the moment i program the gravitation for my entity with c_trace and it is working well.
Posted By: Max_Prower

Re: My movement script isn't working correctly, please help me. - 03/01/09 12:06

I don't know how to use c_trace, though...
Posted By: MPQ

Re: My movement script isn't working correctly, please help me. - 03/01/09 12:10

have a try you will get it out
Posted By: Max_Prower

Re: My movement script isn't working correctly, please help me. - 03/01/09 12:28

Well I know the c_trace command. But how would I impliment it into a gravity scrpt?
© 2024 lite-C Forums