[ad_1]
I am new to programming in Godot however I have been enjoying round with issues I’ve realized in varied tutorials. That’s, till I bumped into the next situation which I can not seem to debug. I connected a video to indicate what’s taking place.
After I first run it, the kid bullets work rather well with the place on the Gun’s Marker2D, path and rotation in response to the code. As soon as I transfer the participant although, the global_position of the Marker2D appears to translate in the identical Vector because the participant motion however vastly elevated. So rotation and path nonetheless work positive, however the beginning place is method off. It is even potential to maneuver again to the unique pos after which the bullets begin on the proper place once more.
Code at participant.gd:
extends CharacterBody2D
const SPEED = 400
var bullet_scene: PackedScene = preload("res://projectile.tscn")
func _process(_delta):
var path := Enter.get_vector("move_left", "move_right", "move_up", "move_down")
velocity = path * SPEED
move_and_slide()
if Enter.is_action_just_pressed("primary_shot"):
var weapon_rotation = (get_global_mouse_position() - place).normalized()
var shot_pos = $Gun/Marker2D.global_position
var other_rotation = get_angle_to($Gun/Marker2D.global_position)
#print("shot_pos:", shot_pos, "weapon_rot:", weapon_rotation)
var bullet = bullet_scene.instantiate()
get_node("Projectiles").add_child(bullet)
bullet.place = shot_pos
bullet.path = weapon_rotation
bullet.rotation = other_rotation
For some cause, if I emit a sign from the participant with all the identical variables to my predominant.gd, and run all the things verbatim from var bullet onwards in its sign perform, it really works simply positive. My concern is that I actually have one other mission I made a few days earlier the place I run all the things in participant.gd and it really works excellent there, however not now, and I wish to know what I am doing unsuitable.
[ad_2]