2 registered members (Akow, SBGuy),
1,423
guests, and 7
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Move an entity towards point without rotating it to it
[Re: mEnTaL]
#315087
03/13/10 10:40
03/13/10 10:40
|
Joined: Sep 2003
Posts: 5,900 Bielefeld, Germany
Pappenheimer
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
|
It should work like the following. It is more pseudo code, I didn't test anything, it is just to give you an idea:
vec_diff(temp, me, you);//this is needed, but not the vec_to_angle vec_lerp(temp, ...); //if you want the speed relating the distance to the target vec_normalize(temp, ...);// if you want a steady speed, in this case you will have to combine it with vec_diff to avoid that it runs beyond the target and back, again and again. c_move(NULLVECTOR, temp, ... );//the first vector is movement relating the entities orientation, the second uses the world's orientation, look into the manual to clarify this.
|
|
|
Re: Move an entity towards point without rotating it to it
[Re: mEnTaL]
#315088
03/13/10 10:43
03/13/10 10:43
|
Joined: Nov 2008
Posts: 354 saeculum II
MPQ
Senior Member
|
Senior Member
Joined: Nov 2008
Posts: 354
saeculum II
|
maybe sth. like this:
while(1) { c_move (sprite, ...) vec_set (vecTemp, sprite.x); vec_sub (vecTemp, camera.x); vec_to_angle (sprite.pan, vecTemp); wait(1); }
new project in early stage...
Intel Xeon X3450 2,66GHz | Mushkin 8 Gib | Zotac GTS250 + 7300LE | A8.3 com
|
|
|
Re: Move an entity towards point without rotating it to it
[Re: Widi]
#315122
03/13/10 12:35
03/13/10 12:35
|
Joined: Jul 2002
Posts: 4,436 Germany, Luebeck
Xarthor
Expert
|
Expert
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
|
void move_WithoutTurn(ENTITY* _ent, ENTITY* _target, var _maxSpeed)
{
VECTOR temp;
vec_diff(temp,_target.x,_ent.x);
if(vec_length(temp) > _maxSpeed)
{
vec_normalize(temp,_maxSpeed);
}
vec_scale(temp,time_step);
c_move(_ent,nullvector,temp,IGNORE_PASSABLE);
}
just from the top of my head. The basic idea was already described by Pappenheimer.
|
|
|
Re: Move an entity towards point without rotating it to it
[Re: mEnTaL]
#315397
03/15/10 08:27
03/15/10 08:27
|
Joined: Jul 2002
Posts: 4,436 Germany, Luebeck
Xarthor
Expert
|
Expert
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
|
I just tested my code and it works as it should. You have to call that function in a while loop or put a while loop into the function itself. Here is my testing set up as zip file (includes all sources): and here is a modified function of the above one which moves the entity the whole way:
/*
* move_WithoutTurn
* This function moves one entity (_ent) towards another entity (_target) without
* rotating the moving entity itself. The maximum movement speed is given through
* _maxSpeed, the minimum distance until this code is executed is _minDist
* requirements: both entity pointers have to be valid!
*/
void move_WithoutTurn(ENTITY* _ent, ENTITY* _target, var _maxSpeed, var _minDist)
{
VECTOR temp;
while(vec_dist(_ent,_target) > _minDist)
{
vec_diff(temp,_target.x,_ent.x);
if(vec_length(temp) > _maxSpeed)
{
vec_normalize(temp,_maxSpeed);
}
vec_scale(temp,time_step);
c_move(_ent,nullvector,temp,IGNORE_PASSABLE);
wait(1);
}
}
|
|
|
|