Godot Version
` 4.2.2
Question
` Ok, so I’m working on a tetris/platformer hybrid, and I was making laser blocks. All was going well until I exported to html, and then problems started. The laser blocks functioned normally (being blocked by obsatcles) in my native browser/OS, but some others (maybe windows OS has something to do with it) had the lasers passing through objects. This is not a collision error (as they actual laser collides with the block and not the player if theres a block in the way), but rather a coordinate error (it displays incorrectly). I think. Anyway, here’s the relevant code.
func _process(delta):
var length = 1000
if get_collider() != null:
if get_collider().name == "Player": get_parent().get_parent().get_parent().get_node("Game Manager").lose()
length = (get_parent().position - get_collision_point()).length() - 14
get_node("Image").position = target_position.normalized() * (13 + length/2)
get_node("Image").scale = abs(target_position.normalized()) * (length - 2) + Vector2(4, 4)
I essentially take a sprite2d and modify its scale based on the collision point of a ray.
Also (related?), back when I was starting this project and didn’t know about control nodes, I created buttons and manually centered them with code. This also seems to work in some environments but not others (I tried firefox and safari and both browsers work, but Windows computers didn’t). Here’s the code:
func _process(delta):
menu = get_node("../Settings/Settings").menu
if float(get_viewport().size.y) / ProjectSettings.get_setting("display/window/size/viewport_height") > float(get_viewport().size.x) / ProjectSettings.get_setting("display/window/size/viewport_width"):
height = get_viewport().size.y * ProjectSettings.get_setting("display/window/size/viewport_width") / get_viewport().size.x
width = ProjectSettings.get_setting("display/window/size/viewport_width")
else:
height = ProjectSettings.get_setting("display/window/size/viewport_height")
width = get_viewport().size.x * ProjectSettings.get_setting("display/window/size/viewport_height") / get_viewport().size.y
$Replay.scale = Vector2(height * 4.0 / ProjectSettings.get_setting("display/window/size/viewport_width"), height * 4.0 / ProjectSettings.get_setting("display/window/size/viewport_width"))
$Menu.scale = Vector2(height * 4.0 / ProjectSettings.get_setting("display/window/size/viewport_width"), height * 4.0 / ProjectSettings.get_setting("display/window/size/viewport_width"))
if $Next != null: $Next.scale = Vector2(height * 4.0 / ProjectSettings.get_setting("display/window/size/viewport_width"), height * 4.0 / ProjectSettings.get_setting("display/window/size/viewport_width"))
if width > height:
$Replay.position = Vector2(ProjectSettings.get_setting("display/window/size/viewport_width")/2 - 36*$Replay.scale.x, height/6)
$Menu.position = Vector2(ProjectSettings.get_setting("display/window/size/viewport_width")/2 - 36*$Menu.scale.x, height/3)
if $Next != null: $Next.position = Vector2(ProjectSettings.get_setting("display/window/size/viewport_width")/2 - 36*$Menu.scale.x, height/2)
else:
$Replay.position = Vector2(ProjectSettings.get_setting("display/window/size/viewport_width")/2 - 36*$Replay.scale.x, height/3)
$Menu.position = Vector2(ProjectSettings.get_setting("display/window/size/viewport_width")/2 - 36*$Menu.scale.x, height/2)
if $Next != null: $Next.position = Vector2(ProjectSettings.get_setting("display/window/size/viewport_width")/2 - 36*$Menu.scale.x, height*2/3)
Apologies for the messy code, and thanks so much for your help!!