# entmove.c

This include file contains basic entity position and angle manipulation functions, such as rotating, turning towards a target, moving to a certain position, or moving along a path with a certain speed. The functions are simple enough to understand them at a glance, and to learn from them how to calculate entity positions and angles. If you want to modify them, please edit an entmove.c copy in your work folder, and not the original file in the include folder.

## ent_rotate (ENTITY* ent, var speed_pan, var speed_tilt, var speed_roll)

Starts a permanent rotation about an entity's relative pan, tilt, and roll axis with given angular speed values.

### Parameters:

ent - entity pointer
speed_pan - rotation rate about the pan axis in degrees per tick
speed_tilt - rotation rate about the tilt axis in degrees per tick
speed_roll - rotation rate about the roll axis in degrees per tick

### Remarks:

• The function can be called many times; each call cancels the previous rotation.
• Calling ent_rotate with all speeds at 0 stops the rotation.

### Example:

```action rotating_door(){
while(1) {    ent_rotate(me,2,0,0); // rotate about the entity's vertical axis with 2 degrees per tick
wait(-90/16); // wait ~6 seconds (= 180 degrees)
ent_rotate(me,0,0,0); // stop the rotation
wait(-1); // wait 1 second    ent_rotate(me,-2,0,0); // rotate back
wait(-90/16); // wait ~6 seconds (= 180 degrees)
}
}
```

## ent_turnto (ENTITY* ent, ANGLE* to, var aspeed)

Starts a rotation towards a certain Euler angle with a certain angular speed; stops when the angle is reached.

### Parameters:

ent - entity pointer
to - target Euler angle
aspeed - rotation rate in degrees per tick

### Remarks:

• The function can be called many times; each call cancels the previous rotation.
• Use the wait_for_my(ent_turnto) macro for determining when the angle is reached.

### Example:

`ent_turnto(me,vector(90,0,0),2);wait_for_my(ent_turnto);`

## ent_faceto (ENTITY* ent, VECTOR* pos, var aspeed)

Starts a rotation with a certain angular speed until the entity faces a certain position.

### Parameters:

ent - entity pointer
pos - target position
aspeed - rotation rate in degrees per tick

### Remarks:

• The function can be called many times; each call cancels the previous rotation.
• Call this function with a high aspeed (like 999999) for letting the entity immediately face the target position.
• This function calls ent_turnto. Use the wait_for_my(ent_turnto) macro for determining when the target angle is reached.

### Example:

```action turret()
{
while(1) {
if (player) {
ent_faceto(me,player.x,10); // turn towards the player      wait_for_my(ent_turnto);   // wait until target angle reached
fire(); // fire at player's previous position
}
wait(1);
}
}```

## ent_moveto (ENTITY* ent, VECTOR* pos, var speed)

Starts a movement without collision detection to a certain absolute position.

## ent_moveby (ENTITY* ent, VECTOR* pos, var speed)

Starts a movement without collision detection to a certain position relative to the entity position.

### Parameters:

ent - entity pointer
pos - target position, absolute or relative
speed - speed in quants per tick

### Remarks:

• The function can be called many times; each call cancels the previous movement.
• Call ent_moveby(entity,nullvector,1) for stopping the previous movement.
• Use the wait_for_my(ent_moveto) macro for determining when the position is reached.

### Example:

```action lift()
{
while(1) {
ent_moveby(me,vector(0,0,100),1); // move the lift 100 units upwards    wait_for_my(ent_moveto);   // wait until target position reached
wait(-10); // stop the lift at the upper position for 10 seconds
ent_moveby(me,vector(0,0,-100),1); // move the lift 100 units downwards    wait_for_my(ent_moveto);   // wait until target position reached
wait(-10); // stop the lift at the lower position for 10 seconds
}
}```

## ent_movepath (ENTITY* ent, char* pathname, var speed,var mode)

Moves the entity along a path.

### Parameters:

ent - entity pointer
pathname - name of the path, char* or STRING*; or NULL for using an already-attached path.
speed - speed in quants per tick, or 0 for stopping the entity.
mode - 1 for moving the entity with its feet on the ground, 2 for rotating the entity in move direction.

### Remarks:

• The function can be called many times; each call cancels the previous movement.
• Call ent_movepath(entity,NULL,0) for stopping the previous movement.
• When using mode 1 for placing the entity's feet or wheels on the ground, make sure that all path positions are above the ground.

### Example:

```action patrol()
{
ent_movepath(me,"path1",5,1+2);
}```