This article's documentation is for anything that uses the Source engine. Click here for more information.

Env quadraticbeam: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Fix vscript example)
(Should work in other games.)
 
(4 intermediate revisions by 4 users not shown)
Line 2: Line 2:
{{Ent not in fgd|nolink=1|because=it is only configurable via code or [[vscript]]}}
{{Ent not in fgd|nolink=1|because=it is only configurable via code or [[vscript]]}}
{{CD|CEnvQuadraticBeam|file1=1}}
{{CD|CEnvQuadraticBeam|file1=1}}
{{CD|C_QuadraticBeam|game=client side|base=C_BaseEntity|file1=[https://github.com/ValveSoftware/source-sdk-2013/blob/master/mp/src/game/client/c_effects.cpp#L1500 c_effects.cpp]}}
{{CD|C_QuadraticBeam|client=1|base=C_BaseEntity|file1=1}}
{{this is a|[[entity]]|name=env_quadraticbeam}} It is a duplicate of the {{ent|beam}} entity, but with ability to arc by using a quadratic equation.  It can be used to produce a similar effect to the {{gmod}} physics gun.  The formula used to form the curve can be found [https://github.com/ValveSoftware/source-sdk-2013/blob/0d8dceea4310fde5706b3ce1c70609d72a38efdf/mp/src/game/client/beamdraw.cpp#L1489 here].
{{this is a|[[entity]]|name=env_quadraticbeam}} It is a duplicate of the {{ent|beam}} entity, but with ability to arc by using a quadratic equation.  It can be used to produce a similar effect to the {{gmod}} physics gun.  The formula used to form the curve can be found [https://github.com/ValveSoftware/source-sdk-2013/blob/0d8dceea4310fde5706b3ce1c70609d72a38efdf/mp/src/game/client/beamdraw.cpp#L1489 here].
{{Important|This entity has no additional KIO other than those that [[CBaseEntity]] already offers! Values listed under 'Fields' can only be accessed with an external plugin, or the NetProp manager found in certain [[VScript]]-supported titles ({{tf2}} and {{l4d2}}).}}
{{Important|This entity has no additional KIO other than those that [[CBaseEntity]] already offers! Values listed under 'Fields' can only be accessed with an external plugin, or the NetProp manager found in certain [[VScript]]-supported titles ({{tf2}} and {{l4d2}}).}}
{{bug|Disappears if the end and control positions are outside the player's view field.|tested={{bms}}}}


== Fields ==
== Fields ==
Line 13: Line 14:


== Notable KIO ==
== Notable KIO ==
{{Note|The CBaseEntity <code>model</code> keyvalue does not work for setting the sprite, it must be set after spawning.}}
=== Keyvalues ===
=== Keyvalues ===
{{KV|Origin|intn=origin|vector|Start point of the beam}}
{{KV|Origin|intn=origin|vector|Start point of the beam}}


=== Inputs ===
=== Inputs ===
{{IO|Color|param=rgb|Changes color}}
{{I|Color|param=rgb|Changes color}}


[[File:Quadraticbeam.jpg|thumb|right]]
[[File:Quadraticbeam.jpg|thumb|right]]


== Spawning via vscript example ==
== Spawning via vscript example ==
<syntaxhighlight lang=js style="background:initial;">
<syntaxhighlight lang=js style="background:initial;">
function SpawnQuadBeam(start, end, control, color="255 0 0", model="sprites/laserbeam.spr") {
function SpawnQuadBeam(start, end, control, color="255 0 0", model="sprites/laserbeam.spr") {


     // precache the beam sprite
     // precache the beam sprite
     PrecacheModel(model)
     if (!IsModelPrecached(model))
   
        PrecacheModel(model)
 
     // spawn the beam and set the start point
     // spawn the beam and set the start point
     local ent = SpawnEntityFromTable("env_quadraticbeam", { origin = start })
     local ent = SpawnEntityFromTable("env_quadraticbeam", {
        origin = start
    //  model = model //model doesn't work here, need to SetModel after spawning
    })
 
    // set the beam sprite
    ent.SetModel(model)


     // set the end point for the beam
     // set the end point for the beam
Line 43: Line 51:
     // set the beam color
     // set the beam color
     DoEntFire("!self", "color", color, 0, null, ent)
     DoEntFire("!self", "color", color, 0, null, ent)
    // set the beam sprite
    ent.SetModel(model)
}
}


//Draw a beam from the players origin point to the nearest prop_dynamic in a 2048hu radius
//Draw a beam from the players origin point to the nearest prop_dynamic in a 2048hu radius
local start_pos = GetListenServerHost().GetOrigin()
local start_pos = GetListenServerHost().GetOrigin()
local end_pos = Entities.FindByClassnameNearest("prop_dynamic", eye_pos, 2048)
local end_pos = Entities.FindByClassnameNearest("prop_dynamic", start_pos, 2048).GetOrigin()


//set control point to map origin (0 0 0)
//set control point to map origin (0 0 0)

Latest revision as of 06:10, 18 June 2025

English (en)Translate (Translate)
Icon-NotInFGD.png
This entity is not in the FGD by default.
It should not be put directly in a map because it is only configurable via code or vscript.
C++ Class hierarchy
CEnvQuadraticBeam
CPointEntity
CBaseEntity
C++ effects.cpp
C++ Class hierarchy (client)
C_QuadraticBeam
C_BaseEntity
C++ c_effects.cpp

env_quadraticbeam is an entity available in all Source Source games. It is a duplicate of the beam entity, but with ability to arc by using a quadratic equation. It can be used to produce a similar effect to the Garry's Mod physics gun. The formula used to form the curve can be found here.

Icon-Important.pngImportant:This entity has no additional KIO other than those that CBaseEntity already offers! Values listed under 'Fields' can only be accessed with an external plugin, or the NetProp manager found in certain VScript-supported titles (Team Fortress 2 and Left 4 Dead 2).
Icon-Bug.pngBug:Disappears if the end and control positions are outside the player's view field.  (tested in: Black Mesa)

Fields

m_targetPosition <FIELD_POSITION_VECTOR>

END point

m_controlPosition <FIELD_POSITION_VECTOR>

CONTROL point (see picture)

m_scrollRate <FIELD_FLOAT>

Must be value between -4, 4

m_flWidth <FIELD_FLOAT>


Notable KIO

Note.pngNote:The CBaseEntity model keyvalue does not work for setting the sprite, it must be set after spawning.

Keyvalues

Origin (origin) <vector>
Start point of the beam

Inputs

Color <color255RedirectInput/color32>
Changes color
Quadraticbeam.jpg

Spawning via vscript example

function SpawnQuadBeam(start, end, control, color="255 0 0", model="sprites/laserbeam.spr") {

    // precache the beam sprite
    if (!IsModelPrecached(model))
        PrecacheModel(model)

    // spawn the beam and set the start point
    local ent = SpawnEntityFromTable("env_quadraticbeam", {
        origin = start
    //  model = model //model doesn't work here, need to SetModel after spawning
    })

    // set the beam sprite
    ent.SetModel(model)

    // set the end point for the beam
    NetProps.SetPropVector(ent, "m_targetPosition", end)

    // set the control point for the curve
    NetProps.SetPropVector(ent, "m_controlPosition", control)

    NetProps.SetPropFloat(ent, "m_scrollRate", 2)
    NetProps.SetPropFloat(ent, "m_flWidth", 5)

    // set the beam color
    DoEntFire("!self", "color", color, 0, null, ent)
}

//Draw a beam from the players origin point to the nearest prop_dynamic in a 2048hu radius
local start_pos = GetListenServerHost().GetOrigin()
local end_pos = Entities.FindByClassnameNearest("prop_dynamic", start_pos, 2048).GetOrigin()

//set control point to map origin (0 0 0)
local control_pos = Vector()

SpawnQuadBeam(start_pos, end_pos, control_pos)

See Also