Closed VerdeCreeper closed 6 months ago
Hello @VerdeCreeper. After looking into this, I'll admit that setting up the advance shader isn't as simple as it should be, and can be confusing. The black screen tends to happen when the script isn't configured correctly, and is generally accompanied by a Godot Error.
To configure it correctly here's a screenshot of how I did it. Make sure the Array is at size 0 (at least for now), that the Office Clamp for the y axis is between 0 and 0.5, and that Shader Path points to the Perspective Shader node.
Please tell me if this works on your side.
Thanks a lot helping! Also you know if it possible to make a 360° office?
@VerdeCreeper No problem ! And yes it's possible, although you'll need to make a few modifications to the code and you'll need a 360° office render. Since I've already done it, here's the code I made to make it work. And here's a 360° office render of the office already in the Framework. You'll also need to modify the Office Clamp settings to make it work too (I personally put it at 1500). Keep in mind, that everything I shared was only tested in Godot 3.5.2 with the simple office script so I can't guarantee that it'll work.
What is the var/indentifier of can_fully_turn?
@VerdeCreeper It's a boolean. It was supposed to be there for users in Godot to easily activate/deactivate 360° turning. If you're only looking to make the 360° turning, you'll only need what's in the else statement.
Can you simply copy and paste the script?
extends TextureRect
export var pan_speed : float
export var office_clamp : int
# An export made for objects that need a slight offset due to the equirectangular shader (most notably hitboxes for buttons)
# Reminder that objects need to be an Array of an Array to work
# [NodePath, PanOffsetSpeed_x(int), SpeedClamp_x(int), SizeClamp_x(int)]
export var list_offset_corrections : Array
export var can_fully_turn : bool
# border_distance[0] is for the left border and border_distance[1] is for the right border
var border_distance : Array = [0,0]
var pos_offset : int = rect_position.x
func _ready():
# Get horizontal window size
var view_size_x : float = get_viewport().size.x
# The border correcters are made to fix a 1 pixel issue in the code when moving the cursor
# all the way to the Right of the screen
var border_correcter_x : float = 1/(1920/view_size_x)
# This calculates the area where the cursor needs to be to move the view
border_distance[0] = view_size_x / 5 # To the Left
border_distance[1] = view_size_x - (border_distance[0] + border_correcter_x) # To the Right
# Uses the nodepath within the exported array to use the actual object
for i in list_offset_corrections:
i[0] = get_node(i[0])
func _physics_process(delta):
var mouse_position : Vector2 = get_viewport().get_mouse_position()
var pan_value : float = 0.0
# Checks if the mouse is within one the mouse movement areas, and pans the office if it is
if mouse_position.x < border_distance[0]:
pan_value = (border_distance[0] - mouse_position.x) * int(Global.can_move) * pan_speed
elif mouse_position.x > border_distance[1]:
pan_value = (border_distance[1] - mouse_position.x) * int(Global.can_move) * pan_speed
if can_fully_turn == false:
# Modifies the position of the office, while clamping it, so the office stays in frame
rect_position.x= clamp(rect_position.x + clamp(pan_value * delta, -40,40), -office_clamp + pos_offset, office_clamp + pos_offset)
else:
rect_position.x= rect_position.x + clamp(pan_value * delta, -40,40)
if(rect_position.x > office_clamp + pos_offset):
rect_position.x = rect_position.x - (rect_size.x/2)
elif(rect_position.x < -office_clamp + pos_offset):
rect_position.x = rect_position.x + (rect_size.x/2)
# Modifies the buttons collision postion, makes it so the button is pressable with the shader
apply_offset(pan_value, delta)
func apply_offset(pan_value : float, delta : float):
for i in list_offset_corrections:
i[0].position.x = clamp(i[0].position.x + clamp(pan_value/i[1] * delta, -i[2],i[2]), -i[3], i[3])
Again 3.5.2 code, you'll need to adapt it to 4.0.
It kinda works. I only had to change the Sprite2D
to TextureRect
, export
to @export
, rect_position
to position
and rect_size
to size
. However the panorama doesn't "loop" and leaves a black void in the sides
I think it has something to do with the Control Layout
@VerdeCreeper That's normal, to fix this you'll need to increase the width of the office TextureRect
and modify the Stretch Mode to Tile (or its 4.0 equivalent).
You might also need to modify some shader parameters in the _PerspectiveShader node, so here are the values I used.
Unless you encounter an issue, that should be it
Thanks, it works! The only thing that I need is the Y rotation and adjust the cupcake button, but other than that, thank you.
No problem ! For the Y axis, that's just a matter of copy pasting sections of the advanced script into what I sent you, it's all commented so it should be easy to figure out.
As for the cupcake button, i'll advise you to turn on Visible Collision Shapes in the debug tab, and get an understanding of the example present in the base project by looking at the comments and toying with the List Offset Correction values. It's not easy to explain, and requires quite a bit of trial and error to get it working right. So I won't be able to help you with that.
Anyways, good luck with your project ^^.
Sorry for bothering you one last time, but, can you paste the 360° script with the advanced sections? I having a problem with the Vector2
, int
and float
Hi, i'm trying to change to the advanced office script, but I really didn't understand how it actually works, and every time I play the scene it shows only a black screen.
So what is your main setup for the advanced script? The office clamp should be the same as the simple? And should add one or two arrays? with the same size and configs?