Bullet not going to desired point

Godot Version

Godot 4.3

Question

Hello! To go straight to business, basically i have a shooting mechanic that i’m getting through with an youtube video and i can’t make the shot go where i want it to go/the target desired, that is, where my aim leads.

Everything is working well, it’s really just the bullet that is going to somewhere i don’t want it to go…


Where i’m aiming


Where the bullet goes, to the side (it’s marked by this red mark on the ground, it’s where the shot landed)

I have the project for the game, and it’s right by the Player3D, in Main_Cam and then in Weapons_Manager…

Any help is much appreciated, it should be really simple, i just can’t figure out what it is. I thought maybe it was the rotation of the Bullet_Point node, or maybe some miscalculation on the code, but i can’t seen to find it :frowning:

I’m guessing these are the relevant lines?

Put down some print statements to see what values are being used. Print out the value of every variable in the functions. Without this it will be hard to diagnose.

Also your github project was updated three weeks ago so I can’t be sure you’re showing me your recent code.

I assure it’s recent-to-date. Well i could print some statements, but i would’ve to have something i wanted to test if it’s working? Like, everything is working, it’s just the bullet doesn’t go in straight line, it goes to the bottom right. It technically even can hit the desired target (in which is a purple box), but not the way it has to, yk? like you can hit it, you just can’t aim it to hit it lol

When I say print statements, I mean printing the value of each variable in the code snipped I shared in my previous post. By printing the value of each variable, you can observe if it is what you’d expect. This is a first step in diagnosing the problem. When we see what values are expected and what values are actually used, I can help you better.

1 Like

Oh, i think i got it. But, if i am not asking too much, how could i do that? Do you have an example at least that i could work around? I’m new to this so, i’m still learning and getting things done

Like this:



func Get_Camera_Collision()->Vector3:
	var camera = get_viewport().get_camera_3d()
	var viewport = get_viewport().get_size()
    print_debug("viewport = " + str(viewport))
	
	var Ray_Origin = camera.project_ray_origin(viewport/2)
    print_debug("Ray_Origin = " + str(Ray_Origin))
	var Ray_End = Ray_Origin + camera.project_ray_normal(viewport/2)*Current_Weapon.Weapon_Range
    print_debug("Ray_End = " + str(Ray_End))
	
	var New_Intersection = PhysicsRayQueryParameters3D.create(Ray_Origin,Ray_End)
    print_debug("New_Intersection = " + str(New_Intersection))
	var Intersection = get_world_3d().direct_space_state.intersect_ray(New_Intersection)
    print_debug("Intersection = " + str(Intersection))
	
	if not Intersection.is_empty():
		var Cel_Point = Intersection.position
        print_debug("Cel_Point = " + str(Cel_Point))
		return Cel_Point
	else:
		return Ray_End
	
func Hit_Scan_Collision(Collision_Point):
	var Bullet_Direction = (Collision_Point - Bullet_Point.get_global_transform().origin).normalized()
        print_debug("Bullet_Direction = " + str(Bullet_Direction))
	var New_Intersection = PhysicsRayQueryParameters3D.create(Bullet_Point.get_global_transform().origin,Collision_Point+Bullet_Direction*2)
        print_debug("New_Intersection = " + str(New_Intersection))
	
	var Bullet_Collision = get_world_3d().direct_space_state.intersect_ray(New_Intersection)
        print_debug("Bullet_Collision = " + str(Bullet_Collision))
	
	if Bullet_Collision:
		var Hit_Indicator = Debug_Bullet.instantiate()
		var world = get_tree().get_root()
		world.add_child(Hit_Indicator)
		Hit_Indicator.global_translate(Bullet_Collision.position)
		
		Hit_Scan_Damage(Bullet_Collision.collider)

When you fire, you can see what values each variable get assigned. Then you will know if each variable has the expected value or not.