Rotating Portalgun

From Valve Developer Community
Jump to: navigation, search


The Rotating Portalgun is featured twice in Portal. It involves the gun sitting on it's pedestal, rotating and firing a Portal every 90 degree of Rotation.

Creating the Rotating Portalgun

The Pedestal

the pedestal Models

The Pedestal itself consists of two prop_dynamic entities. First create a Prop_Dynamic:

Prop_dynamic
Name Pedestal_Model
Model models/props/pedestal_center_reference.mdl

then Create a second one underneath the first one:

Prop_dynamic
Name Pedestal_Base
Model models/props/pedestal_base_reference.mdl

Set the following values at your Pedestal_Model:

Default Animation idle
Hold Animation? Yes

And at Pedestal_Base:

Default Animation close
Hold Animation? Yes


Creating the Gun

To Create the Portal Gun itself, place a weapon_portalgun at the appropriate poition inside the two rings at your Pedestal_Model. Name it "PGun" or something similar, then set all the values you wish.

Note:For Example, You may want to set "Can Fire Portal 2" to false.

Making it rotate

the func_Rotating and the weapon_portalgun added

To make the Gun and the pedestal rotate, place a brush with the nodraw texture at the bottom of the pedestal. Press CTRL + T to tie it to an entity, make it a func_rotating, name it "pedestal_rotation" and set the following keyvalues:

Max rotation speed 30

Set the Parent of your gun and pedestal_Model to pedestal_rotation.

Making the gun shoot

This part is a bit tricky: as we set the speed of the gun to 30 degree/s, and we want the gun to fire every 90 degrees, we have to stop the pedestal every 3 seconds, charge the gun, fire the gun and resume the rotation.

Therefore, create a logic_timer entity.

logic_timer
name shoot_Timer
Refire Interval 4 (as we have three seconds of rotation and one second when the pedestal stops and the gun is fired)

Add the following outputs:

My Output Named Target Entity Target Input Delay
onTimer pedestal_rotation stop 0
onTimer PGun ChargePortal1 0.1
onTimer PGun FirePortal1 0.5
onTimer pedestal_rotation start 1.0

To enable everything, place a logic_auto entity and give it the following outputs:

My Output Named Target Entity Target Input Delay
OnMapSpawn shoot_timer Enable 0.0
OnMapSpawn pedestal_rotation start 1.0
Note:the one second delay is very important! Else you would get the gun firing 30 degrees too late.

Stopping everything when the gun is picked up

Add these outputs to your portalgun:

My Output Named Target Entity Target Input Delay
onPlayerPickup pedestal_rotation stop 0
onPlayerPickup pedestal_model setAnimation inactive
onPlayerPickup pedestal_open_trigger kill 0
onPlayerPickup shoot_timer disable 0
Note:Output 3 only applys to your Gun, if you follow the next step.

Optional: triggering the pedestal model to open when the player gets nearby

The finished setup

Place a trigger_multiple over your pedestal. Name it "pedestal_open_trigger" and give it the following outputs:

My Output Named Target Entity Target Input value Delay
onStartTouch pedestal_model setAnimation open 0.0
onEndTouch pedestal_model setAnimation close 0.0

Notes

- To make the Gun fire the orange Portal, instead of the blue, replace "ChargePortal1" with "ChargePortal2" and "FirePortal1" with "FirePortal2"

- If an NPC is going to pick up the gun, change "OnPlayerPickup" to "OnNPCPickup"