# Making shogun bullet

Attention Topic was automatically imported from the old Question2Answer platform.

Hi I try to make a shotgun bullet and I want to decide to change the size of the dispersion and a damge reduce by distance the bullet do and fix it minimum and max damage to 1 for the reduce damage by distance.

script for bullet 1:

``````extends Area2D
``````

const speed = 900

export(int) var damage = 10
var velocity = Vector2(1,1)

func shoot_at_mouse(start_pos):
self.global_position = start_pos
var direction = (get_global_mouse_position() - start_pos).normalized()
self.linear_velocity = -direction * speed

func _physics_process(delta):
velocity.x = speed * delta
velocity.y = speed * -delta
translate(velocity)
set_position(get_position()+velocity*-delta)

script bullet 2:

``````extends Area2D
``````

const speed = 900

export(int) var damage = 10
var velocity = Vector2()

func shoot_at_mouse(start_pos):
self.global_position = start_pos
var direction = (get_global_mouse_position() - start_pos).normalized()
self.linear_velocity = direction * speed

func _physics_process(delta):
velocity.x = speed * delta

``````translate(velocity)
set_position(get_position()+velocity*delta)
``````

script bullet 3:

``````extends Area2D
``````

const speed = 900

export(int) var damage = 10
var velocity = Vector2(-1,1)

func shoot_at_mouse(start_pos):
self.global_position = start_pos
var direction = (get_global_mouse_position() - start_pos).normalized()
self.linear_velocity = -direction * speed

func _physics_process(delta):
velocity.x = speed * delta
velocity.y = speed * delta
translate(velocity)
set_position(get_position()+velocity*-delta)
Thank for helping me

Hello! Why you have 3 different bullet nodes?

fershopls | 2019-07-30 04:34

yeah a use three bullet to give the “effect” of dispersion of a shotgun bullet.It just a part of the design of the weapon.

Edit:actually I find the solution for the dispersion but anyway could you just explain me how to to the damage reduce by distance whit a max damage and a minimum damage.

thoma | 2019-07-30 17:07

You could make variable damage like this:

``````var damage = 10.0
const damage_minimum = 1.0
const damage_reduction = 5.0

func _process(delta):
damage -= damage_reduction * delta
if damage < damage_minimum
damage = damage_minimum
``````

Then play around with the values of the variables to make an effect you like.
The longer the bullet will fly, the less the damage will it make, down to a minimum of 1.

You could also adjust the function to be nonlinear by, for example, reducing damage by a percentage instead of fixed value.