Switch: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
m (Unicodifying, replaced: [[Image: → [[File: (7))
 
(24 intermediate revisions by 11 users not shown)
Line 1: Line 1:
==Introduction==
{{DISPLAYTITLE: Portal - Tutorial - Switch}}
This tutorial will show you how to create a switch that when pushed will go in and tick for a certain amount of time, then pop back out.
{{lang|Switch}}
{{back | Portal Level Creation}}
__NOTOC__
This tutorial will show how to create the '''switch''' seen throughout the later test chambers of [[Portal]]. The switch is activated by a player [[Use|using]] it, and can either be permanently pressed, or stay pressed for a set amount of time.


==Entity Creation==
{{todo|There are a number of cleaner methods for making pedestal buttons which should probably be documented here, including a rather obscure one involving parenting the button prop to a non-moving func_button, which will cause interactions anywhere on the prop to press the button similar to how it behaves in P2.}}
1. Using the [[Entity Tool]], place a [[prop_dynamic]] where you would like the switch model. Set the properties to the following:
 
:{|
== Creation ==
!  Property Name || Value
 
|-
=== Step 1 ===
| World Model || models/props/switch001.mdl
[[File:Portal switch base.PNG|200px|thumb|right|The base brush]]
|-
Create a <code>64w*64l*8h</code> brush with the <code>[[nodraw]]</code> texture. Texture the sides of the brush with <code>signage/hazard_orange_03b</code>, and texture the top of the brush with <code>concrete/concrete_modular_floor001a</code>.
| Name || switch_model
{{clr}}
|}
 
[[Image:Switch1.jpg|right|thumb|How to align the func_button.]]
=== Step 2 ===
[[File:Portal Switch button.png|200px|thumb|right|The switch model]]
Create a <code>[[prop_dynamic]]</code> entity and set its ''World Model'' to <code>models/props/switch001.mdl</code>, and set its ''Name'' to <code>switch1</code>.
{{clr}}


2. Create a 16x16x16 block [[brush]] covering the button on the model textured with ''tools/toolsinvisible''. Tie it to a [[func_button]]. Under '''Flags''', check '''Don't move''' and change the '''Delay before Reset''' to however long you want to prevent the player from activating it again.
=== Step 3 ===
{{note|For doors, make sure you give it enough time for the door to open, stay open and close.}}
[[File:Portal Switch sounds.PNG|200px|thumb|right|The <code>ambient_generic</code> entities]]
Create a <code>[[ambient_generic]]</code> and set its ''Name'' to <code>button1_down</code>, its ''Sound Name'' to <code>Portal.button_down</code>, and its ''Source Entity Name'' to <code>switch1</code>. Create another <code>ambient_generic</code> and set its ''Name'' to <code>button1_up</code>, its ''Sound Name'' to <code>Portal.button_up</code>, and its ''Source Entity Name'' to <code>switch1</code>.
{{clr}}


3. Create 3 [[ambient_generic]] entities near the switch. Give them the following properties:
=== Step 4 ===
1
[[File:Portal Switch ticktock.PNG|200px|thumb|right|The timer setup]]
:{|
Create a <code>[[logic_timer]]</code> entity. Set its ''Name'' to <code>timer_ticktock1</code>, set ''Start Disabled'' to <code>Yes</code> and set its ''Refire Interval'' to <code>1</code>. Next, create an <code>ambient_generic</code> entity and set its ''Name'' to <code>sound_ticktock1</code>, set its ''Sound Name'' to <code>Portal.room1_TickTock</code>, set its ''Max Audible Distance'' to <code>441</code> and set it ''Source Entity Name'' to <code>switch1</code>. Now add the following output to <code>timer_ticktock1</code>:
!  Property Name || Value
{| {{OutputsTable}}
|-
| [[File:Io11.png]] || OnTimer || sound_ticktock1 || PlaySound || &nbsp; || 0.00 || No
| Name || switch_sound_up
|-
| Sound Name || Portal.button_up
|-
| SourceEntityName || switch_model
|}
|}
:{|
{{clr}}
!  Property Name || Value
 
=== Step 5 ===
[[File:Portal Switch door.PNG|200px|thumb|right|The <code>func_door_rotating</code> brush]]
Create a <code>16w*16l*16h</code> brush 32 units above the bottom of the switch model. Texture it with <code>tools/toolsplayerclip</code> and tie it to a <code>[[func_door_rotating]]</code> entity. Set its ''Speed'' to <code>500</code>, its ''Distance'' to <code>0</code> and its ''Delay before reset'' to how long it should stay pressed for, in seconds. Set it to <code>-1</code> to make it stay pressed forever after being activated. Next, check the ''Use Opens'' and ''Door Silent'' flags. Next, add the following outputs to the door:
{| {{OutputsTable}}
| [[File:Io11.png]] || OnOpen || switch1 || SetAnimation || down || 0.00 || No
|-
|-
| Name || switch_sound_down
| [[File:Io11.png]] || OnFullyOpen || button1_down || PlaySound || &nbsp; || 0.00 || No
|-
|-
| Sound Name || Portal.button_down
| [[File:Io11.png]] || OnFullyOpen || timer_ticktock1 || Enable || &nbsp; || 0.00 || No
|-
|-
| SourceEntityName || switch_model
| [[File:Io11.png]] || OnClose || switch1 || SetAnimation || up || 0.00 || No
|}
:{|
!  Property Name || Value
|-
|-
| Name || switch_sound_tick
| [[File:Io11.png]] || OnFullyClosed || button1_up || PlaySound || &nbsp; || 0.00 || No
|-
|-
| Sound Name || Portal.room1_TickTock
| [[File:Io11.png]] || OnFullyClosed || timer_ticktock1 || Disable || &nbsp; || 0.00 || No
|-
| SourceEntityName || switch_model
|}
|}
For the switch_sound_tick entity, un-check '''Starts Silent''' under '''Flags'''.


4. Next create a [[logic_timer]] somewhere near the switch. Give it the following properties:
:{|
!  Property Name || Value
|-
| Name || switch_sound_tickloop
|-
| Starts Disabled || Yes
|-
| Refire Interval || 1
|}
And the following Output:
:{|
!  || My Output || Target Entity || Target Input || Parameter || Delay || Only Once
|-
| [[Image:Io11.png]] || OnTimer || switch_sound_tick || PlaySound || <none> || 0.00 || No
|}
[[Image:Switch2.jpg|right|thumb|In-game]]


5. Select the [[func_button]] and add the following outputs:
The switch is now finished and ready to be implemented in a map.
:{|
{{clr}}
!  || My Output || Target Entity || Target Input || Parameter || Delay || Only Once
 
|-
== Implementation ==
| [[Image:Io11.png]] || OnOut || switch_model || SetAnimation || up || 0.00 || No
=== Step 1 ===
|-
Place the switch where it should be in the map. Rotate it if necessary.
| [[Image:Io11.png]] || OnOut || switch_sound_tickloop || Disable || <none> || 0.00 || No
 
|-
=== Step 2 ===
| [[Image:Io11.png]] || OnOut || switch_sound_up || PlaySound || <none> || 0.00 || No
Add the outputs that should fire when the switch is activated. The outputs that should fire when the switch is pressed should be the ''OnFullyOpen'' output on the <code>func_door_rotating</code> entity, and the ''OnFullyClosed'' output when the button is reset after its timer has run out.
|-
| [[Image:Io11.png]] || OnPressed || switch_model || SetAnimation || down || 0.00 || No
|-
| [[Image:Io11.png]] || OnPressed || switch_sound_tickloop || Enable || <none> || 0.00 || No
|-
| [[Image:Io11.png]] || OnPressed || switch_sound_down || PlaySound || <none> || 0.00 || No
|}
{{note|The time you have for '''Delay before Reset''' will be how long it takes for the OnOut outputs to trigger. Make sure you have it timed accordingly!}}


== See also ==
* [[Portal Level Creation]]


Add in your door open triggers with OnPressed and closing triggers with OnOut. You can also put in some [[Creating indicator lights|indicator lights]] for added effect. Download the tutorial map [http://www.remmiz.com/portal/maps/switchtutorial.zip here].
[[Category:Portal]]
[[Category:Level Design]]
[[Category:Tutorials]]

Latest revision as of 18:21, 7 January 2024

English (en)Français (fr)Translate (Translate)
Portal Level Creation

This tutorial will show how to create the switch seen throughout the later test chambers of Portal. The switch is activated by a player using it, and can either be permanently pressed, or stay pressed for a set amount of time.

Todo: There are a number of cleaner methods for making pedestal buttons which should probably be documented here, including a rather obscure one involving parenting the button prop to a non-moving func_button, which will cause interactions anywhere on the prop to press the button similar to how it behaves in P2.

Creation

Step 1

The base brush

Create a 64w*64l*8h brush with the nodraw texture. Texture the sides of the brush with signage/hazard_orange_03b, and texture the top of the brush with concrete/concrete_modular_floor001a.

Step 2

The switch model

Create a prop_dynamic entity and set its World Model to models/props/switch001.mdl, and set its Name to switch1.

Step 3

The ambient_generic entities

Create a ambient_generic and set its Name to button1_down, its Sound Name to Portal.button_down, and its Source Entity Name to switch1. Create another ambient_generic and set its Name to button1_up, its Sound Name to Portal.button_up, and its Source Entity Name to switch1.

Step 4

The timer setup

Create a logic_timer entity. Set its Name to timer_ticktock1, set Start Disabled to Yes and set its Refire Interval to 1. Next, create an ambient_generic entity and set its Name to sound_ticktock1, set its Sound Name to Portal.room1_TickTock, set its Max Audible Distance to 441 and set it Source Entity Name to switch1. Now add the following output to timer_ticktock1:

  My Output Target Entity Target Input Parameter Delay Only Once
Io11.png OnTimer sound_ticktock1 PlaySound   0.00 No

Step 5

The func_door_rotating brush

Create a 16w*16l*16h brush 32 units above the bottom of the switch model. Texture it with tools/toolsplayerclip and tie it to a func_door_rotating entity. Set its Speed to 500, its Distance to 0 and its Delay before reset to how long it should stay pressed for, in seconds. Set it to -1 to make it stay pressed forever after being activated. Next, check the Use Opens and Door Silent flags. Next, add the following outputs to the door:

  My Output Target Entity Target Input Parameter Delay Only Once
Io11.png OnOpen switch1 SetAnimation down 0.00 No
Io11.png OnFullyOpen button1_down PlaySound   0.00 No
Io11.png OnFullyOpen timer_ticktock1 Enable   0.00 No
Io11.png OnClose switch1 SetAnimation up 0.00 No
Io11.png OnFullyClosed button1_up PlaySound   0.00 No
Io11.png OnFullyClosed timer_ticktock1 Disable   0.00 No


The switch is now finished and ready to be implemented in a map.

Implementation

Step 1

Place the switch where it should be in the map. Rotate it if necessary.

Step 2

Add the outputs that should fire when the switch is activated. The outputs that should fire when the switch is pressed should be the OnFullyOpen output on the func_door_rotating entity, and the OnFullyClosed output when the button is reset after its timer has run out.

See also