Angle of Incidence
Angle of Incidence
Okay. This is less of scripting support and more of mathematical support
I have tried to work this out myself, but just MASSIVELY confused myself in the process. I want to calculate the angle of incidence upon a player shooting a wall. I am not worried whether this is a 2D or 3D angle, however must be calculated from the wall.
Picture below to explain a bit better.
I have tried to work this out myself, but just MASSIVELY confused myself in the process. I want to calculate the angle of incidence upon a player shooting a wall. I am not worried whether this is a 2D or 3D angle, however must be calculated from the wall.
Picture below to explain a bit better.
Here's a sourcemod plugin which does something very similar to what you're after.
https://forums.alliedmods.net/showthread.php?t=152173
The key thing I think you are missing is the use of a 'normal' vector from the wall. This is a vector going 90 degrees out from the wall (perpendicular).
You can use this to manipulate your view vector and basically get the product of the two.
Good luck
https://forums.alliedmods.net/showthread.php?t=152173
The key thing I think you are missing is the use of a 'normal' vector from the wall. This is a vector going 90 degrees out from the wall (perpendicular).
You can use this to manipulate your view vector and basically get the product of the two.
Good luck
You can already get the plane from a trace. https://github.com/Source-Python-Dev-Team/Source.Python/blob/bd62d8a4118dce438c0a78f264cb4a2d0e4060b8/src/core/modules/engines/engines_wrap_python.cpp#L937
my_trace.plane.normal
my_trace.plane.normal
What I have so far, am a little stuck now. Any help would be appreciated :)
Also, think I went a little over the top with the math? Or is this all necessary?
A picture is underneath for your reference.
Also, think I went a little over the top with the math? Or is this all necessary?
A picture is underneath for your reference.
Syntax: Select all
view_vector = player.view_vector
# Construct the simple right angle triange including missing values.
triangle_point_c = wall_position - view_vector * 10
triangle_point_b = ray.end_position
triangle_point_a = None
# Obtain the normal of the trace ray. To find the final point.
# The vector is extended behind and infront to allow for the chance of the wall
# is on either side of the view_vector.
new_trace_vec = ray.plane.normal
new_trace_start_point = triangle_point_c - new_trace_vec * 100
new_trace_end_point = triangle_point_c + new_trace_vec * 100
# Create a trace ray for the normal, and use it to find point 'a'.
normal_ray = get_trace_ray(new_trace_start_point, new_trace_end_point)
if normal_ray.did_hit_world():
if normal_ray.end_position.get_distance(triangle_point_b) <= 100:
triangle_point_a = normal_ray.end_position
# If point 'a' was found.
if triangle_point_a:
# Find the length of A and B to determine the incidence angle.
triangle_length_A = triangle_point_c.get_distance(triangle_point_b)
triangle_length_B = triangle_point_c.get_distance(triangle_point_a)
incidence_angle = degrees(atan(triangle_length_B / triangle_length_A))
reflection_angle = 180 - incidence_angle
# Not create a triangle on the otherside to find the reflection vector.
triangle_vec_C = triangle_point_b - triangle_point_a
triangle_point_d = triangle_point_b + triangle_vec_C
triangle_length_C = triangle_point_a.get_distance(triangle_point_b)
triangle_length_D = triangle_length_C
Okay. Scrap everything I have been doing. I converted Rob123's suggested plugin directly and it works beautifully
Code is below
Code is below
Syntax: Select all
from players.entity import PlayerEntity
from players.helpers import index_from_userid
from events import Event
from mathlib import Vector
from messages import SayText2
from effects import temp_entities
from filters.recipients import RecipientFilter
from engines.precache import Model
import random
beam_model = Model('sprites/laserbeam.vmt')
@Event
def weapon_fire(ev):
userid = ev.get_int('userid')
player = PlayerEntity(index_from_userid(userid))
origin = player.origin
angle = player.view_angle
velocity = player.view_vector
line = player.get_trace_ray()
normal = line.plane.normal
wall = line.end_position
product = normal.dot(velocity)
normal *= product*2
ricochet = velocity-normal
test = wall+ricochet*200
temp_entities.beam_points(
RecipientFilter(),
0,
wall,
test,
beam_model.index,
beam_model.index,
0,
255,
5,
3,
3,
3,
0,
random.randint(0, 255),
random.randint(0, 255),
random.randint(0, 255),
255,
1
)
Return to “Plugin Development Support”
Who is online
Users browsing this forum: No registered users and 59 guests