Moving on an to center y axis automaticly

Posted By: Realspawn

Moving on an to center y axis automaticly - 07/31/15 15:20

I have this model that i place random in my level.
I need it to move automaticly but it should always move to 0 on the y axis so the models are placed in the air then go down to a cetain hight but always should land on the middle of the screen on the y


Code:
action landing_ufo()

{

	set(my,SHADOW | METAL | POLYGON);
	ufo=me;

	while(1)
	{
		c_move(my, vector(15 * time_step, 0, 0), nullvector, NULL | IGNORE_SPRITES | IGNORE_PASSABLE);
		
		my.z -=2* time_step;


		camera.x = ufo.x+100; 

		camera.z =  1000; 
		camera.tilt = -90;
		wait(1);
		if(plane.z <= -12){

			you_madeit();

			break;
			wait(1);

			
			
		}
	}




any help would be highly aprreciated as it is for a next retro workshop game i have almost finished laugh
Posted By: Kartoffel

Re: Moving on an to center y axis automaticly - 07/31/15 15:31

well you just need to keep moving it towards the y = 0 coordinate and check if it has crossed it (per frame).
when the if comparison is true you simply stop the movement and set it's y coordinate manually to 0 to avoid inaccuracy errors.

soo there's really not much to it...
Posted By: Realspawn

Re: Moving on an to center y axis automaticly - 07/31/15 17:02

forgive me my dumbness laugh i am not that good in understanding sometimes simple logics of code laugh Now the model can be left or right from the center of the Y axis so how to make it go the right direction to 0 ?

i will struggle to solve this grinnnnn but i sometimes get stuck with the simplest things lol laugh

thx anyway
Posted By: Anonymous

Re: Moving on an to center y axis automaticly - 07/31/15 17:07

VECTOR vec_temp

action .....
{
vec_set(vect_temp,my.x);
vec_diff(vec_temp,vector(0,0,0),vec_temp);
vec_normalize(vec_temp,5);

c_move(my, nullvector,vec_temp,.....);



Blind guessing
Posted By: Realspawn

Re: Moving on an to center y axis automaticly - 07/31/15 18:05

and your guessing is most of the time good laugh
i will give it a shot laugh

nice to see you back bro where have you been ? laugh
Posted By: EpsiloN

Re: Moving on an to center y axis automaticly - 07/31/15 18:24

I'm not sure if I understand what you need, but here's what I'm thinking:

In case you want to limit a model in 3D space not to fall below the middle of the screen space, use vec_to_screen to get the screen coordinates of the model and if they are higher than (screen_size.y / 2) stop the falling...
But this requires a static camera height.
Posted By: Anonymous

Re: Moving on an to center y axis automaticly - 07/31/15 22:19

I'm not back... I am a ghost. There is no coming back lol
Posted By: Realspawn

Re: Moving on an to center y axis automaticly - 08/01/15 23:33

no luck yet laugh i need the darn thing go to 0 on y grin lol
i could use my.y = 0; but then it jumps right to it so it
needs to move to zero - on y or + depending which side it is laugh

dang
Posted By: EpsiloN

Re: Moving on an to center y axis automaticly - 08/02/15 14:51

My.y = my.y * 0.95; ? Or other factor...
Posted By: Anonymous

Re: Moving on an to center y axis automaticly - 08/02/15 15:33

Code:
action .....
{
VECTOR vec_temp;
VECTOR vec_temp2;
vec_set(vec_temp,my.x); // set temp vec to my location
vec_diff(vec_temp2,vector(0,0,0),vec_temp); // make temp point from my location to vec 000
vec_normalize(vec_temp2,5*time_step); // set your speed here

c_move(my, nullvector,vector(0,vec_temp2.y,0),.....); // move on the abs to 0 y



And why does this not work?? If you only use the Y axis?

Some simple things you should notice.
1) this has to run in a loop. Walk in you mind loop steps, first run it moves 5 closer to 0y next run 5 more, if it cross 0y it move 5 towards 0y on the next loop.
2) a lock maybe need ... if(my.y != 0)
Posted By: Anonymous

Re: Moving on an to center y axis automaticly - 08/02/15 16:35

Here is the logic chain here
1) locate a vector that points from the player to 0-Y'
2) move along the vector till the player is as close as possible to 0-Y
3) snap the player to 0-Y

secondary logic
1) do not move along the vector unless landing
2) stop the move if landed

logic of the code
1) define vectors
VECTOR vec_temp
Vector vec_temp2

2) set vector to my location
vec_set(vec_temp,my.x)

3) get a abs vector to 0-Y
vec_diff(vec_temp2,nullvector,vec_temp);

4) change the vector length without changing it's direction to get a speed along the direction vec
vec_normilize(vec_temp2,5*time_step);

5) set a lock
if(vec_dist(my.y,vec_temp2.y)>5)

6)move along the direction at speed 5*time_step, along the abs vec
c_move(my,nullvector,vector(0,vec_temp2.y,0),GLIDE);

7) snap to the 0-Y ( step-5 if is now false)
vec_set(vector(0,my.y,0),nullvector);

Posted By: EpsiloN

Re: Moving on an to center y axis automaticly - 08/02/15 18:31

Malice, your code is good, but for 3 dimensions.

Just for one (y) , y * 0.9 is easier and simple, and doesnt need a lock.
Simply scaling down the y pos until it becomes as close as 0, every frame.
Posted By: Anonymous

Re: Moving on an to center y axis automaticly - 08/02/15 18:49

Sure I get it.
muling the my.y by that factor will reduce it towards 0 every frame regardless of the sign of my.y pos.
it is not regulated by time_step.

The basic logic is a mul by .9 reduces the my value by 10% and to increase the shift rate you decrease the decimal value.
So then a mul by .75 will decrease the my.y pos by 25% per loop.

I understand, but does the OP understand. We both present a logic design to achieve the same effect. But if the OP doesn't see the logic then they can never use that logic to create variation for similar effects.
Posted By: EpsiloN

Re: Moving on an to center y axis automaticly - 08/02/15 19:09

You are right.

I started with 3dgs so i never learned to design programs. I recently picked up that skill from a Java tut and now I know what I've been missing for the past 15 years laugh
© 2024 lite-C Forums