0 votes

func process(delta):
--- var bodies = get
overlappingbodies()
----for body in bodies:
-------if (body.get
name() == PLAYERNAME):
----------stairs.material.set("shaderparam/width", 0.5)
------else:
--------if (body.get
name() != PLAYERNAME):
-------------stairs.material.set("shader_param/width", 0.0)

hello can somebody help me? im trying to make the shader go "on" and "off" if the player get in the area2D.
until the statment "if" is work fine. but when i but the "else" statement. it doesn't work at all for both.
i wonder if someone have an insight?

Godot version 3.2.1
in Engine by (62 points)

nvm i find a way.. i use bodyexited instade of :
--------if (body.getname() != PLAYERNAME):
-------------stairs.material.set("shader
param/width", 0.0)

1 Answer

+2 votes
func physics_process(delta):
    var bodies = get_overlapping_bodies()
    var player_inside = false
    for body in bodies:
        if (body.get_name() == PLAYERNAME):
            player_inside = true
            break
    if player_inside:
        stairs.material.set("shaderparam/width", 0.5)
    else:
        stairs.material.set("shader_param/width", 0.0)

I think that will give you the effect you desire. Ideally you would have

class_name Player 

inside your Player.gd script then the code becomes very simple:

func physics_process(delta):
    if Player in get_overlapping_bodies():
        stairs.material.set("shaderparam/width", 0.5)
    else:
        stairs.material.set("shader_param/width", 0.0)
by (3,389 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.