Teleporting entities: Difference between revisions
add |
Add new section Technique 3: "Kicking a Single Path Target Down the Road" |
||
(15 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
Often | Often you want to teleport one or more entities to a specific place and orientation. | ||
== Method 1 - Traditional Scripting Approach == | |||
In Doom3 and likewise TDM, this is straightforward: set the origin and angles of the object inside a script and it will appear where it should. For instance, to teleport the player to, say, a rug called $new_place: | |||
$player1.setOrigin($new_place.getOrigin()); // Does not affect the orientation | |||
Similarly, if you care about the orientation, there are general setAngles() and getAngles() functions you can use. Or the player-specific setViewAngles: | |||
vector east = '0 0 0'; // face east along the X axis in DR. Other directions: north = '0 90 0' (along the Y axis), west = '0 180 0', south = '0 270 0'. | |||
$player1.setViewAngles(east); | |||
TIP: If you need an invisible placemarker in your map as a teleport target, the Method 2 teleport entity discussed next is also ideal for that... an "off label" use. | |||
== Method 2 - Using atdm:teleport == | |||
To make positioning easier and possible without writing scripts, a new '''atdm:teleport''' entity has been added. | |||
=== Basic Example === | |||
* Create the atdm:teleport entity '''{{RMB}} -> Create Entity -> darkmod -> Targets -> atdm:teleport''' | |||
* Move it to the position and orient it the way that the teleported entity/entities should appear | |||
* Link the atdm:teleport to any entities you want to be teleported (Select it, select another entity, then press {{key|CTRL}} + {{key|K}}) | |||
* Create a trigger and link it to the atdm:teleport. Once the trigger activates atdm:teleport, the teleport will happen. | |||
Note: Triggers have a lot of useful spawnargs that can insert delays, make it trigger only once etc. | |||
==== Screenshot ==== | |||
[[Image:Trigger teleport.jpg]] | [[Image:Trigger teleport.jpg]] | ||
=== Teleporting multiple entities === | |||
To teleport more than one entity, you can target them all from the same teleport entity. The targets will be teleported in the order of the target spawnargs, e.g. "target0" first, "target1" second and so on. | |||
However, this would also mean that all targets get teleported to the same location and are thus stuck inside each other. | |||
To fix this, you can use the following spawnargs on each to be teleported entity: | |||
# '''teleport_offset''': Specifies an offset relative to the atdm:teleport entity | |||
# '''teleport_random_offset''': Specifies the magnitude of an random offset that will be added to the final location | |||
= | |||
==== Example: ==== | |||
"teleport_offset" "-32 0 0" // 32 units to the left | |||
"teleport_random_offset" "5 5 0" // -2.5 .. 2.5 units in X and Y direction from that | |||
=== Delays === | |||
The '''atdm:teleport''' entity has two spawnargs that influence the time that the teleport happens: | |||
# '''delay''' - the initial delay in seconds before the first teleport happens | |||
# '''wait''' - the delay between each subsequent teleport | |||
==== Example: ==== | |||
"delay" "1" | |||
"wait" "0.5" | |||
would wait 1 second before the first teleport, and then teleport the second entity 0.5 seconds later (after 1.5 seconds from triggering), the third 0.5 seconds later (so after 2 seconds after triggering) and so on. | |||
== Method 3 - Using info_player_teleport == | |||
As its name indicates, this alternate method, by Stumpy, is just for teleporting the player, not other entities. You create an info_player_teleport entity in your map (NOT an atdm:teleport NOR the func_teleport). The easiest way to find this is to click on the DR Entity Viewer left pane, then type "info_player_teleport" | |||
=== Example === | |||
''Suppose at game start, you want to have the player's start position seem to differ by difficulty level. Simply start the player in a black room (probably any dark plain area will do), wait a moment for worldspawn to subside, then teleport.'' | |||
* Create an info_player_teleport entity, and move it to the first place where you want the player for difficulty Easy. | |||
* Rotate it the way you want the player to face. | |||
* Give it diff_1_nospawn 1 and diff_2_nospawn 1, so it only appears on Easy. | |||
* Clone it for Hard and change above to diff_0_nospawn 1 and diff_2_nospawn 1. | |||
* Clone it for Expert and change above to diff_0_nospawn 1 and diff_1_nospawn 1. | |||
* Create a delay mechanism, and give it the three teleports as targets. Example mechanisms: | |||
** Target a trigger_relay with brief delay from worldspawn | |||
** Create a door (anywhere it can't be seen in the game), and give it auto_open_time 0.01 | |||
== Making an AI Start a Path after Teleporting == | |||
''by Geep 2021, [https://forums.thedarkmod.com/index.php?/topic/9082-newbie-darkradiant-questions/page/414/#comment-459348 due to JackFarmer & geegee]'' | |||
===A Prerequisite=== | |||
For a newly teleported AI to use the path, be sure the area where the AI lands had the relevant "aas" pathing calculation done for it during dmap. This calculation happens if either: | |||
* some AI of the same aas class (e.g., "aas32" for humanoid AI) can get to the area(s) where the path is; or | |||
* pathing support is forced by flooding, e.g., by setting an "aas32_flood" entity on the path's ground brush(es). | |||
===Technique 1: "Wait For Trigger"=== | |||
Create a path_waitfortrigger in your map near the teleport spot. It serves as the start of your path. Add the spawnarg: | |||
target <the first path_corner of the AI's route> | |||
Finally, to your AI, add: | |||
target <name of path_waitfortrigger> | |||
Then, if using the scripting method, your script might look like this: | |||
$myAI.setOrigin($new_place.getOrigin()); // teleport to near the path_waitfortrigger | |||
sys.trigger($myAI); // proceed on from the waitfortrigger | |||
Or, with an atdm:teleport, you could have a trigger_once that targets both it and the AI. | |||
===Technique 2: "Target Change Target"=== | |||
Create a "atdm:target_changetarget" entity (at any convenient location) with spawnargs: | |||
target <name of AI> | |||
add <name of desired path_corner> | |||
The AI initially has no target path node set. After teleportation, arrange to trigger your target_changetarget to add the path_corner. This can be done various ways, e.g., by scripting or a trigger_once_entity. | |||
===Technique 3: "Kicking a Single Path Target Down the Road"=== | |||
''Due to [https://forums.thedarkmod.com/index.php?/topic/9082-newbie-darkradiant-questions/&do=findComment&comment=497048 JackFarmer with testing by grodenglaive and thebigh, 2024]'' | |||
Occasionally, for mysterious reasons (e.g., latent bugginess), patrolling AIs might quit patrolling, lie down, or show other undesired behavior. This is particularly problematic after teleporting. This third method seems more reliable to maintain proper patrolling. | |||
Instead of defining a static series of path nodes (or sub-series bridged by teleports), a single path entity "X" is placed at a starting location. The AI is given one target that always points to X... and then you arrange to teleport X to different locations. You just need to have the AI hit a trigger brush that triggers the teleport before it can reach the path corner. You can also teleport the AI at the same time (if desired to reach an inaccessible area for example) and they will continue walking to the path entity afterwords. | |||
===Visual and Sound Effects During Teleport=== | |||
For how to give a teleporting wizard smoke puffs and sounds at teleport origin and destination, see [https://forums.thedarkmod.com/index.php?/topic/9082-newbie-darkradiant-questions/&do=findComment&comment=497016 this set of 2024 posts by thebigh and JackFarmer]. | |||
{{editing}} | {{editing}} | ||
[[Category:AI]] | |||
[[Category:AI Tutorials]] |
Latest revision as of 20:49, 10 October 2024
Often you want to teleport one or more entities to a specific place and orientation.
Method 1 - Traditional Scripting Approach
In Doom3 and likewise TDM, this is straightforward: set the origin and angles of the object inside a script and it will appear where it should. For instance, to teleport the player to, say, a rug called $new_place:
$player1.setOrigin($new_place.getOrigin()); // Does not affect the orientation
Similarly, if you care about the orientation, there are general setAngles() and getAngles() functions you can use. Or the player-specific setViewAngles:
vector east = '0 0 0'; // face east along the X axis in DR. Other directions: north = '0 90 0' (along the Y axis), west = '0 180 0', south = '0 270 0'. $player1.setViewAngles(east);
TIP: If you need an invisible placemarker in your map as a teleport target, the Method 2 teleport entity discussed next is also ideal for that... an "off label" use.
Method 2 - Using atdm:teleport
To make positioning easier and possible without writing scripts, a new atdm:teleport entity has been added.
Basic Example
- Create the atdm:teleport entity -> Create Entity -> darkmod -> Targets -> atdm:teleport
- Move it to the position and orient it the way that the teleported entity/entities should appear
- Link the atdm:teleport to any entities you want to be teleported (Select it, select another entity, then press CTRL + K)
- Create a trigger and link it to the atdm:teleport. Once the trigger activates atdm:teleport, the teleport will happen.
Note: Triggers have a lot of useful spawnargs that can insert delays, make it trigger only once etc.
Screenshot
Teleporting multiple entities
To teleport more than one entity, you can target them all from the same teleport entity. The targets will be teleported in the order of the target spawnargs, e.g. "target0" first, "target1" second and so on.
However, this would also mean that all targets get teleported to the same location and are thus stuck inside each other.
To fix this, you can use the following spawnargs on each to be teleported entity:
- teleport_offset: Specifies an offset relative to the atdm:teleport entity
- teleport_random_offset: Specifies the magnitude of an random offset that will be added to the final location
=
Example:
"teleport_offset" "-32 0 0" // 32 units to the left "teleport_random_offset" "5 5 0" // -2.5 .. 2.5 units in X and Y direction from that
Delays
The atdm:teleport entity has two spawnargs that influence the time that the teleport happens:
- delay - the initial delay in seconds before the first teleport happens
- wait - the delay between each subsequent teleport
Example:
"delay" "1" "wait" "0.5"
would wait 1 second before the first teleport, and then teleport the second entity 0.5 seconds later (after 1.5 seconds from triggering), the third 0.5 seconds later (so after 2 seconds after triggering) and so on.
Method 3 - Using info_player_teleport
As its name indicates, this alternate method, by Stumpy, is just for teleporting the player, not other entities. You create an info_player_teleport entity in your map (NOT an atdm:teleport NOR the func_teleport). The easiest way to find this is to click on the DR Entity Viewer left pane, then type "info_player_teleport"
Example
Suppose at game start, you want to have the player's start position seem to differ by difficulty level. Simply start the player in a black room (probably any dark plain area will do), wait a moment for worldspawn to subside, then teleport.
- Create an info_player_teleport entity, and move it to the first place where you want the player for difficulty Easy.
- Rotate it the way you want the player to face.
- Give it diff_1_nospawn 1 and diff_2_nospawn 1, so it only appears on Easy.
- Clone it for Hard and change above to diff_0_nospawn 1 and diff_2_nospawn 1.
- Clone it for Expert and change above to diff_0_nospawn 1 and diff_1_nospawn 1.
- Create a delay mechanism, and give it the three teleports as targets. Example mechanisms:
- Target a trigger_relay with brief delay from worldspawn
- Create a door (anywhere it can't be seen in the game), and give it auto_open_time 0.01
Making an AI Start a Path after Teleporting
by Geep 2021, due to JackFarmer & geegee
A Prerequisite
For a newly teleported AI to use the path, be sure the area where the AI lands had the relevant "aas" pathing calculation done for it during dmap. This calculation happens if either:
- some AI of the same aas class (e.g., "aas32" for humanoid AI) can get to the area(s) where the path is; or
- pathing support is forced by flooding, e.g., by setting an "aas32_flood" entity on the path's ground brush(es).
Technique 1: "Wait For Trigger"
Create a path_waitfortrigger in your map near the teleport spot. It serves as the start of your path. Add the spawnarg:
target <the first path_corner of the AI's route>
Finally, to your AI, add:
target <name of path_waitfortrigger>
Then, if using the scripting method, your script might look like this:
$myAI.setOrigin($new_place.getOrigin()); // teleport to near the path_waitfortrigger sys.trigger($myAI); // proceed on from the waitfortrigger
Or, with an atdm:teleport, you could have a trigger_once that targets both it and the AI.
Technique 2: "Target Change Target"
Create a "atdm:target_changetarget" entity (at any convenient location) with spawnargs:
target <name of AI> add <name of desired path_corner>
The AI initially has no target path node set. After teleportation, arrange to trigger your target_changetarget to add the path_corner. This can be done various ways, e.g., by scripting or a trigger_once_entity.
Technique 3: "Kicking a Single Path Target Down the Road"
Due to JackFarmer with testing by grodenglaive and thebigh, 2024
Occasionally, for mysterious reasons (e.g., latent bugginess), patrolling AIs might quit patrolling, lie down, or show other undesired behavior. This is particularly problematic after teleporting. This third method seems more reliable to maintain proper patrolling.
Instead of defining a static series of path nodes (or sub-series bridged by teleports), a single path entity "X" is placed at a starting location. The AI is given one target that always points to X... and then you arrange to teleport X to different locations. You just need to have the AI hit a trigger brush that triggers the teleport before it can reach the path corner. You can also teleport the AI at the same time (if desired to reach an inaccessible area for example) and they will continue walking to the path entity afterwords.
Visual and Sound Effects During Teleport
For how to give a teleporting wizard smoke puffs and sounds at teleport origin and destination, see this set of 2024 posts by thebigh and JackFarmer.