|
how can I do this?
#292841
10/07/09 12:38
10/07/09 12:38
|
Joined: Sep 2009
Posts: 84
Theil
OP
Junior Member
|
OP
Junior Member
Joined: Sep 2009
Posts: 84
|
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);
Last edited by Theil; 10/07/09 22:29.
|
|
|
Re: how can I do this?
[Re: Theil]
#292847
10/07/09 14:32
10/07/09 14:32
|
Joined: Aug 2007
Posts: 1,922 Schweiz
Widi
Serious User
|
Serious User
Joined: Aug 2007
Posts: 1,922
Schweiz
|
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....
Last edited by Widi; 10/07/09 14:33.
|
|
|
Re: how can I do this?
[Re: Theil]
#292878
10/07/09 17:48
10/07/09 17:48
|
Joined: Oct 2004
Posts: 1,655
testDummy
Serious User
|
Serious User
Joined: Oct 2004
Posts: 1,655
|
/* 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);
|
|
|
|