Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const GRAVITY : float = 9.81
- const SHAPE_RAYCAST_RADIUS := 0.3
- const LINE_POINT_COUNT : int = 50 # numPoints
- const TIME_BETWEEN_POINTS : float = .45 # timeBetweenPoints
- const PROJECTILE_POWER = 8
- var query = PhysicsShapeQueryParameters3D.new()
- func _ready() -> void:
- update_visualiser_position.connect(get_parent()._on_projectile_visualiser_set_position)
- query.shape_rid = PhysicsServer3D.sphere_shape_create()
- query.exclude = [self]
- PhysicsServer3D.shape_set_data(query.shape_rid, SHAPE_RAYCAST_RADIUS)
- func calculate_projectile():
- var points : Array[Vector3] = []
- var starting_pos : Vector3 = Vector3(0, 1, -1)
- var starting_velocity : Vector3 = (basis.z * PROJECTILE_POWER)
- var time := 0.0
- for n in LINE_POINT_COUNT:
- # This is how the Unity tutorials calculated both the x and z - but it doesn't seem to work very well:
- var new_point : Vector3 = starting_pos + time * starting_velocity
- new_point.y = starting_pos.y + starting_velocity.y * time + (GRAVITY / 2.0 + pow(time, 2))
- # As new_point is local to Player, we move the query's location by the players position + new_point
- query.transform = global_transform.translated_local(new_point)
- var intersection := get_world_3d().direct_space_state.intersect_shape(query, 2)
- if not intersection.is_empty():
- # Get the point where the shape first intersected
- var collision := get_world_3d().direct_space_state.get_rest_info(query)
- if !collision.is_empty():
- # Location of point found, place an indicator on the point.
- pass
- break
- points.append(new_point)
- time += TIME_BETWEEN_POINTS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement