Skip to content

Commit

Permalink
fix collision avoidance
Browse files Browse the repository at this point in the history
  • Loading branch information
wittrockscode committed Jan 14, 2025
1 parent 7699225 commit d3ba7b9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions vscripts/rocket_spawner/rocket_functions.nut
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ function ROCKETS::HomingRocketThink(rocket) {
local final_direction = ROCKETS.Helpers.LerpVectors(current_dir, target_direction, turnrate);

if (collision_avoidance) {
final_direction = ROCKETS.RocketCollision(rocket_entity, final_direction, dontCheckFloor);
final_direction = ROCKETS.RocketCollision(rocket_entity, final_direction, dontCheckFloor, targetDistance);
}

rocket_entity.SetAbsVelocity(final_direction.Scale(speed));
rocket_entity.SetForwardVector(final_direction);
}
}

function ROCKETS::RocketCollision(rocket_entity, current_direction, dont_check_floor) {
function ROCKETS::RocketCollision(rocket_entity, current_direction, dont_check_floor, targetDistance) {
rocket_entity.ValidateScriptScope();
local scope = rocket_entity.GetScriptScope();
local current_dir = rocket_entity.GetForwardVector();
Expand All @@ -103,6 +103,8 @@ function ROCKETS::RocketCollision(rocket_entity, current_direction, dont_check_f
local normal = trace_output.plane_normal;
if (dont_check_floor && normal.z > 0.5) return current_direction;

if (targetDistance < (trace_output.endpos - rocket_entity.GetOrigin()).Length()) return current_direction;

scope.last_normal = normal;

local percentage = trace_output.fraction * 100;
Expand Down

0 comments on commit d3ba7b9

Please sign in to comment.