User:Thebigh/Sandbox: Difference between revisions

From The DarkMod Wiki
Jump to navigationJump to search
Thebigh (talk | contribs)
m write more stuff
Thebigh (talk | contribs)
rm
 
Line 41: Line 41:
* The darkvision entity (the light we created earlier) gets repositioned to player_head.
* The darkvision entity (the light we created earlier) gets repositioned to player_head.
* Exit the function. Really, the return command isn't necessary as the function will exit when it gets to the end, but it is a good habit to get into for later when you start writing functions that return information to their caller.
* Exit the function. Really, the return command isn't necessary as the function will exit when it gets to the end, but it is a good habit to get into for later when you start writing functions that return information to their caller.
==Dicussion==
Dark vision can be a useful trick, but may not be suitable for every level. Since it is an additional light source it will affect your frame rate, so consider

Latest revision as of 17:23, 12 September 2021

Deciding on the best level of Ambient Light can be tricky. If you make it too bright, the mission can take on a flat, washed-out feel and useful shadows can be difficult to distinguish from their surroundings. Too dark, and it is often hard to see your immediate vicinity. The dark vision technique gives you the best of both worlds: it allows you to light up nearby objects so you can see them while leaving distant areas nicely unlit.

Essentially, we are going to attach a point light to the thief's head and have it follow him around like a faint lantern.

The light

Put a light anywhere. This will be the dark vision light itself. Later we will use a script to attach it to the player's head, but for now place it in your "blue room".

  • Give it a modest radius; I find 300 to 500 units gives good results (7 - 11.5 m).
  • Name it "darkvision"
  • Give it a fairly low brightness; again, I have got good results with rgb(10,10,10). It should be neutral in colour though.
  • Set its ai_see spawnarg to 0. This will prevent it from affecting your light gem. We're thinking of this as dark-adjusted vision for the player, so it shouldn't make it easier for guards to spot you.
  • Set its noshadows spawnarg to 1. That will improve performance slightly as well as stopping the darkvision light from casting shadows; see what happens if you leave the shadows on and then lean around a corner to understand why this matters.

The trigger timer

Place a trigger_timer entity somewhere in your blue room. This object repeatedly triggers whatever its target is, over and over and over. We'll use the trigger_timer to continually activate the script that positions the light.

  • Give it a target spawnarg called "update_darkvision".
  • Give it a wait spawnarg of 0.1. This means the position of the darkvision will be updated ten times a second.
  • Give it a start_on spawnarg of 1.

The callscriptfunction entity

Put a atdm:target_callscriptfunction entity somewhere near the trigger timer. This object has one purpose: to run a specified script whenever something triggers it. In this case it will be activated by the trigger timer at regular intervals and run the script that actually moves the light.

  • Name it "update_darkvision" so the trigger timer knows what to trigger.
  • Give it a call spawnarg of update_darkvision_function. This is going to be the name of the script.

The script

Outside DarkRadiant, go into the folder containing your mission and navigate to the maps folder. Start a new text file called mapname.script, where "mapname" is the name of your mission. Add the following code to this new file:

void update_darkvision_function() {
    vector player_head;
    player_head = $player1.getOrigin() + '0 0 64';
    $darkvision.setOrigin( player_head );
    return;
}

For those unfamiliar with scripting, this is what the above code means, line-by-line:

  • We are defining a function called update_darkvision_function, which requires no information (the empty brackets) and returns no information (void).
  • Inside the function we define a vector variable called player_head
  • We set that variable to the player's position, and then add a vertical offset of 64 units, which puts it a fair way off the ground.
  • The darkvision entity (the light we created earlier) gets repositioned to player_head.
  • Exit the function. Really, the return command isn't necessary as the function will exit when it gets to the end, but it is a good habit to get into for later when you start writing functions that return information to their caller.