# Rally Rush: godot::Turret Class Reference

Loading...
Searching...
No Matches
godot::Turret Class Reference

Generic turret class with the ability to target any type of node as configured. Used for both the player's roof turret pickup and the enemy turrets. More...

`#include <turret.hpp>`

Inheritance diagram for godot::Turret:

## Public Member Functions

virtual void | _enter_tree () override
| Freeze physics and connect awareness observers. Fetch child nodes and initialize them. Update current awareness.
virtual void | _process (double delta_time) override
| Update state machine. Update gun node position.
void | awareness_changed ()
| Check if a new target needs to be found. Find a new target if required.
Node3D * | select_target ()
| Select a target from the currently known nodes.
void | lead_target (double delta_time)
| Aim ahead of the current target.
void | detect_node (Node3D *node)
| Become aware of a node in the awareness area.
void | lose_node (Node3D *node)
| Lose track of a node exiting the awareness area.
void | try_next_state ()
| Try transition to the next state if possible.
void | create_beam ()
| Create a damaging beam.
void | create_guiding_beam ()
| Create a non-damaging guiding beam.
void | beam_ended ()
| End the fire state.
void | set_fire_time (float val)
| The duration of the damaging lazer.
float | get_fire_time () const
| The duration of the damaging lazer.
void | set_charge_time (float val)
| The duration of the guiding lazer.
float | get_charge_time () const
| The duration of the guiding lazer.
void | set_lock_time (float val)
| The delay between firing and charging the next shot.
float | get_lock_time () const
| The delay between firing and charging the next shot.
void | set_invert_targets (bool value)
| Set to true to target everything but the attack_classes.
void | set_attack_classes (Array array)
| Set the node classes to attack while invert_targets is false.
Array | get_attack_classes () const
| Set the node classes to attack while invert_targets is false.
void | set_beam_scene (Ref< PackedScene > scene)
| Set the scene to spawn when firing.
Ref< PackedScene > | get_beam_scene () const
| Set the scene to spawn when firing.
void | set_guiding_beam_scene (Ref< PackedScene > scene)
| Set the scene to spawn when charging.
Ref< PackedScene > | get_guiding_beam_scene () const
| Set the scene to spawn when charging.

## Private Member Functions

| GDCLASS (Turret, RigidBody3D)

## Static Private Member Functions

static void | _bind_methods ()
| register editor properties

## Private Attributes

Node3D * | current_target {nullptr}
| The current target node.
bool | invert_attack_classes {false}
| If true, target classes not in attack_classes.
Vector3 | aim_position {0.f, 0.f, 0.f}
| Position currently being aimed at.
Vector3 | last_target_position {0.f, 0.f, 0.f}
| Position of the current_target on the last frame.
float | last_state_switch {0.f}
| Last time the state was changed.
float | lead_distance {1.2f}
| Distance ahead of target to aim.
Node3D * | gun_node {nullptr}
| The child node representing the gun.
Vector3 | gun_node_offset {0.f, 0.f, 0.f}
| Position offset of the gun.
TurretState | state {TurretState::WAITING}
| Current state-machine state of the turret.
Vector< StringName > | attack_classes {}
| Names of classes to attack.
HashSet< Node3D * > | awareness {}
| Set of all nodes the turret is currently aware of.
Ref< PackedScene > | beam_scene {}
| Scene to spawn when firing.
Ref< PackedScene > | guiding_beam_scene {}
| Scene to spawn when charging.
float | fire_time {1.0f}
float | charge_time {1.f}
float | lock_time {1.3f}

## Detailed Description

Generic turret class with the ability to target any type of node as configured. Used for both the player's roof turret pickup and the enemy turrets.

## Member Function Documentation

## _bind_methods()

void godot::Turret::_bind_methods | ( |  | ) |

staticprivate

register editor properties

## _enter_tree()

void godot::Turret::_enter_tree | ( |  | ) |

overridevirtual

Freeze physics and connect awareness observers. Fetch child nodes and initialize them. Update current awareness.

## _process()

void godot::Turret::_process | ( | double | delta_time | ) |

overridevirtual

Update state machine. Update gun node position.

## awareness_changed()

void godot::Turret::awareness_changed | ( |  | ) |

Check if a new target needs to be found. Find a new target if required.

## beam_ended()

void godot::Turret::beam_ended | ( |  | ) |

End the fire state.

## create_beam()

void godot::Turret::create_beam | ( |  | ) |

Create a damaging beam.

## create_guiding_beam()

