0 votes

So I my start screen is integrated into a parallax background, and I want it to move when I move my mouse. How would I do this? I have already created script based off the Q&A answer here yet it doesn't seem to work

func _input(event):
if event is InputEventMouseMotion:
    var screensize = get_viewport().size
    var multiplier = 2
    var motion_offset = 0
    var mouse_x = event.position.x
    var mouse_y = event.position.y
    var relative_x = (mouse_x - (screensize.x/2)) / (screensize.x/2)
    var relative_y = (mouse_y - (screensize.y/2)) / (screensize.y/2)
    ParallaxLayer.motion_offset.x = multiplier * relative_x
    ParallaxLayer.motion_offset.y = multiplier * relative_y

Edit: With the answer provided I get the error saying "Invalid index 'motion_offset (on base: 'GDScriptNativeClass')"

in Engine by (309 points)
edited by

1 Answer

0 votes
func _input(event):
if event is InputEventMouseMotion:
ParallaxLayer.motion_offset += event.relative

Join that to your code and you should be fine

by (76 points)

I get an error saying "Invalid index 'motion_offset (on base: 'GDScriptNativeClass')"

Change to parallaxlayer.position

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 Frequently asked questions and 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 [email protected] with your username.