how can I do this?

Posted By: Theil

how can I do this? - 10/07/09 12:38

I want to move an entity toward a specific point without changing the pan of the entity is this possible?, I want to do this because when let's say an enemy attack the player he should move backward while playing he's hurt animation. this is what I have.

On the enemy's code I set this vector so it stays in front of the enemy, some kind marker where the player should move when he's getting hurt:

marker.x = enemy.x + 500 * cos(enemy.pan);
marker.y = enemy.y + 500 * sin(enemy.pan);

On the player's event I have this so when the touches the player he starts moving toward the marker:

vec_set(temp, marker.x);
vec_sub(temp, player.x);
vec_set(temp2, marker.y);
vec_sub(temp2, player.y);
player.x += temp*1*time_step;
player.y += temp2*1*time_step;

The problem with this is that collision won't work.

The other way I found is changing the entity's pan but I don't want to use this because it looks lame:

vec_set(temp, marker.x);
vec_sub(temp,player.x);
vec_to_angle(player.pan, temp);
c_move (player, vector(10 * time_step, 0, 0), nullvector, IGNORE_PASSABLE | GLIDE);


Posted By: Widi

Re: how can I do this? - 10/07/09 14:32

If you want to move without changing the pan,
so you DON`T need:

vec_set();
vec_sub();
vec_to_angle();

This 3 things are only to change the pan. To move the entity you have to use c_move(); if you want the collision. If you set player.x directly, there is no collision.

Use only the following line:
c_move (player, vector(10 * time_step, 0, 0), nullvector, IGNORE_PASSABLE | GLIDE);

Hope that helps....

Posted By: Theil

Re: how can I do this? - 10/07/09 15:23

Thanks for the quick reply laugh
well I've tried that and the only problem with that is that if the player is facing the enemy works just fine but if he's not facing the enemy it won't work since it goes backward and collides with the enemy =/
Posted By: testDummy

Re: how can I do this? - 10/07/09 17:48

Code:
/* sample only: non-functional */
ENTITY* eSrc;
ENTITY* eTarget;
//...
VECTOR vSrc;
VECTOR vTarget;
VECTOR vDir;
//...
vec_set(vSrc, eSrc.x);
vec_set(vTarget, eTarget.x);

// ...
// drop the z of both VECTORs
vSrc[2] = 0;
vTarget[2] = 0;
vec_diff(vDir, vTarget, vSrc); // subtract the src from the target and store it in dir
vec_normalize(vDir, 1);	// normalize it
vec_scale(vDir, time_step); // scale it like a distance
// apply it to the ENTITY which should move towards vTarget / eTarget's pos
c_move(eSrc, NULLVECTOR, vDir, IGNORE_PASSABLE | GLIDE);


Posted By: Theil

Re: how can I do this? - 10/07/09 22:29

Wow it works like a charm shocked
Thank you very much that was so quick :), awesome.
© 2024 lite-C Forums