void godot::Turret::create_guiding_beam | ( |  | ) |

Create a non-damaging guiding beam.

## detect_node()

void godot::Turret::detect_node | ( | Node3D * | node | ) |

Become aware of a node in the awareness area.

## GDCLASS()

godot::Turret::GDCLASS | ( | Turret | ,
|  | RigidBody3D |
| ) |  |

private

## get_attack_classes()

Array godot::Turret::get_attack_classes | ( |  | ) | const

Set the node classes to attack while invert_targets is false.

## get_beam_scene()

Ref< PackedScene > godot::Turret::get_beam_scene | ( |  | ) | const

Set the scene to spawn when firing.

## get_charge_time()

float godot::Turret::get_charge_time | ( |  | ) | const

The duration of the guiding lazer.

## get_fire_time()

float godot::Turret::get_fire_time | ( |  | ) | const

The duration of the damaging lazer.

## get_guiding_beam_scene()

Ref< PackedScene > godot::Turret::get_guiding_beam_scene | ( |  | ) | const

Set the scene to spawn when charging.

## get_lock_time()

float godot::Turret::get_lock_time | ( |  | ) | const

The delay between firing and charging the next shot.

## lead_target()

void godot::Turret::lead_target | ( | double | delta_time | ) |

Aim ahead of the current target.

## lose_node()

void godot::Turret::lose_node | ( | Node3D * | node | ) |

Lose track of a node exiting the awareness area.

## select_target()

Node3D * godot::Turret::select_target | ( |  | ) |

Select a target from the currently known nodes.

## set_attack_classes()

void godot::Turret::set_attack_classes | ( | Array | array | ) |

Set the node classes to attack while invert_targets is false.

## set_beam_scene()

void godot::Turret::set_beam_scene | ( | Ref< PackedScene > | scene | ) |

Set the scene to spawn when firing.

## set_charge_time()

void godot::Turret::set_charge_time | ( | float | val | ) |

The duration of the guiding lazer.

## set_fire_time()

void godot::Turret::set_fire_time | ( | float | val | ) |

The duration of the damaging lazer.

## set_guiding_beam_scene()

void godot::Turret::set_guiding_beam_scene | ( | Ref< PackedScene > | scene | ) |

Set the scene to spawn when charging.

## set_invert_targets()

void godot::Turret::set_invert_targets | ( | bool | value | ) |

Set to true to target everything but the attack_classes.

## set_lock_time()

void godot::Turret::set_lock_time | ( | float | val | ) |

The delay between firing and charging the next shot.

## try_next_state()

void godot::Turret::try_next_state | ( |  | ) |

Try transition to the next state if possible.

## Member Data Documentation

## aim_position

Vector3 godot::Turret::aim_position {0.f, 0.f, 0.f}

private

Position currently being aimed at.

## attack_classes

Vector<StringName> godot::Turret::attack_classes {}

private

Names of classes to attack.

## awareness

HashSet<Node3D*> godot::Turret::awareness {}

private

Set of all nodes the turret is currently aware of.

## beam_scene

Ref<PackedScene> godot::Turret::beam_scene {}

private

Scene to spawn when firing.

## charge_time

float godot::Turret::charge_time {1.f}

private

## current_target

Node3D* godot::Turret::current_target {nullptr}

private

The current target node.

## fire_time

float godot::Turret::fire_time {1.0f}

private

## guiding_beam_scene

Ref<PackedScene> godot::Turret::guiding_beam_scene {}

private

Scene to spawn when charging.

## gun_node

Node3D* godot::Turret::gun_node {nullptr}

private

The child node representing the gun.

## gun_node_offset

Vector3 godot::Turret::gun_node_offset {0.f, 0.f, 0.f}

private

Position offset of the gun.

## invert_attack_classes

bool godot::Turret::invert_attack_classes {false}

private

If true, target classes not in attack_classes.

## last_state_switch

float godot::Turret::last_state_switch {0.f}

private

Last time the state was changed.

## last_target_position

Vector3 godot::Turret::last_target_position {0.f, 0.f, 0.f}

private

Position of the current_target on the last frame.

## lead_distance

float godot::Turret::lead_distance {1.2f}

private

Distance ahead of target to aim.

## lock_time

float godot::Turret::lock_time {1.3f}

private

## state

TurretState godot::Turret::state {TurretState::WAITING}

private

Current state-machine state of the turret.

The documentation for this class was generated from the following files:

- src/turret.hpp
- src/turret.cpp