Customise Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorised as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.

No cookies to display.

[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.

https://www.youtube.com/watch?v=0la6s_OSDfM

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *