Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Bleenx | |
Old Version | Published before Godot 3 was released. |
I wanted to create a function specifically for my gravity and use delta
within it. After the code, I’d call the function under _fixed_process(delta):
but Godot doesn’t seem to recognize delta
anywhere outside of the process function.
Is this something I always have to use in the _process
function no matter what? I like to keep my code clean with separate functions and call them in the _process
, but if I can’t do that with anything pertaining to delta
, then I have no choice but to write it all out under that function.
This is my code:
extends KinematicBody2D
export var playerSpeed = 0
export var force = 0
func _ready():
set_fixed_process(true)
func _fixed_process(delta):
Movement()
Gravity()
func Movement():
var left = Input.is_action_pressed("leftButton")
var right = Input.is_action_pressed("rightButton")
if (left):
get_node("playerSprite").set_flip_h(true)
move(Vector2(-playerSpeed, 0))
elif (right):
get_node("playerSprite").set_flip_h(false)
move(Vector2(playerSpeed, 0))
else:
move(Vector2(0, 0))
func Gravity():
move(Vector2(0, force))
I want to multiply force by delta but just not sure how to do it this way…
Bleenx | 2016-05-15 04:38