GREAT-DNG

  • Aug 7, 2024
  • Joined Jun 18, 2022
  • 2 best answers
  • DaveTheCoder You connected the mouse_entered signal to a function? Did you verify that the function is getting called at the expected time by placing a print statement in it?

    Yes, these methods are executed.

    DaveTheCoder Also:
    Note: If you want to change the default cursor shape for Control's nodes, use Control.mouse_default_cursor_shape instead.

    I don't need this. I have a custom cursor in the game, and I want to make it so that when the mouse enters the element, the cursor becomes the same as in the operating system.

  • Loxyrak Mmm... I tried to call Input.set_default_cursor_shape() on mouse_entered signal. Do you understand correctly what I want to do?

  • It is necessary that the cursor, when hovering over the Control (in my case, FileDialog), changes from the one specified in the project settings to the system arrow, and vice versa when leaving this element. Changing the script with Input.set_default_cursor_shape() doesn't help. How to fix it?

  • Hello.
    There is such a scene tree:

    - Control [uses a custom theme]
    - - FileDialog [inherits the Control theme]

    But I need to use Godot default UI theme for FileDialog, can this be implemented? Creating an empty theme for the FileDialog does not resolve the issue.

    • Well, yeah an empty theme won't be overriding the properties, so they would still fall back to inheriting from the top.

      You have to click on 'Manage Items' in the theme editor area. Next, in the overlay window that opens click on the tab you are after, Default Theme, or if you actually meant the Editor Theme then on that tab. Then in chosen tab, at the bottom you should see a button called 'Select with Data' pressing that should import all the controls themed and their respective properties data.

      With that done you should now have a theme overriding everything either replicating the default theme or the editor theme respectively. Save the theme.

  • Hello.

    I have a TileSet with an Occluder that the level is built from and a player that emits light. The problem is that during the movement of the player, overexposed pixels appear, as if they do not fall into the Occluder. There are also dark pixels, but this is not so critical.

    Screenshot. Project.

    What caused this problem and how to fix it?

    It is translated by Google, inaccuracies are possible.

  • Megalomaniak
    The problem was due to the difference in the aspect ratio of the monitor and the game (the presence of black bars along the edges of the screen), this problem was solved. Here is the final code, I had to add another method:

    func get_resolution_ratio():
    	return get_viewport().size.x / 800
    
    # Returns the size of the black area from the edge of the screen
    func get_aspect_ratio_difference():
    	if !OS.window_fullscreen:
    		return Vector2(1, 1)
    	
    	if OS.get_screen_size().y == get_viewport().size.y:
    		return Vector2((OS.get_screen_size().x - get_viewport().size.x) / 2, 1)
    	if OS.get_screen_size().x == get_viewport().size.x:
    		return Vector2(1, (OS.get_screen_size().y - get_viewport().size.y) / 2)
    
    func add_recoil():
    	var min_offset_value = -10 * guns_collection[active_gun_number].power
    	var max_offset_value = 10 * guns_collection[active_gun_number].power
    	
    	randomize()
    	var x_offset = rand_range(min_offset_value, max_offset_value)
    	var y_offset = rand_range(min_offset_value, max_offset_value)
    	var offset = Vector2(x_offset, y_offset) * get_resolution_ratio()
    	
    	var real_mouse_position = get_viewport().get_mouse_position() * get_resolution_ratio()
    	var new_mouse_position = real_mouse_position + offset + get_aspect_ratio_difference()
    	Input.warp_mouse_position(new_mouse_position)

    Thank you.

  • Megalomaniak
    Yes, that's right, I'm using Godot 3.5.1


    I'm trying to move the mouse to a random value based on weapon strength. The multiplication is done to solve the problem with the difference between the values needed for Input.warp_mouse_position() and those returned by get_viewport().get_mouse_position(). Here is the simplified code:

    var min_value = -10 * gun_power
    var max_value = 10 * gun_power
    
    var x_offset = rand_range(min_value, max_value)
    var y_offset = rand_range(min_value, max_value)
    var offset = Vector2(x_offset, y_offset) * get_resolution_ratio()
    
    var real_mouse_position = get_viewport().get_mouse_position() * get_resolution_ratio()
    var new_position = real_mouse_position + offset
    Input.warp_mouse_position(new_position)

    Sometimes refactoring comes to code obfuscation, I'm sorry.

    • Hello.

      In my 2D game, while shooting, the cursor position is changed after each shot by the following method:

      func get_resolution_ratio():
      	return get_viewport().size.x / 800	# Game resolution 800x600
      
      func shot():
      	# Part of the method:
      	Input.warp_mouse_position(get_viewport().get_mouse_position() * get_resolution_ratio() + Vector2(rand_range(-10 * get_resolution_ratio() * gun_power, 10 * get_resolution_ratio() * gun_power), rand_range(-10 * get_resolution_ratio() * gun_power, 10 * get_resolution_ratio() * gun_power)))

      The get_resolution_ratio() method is needed because get_viewport().get_mouse_position() returns the mouse position using the game resolution set in the project settings, while Input.warp_mouse_position() uses the resolution that actually exists at the moment. Because of this, you need to multiply the argument by the ratio of the resolution from the settings and the really existing resolution.

      The problem is that it doesn't work correctly, in full screen mode the cursor always moves up and with a much larger step relative to windowed mode (taking into account the difference in resolutions).

      Project sources. Used code.

      What did I do wrong? Why doesn't it work? Or do you need to decide differently?

      • Megalomaniak
        The problem was due to the difference in the aspect ratio of the monitor and the game (the presence of black bars along the edges of the screen), this problem was solved. Here is the final code, I had to add another method:

        func get_resolution_ratio():
        	return get_viewport().size.x / 800
        
        # Returns the size of the black area from the edge of the screen
        func get_aspect_ratio_difference():
        	if !OS.window_fullscreen:
        		return Vector2(1, 1)
        	
        	if OS.get_screen_size().y == get_viewport().size.y:
        		return Vector2((OS.get_screen_size().x - get_viewport().size.x) / 2, 1)
        	if OS.get_screen_size().x == get_viewport().size.x:
        		return Vector2(1, (OS.get_screen_size().y - get_viewport().size.y) / 2)
        
        func add_recoil():
        	var min_offset_value = -10 * guns_collection[active_gun_number].power
        	var max_offset_value = 10 * guns_collection[active_gun_number].power
        	
        	randomize()
        	var x_offset = rand_range(min_offset_value, max_offset_value)
        	var y_offset = rand_range(min_offset_value, max_offset_value)
        	var offset = Vector2(x_offset, y_offset) * get_resolution_ratio()
        	
        	var real_mouse_position = get_viewport().get_mouse_position() * get_resolution_ratio()
        	var new_mouse_position = real_mouse_position + offset + get_aspect_ratio_difference()
        	Input.warp_mouse_position(new_mouse_position)

        Thank you.

    • Hello.

      Lightocculder2D with more than four-rod OcculderPolygon2D with Cull Mode equal to Clockwise works as OcculderPolygon2D with Cull Mode equal to D But with Lightocculder2D, with less than four-shaped OcculderPolygon2D with Cull Mode, the clockwise is working fine.

      It's all on Godot 3.4.4.Stable.arch_linux with GLES2.

      How to fix it? Maybe the problem is in GLES2?

      It is translated by Google, inaccuracies are possible.

    • Hello.

      There are Area2D (EnemySpawner scene) to which the script is attached:

      extends Area2D
      export(Vector2) var spawn_position
      func _on_EnemySpawner_body_entered(body):
          if body.name == "Player":
              var enemy = load("res://Scenes/Enemy.tscn").instance() # Enemy - KinematicBody2D
              enemy.position = spawn_position 		$"../../Enemies".add_child(enemy) # It gives errors

      and the main scene in which there is an instance of EnemySpawner.

      And so, at the entrance of the player in the region, the enemy will spawn, but issues:

      body_set_shape_disabled: Can't change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead.
      body_set_shape_as_one_way_collision: Can't change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead.
      body_set_shape_as_one_way_collision: Can't change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead.

      What am I doing wrong?

      It is translated by Google, inaccuracies are possible.

      • Try changing:
        $"../../Enemies".add_child(enemy)
        to:
        $"../../Enemies".call_deferred("add_child", "enemy")

    • cybereality
      Hmm, it looks like the problem is really in the direction of the beam. For some reason, the player shoots under himself (the first coordinates are the player's position, the second are the mouse position). I will try to solve this problem myself. Thanks for your help, you helped me find the cause of the problem.

    • cybereality
      get_world_2d I really wrote incorrectly on the forum, there are brackets in the code.
      The script is tied to the Player, i.e. self is the player.

    • cybereality
      I checked, the ray accurately passes through the enemy (and hits the wall behind him). Perhaps the problem is that this is the second instance of the scene?

    • Hello.

      The structure of the main scene:

      • Node2D:
      • - Player
      • - Enemies:
      • - - Enemy1
      • - - Enemy2

      The structure of the enemy scene (Enemy.tscn):

      • KinematicBody2D:
      • - Sprite
      • - CollisionShape2D

      Player - scene instance Player.tscn; Enemies - Node; Enemy1 and Enemy2 are instances of the Enemy.tscn scene;

      The problem is that when the Player casts the ray using get_world_2d.direct_space_state.intersect_ray(coordinates1, coordinates2, [self]), it passes through Enemy2 without touching it (but it hits Enemy1).

      What is the problem here and how to solve it?

      • cybereality
        Hmm, it looks like the problem is really in the direction of the beam. For some reason, the player shoots under himself (the first coordinates are the player's position, the second are the mouse position). I will try to solve this problem myself. Thanks for your help, you helped me find the cause of the problem.