Lerp() and Clamp() as safe line
Asked Answered
F

3

0

Hello!
This is a question about the typing behavior and safe line casting (that little number on left side of every single line of any script in godot).
I know isn't needed and code can work anyway without that numbers becoming green, but i really feeling obsessed about it, and i always try to having all clear.
So, can someone tell me how a line like this should be formatted to having a safe line? (In Godot v4.1.1)
Thanks!
Update: I believe i found the solution by using clampf()

@onready var playerbase_spring := $playerbase_mount/playerbase_spring as SpringArm3D

func _process(_delta: float) -> void:
   (playerbase_spring as SpringArm3D).rotation.x = clamp((playerbase_spring as SpringArm3D).rotation.x, -PI/4, PI/4)
Flaunt answered 2/8, 2023 at 4:20 Comment(0)
M
0

Flaunt safe line casting

I haven't heard of that. Is there a link that explains it?

Merry answered 2/8, 2023 at 6:13 Comment(0)
F
0

Merry Yes! There you go the official documentation:
https://docs.godotengine.org/en/3.1/getting_started/scripting/gdscript/static_typing.html#safe-lines

Flaunt answered 2/8, 2023 at 6:29 Comment(0)
F
0

Update solution found!
I think this is the solution and it seems to work, if someone has something to add, happy to read.

https://docs.godotengine.org/en/stable/classes/[email protected]#class-globalscope-method-lerpf
https://docs.godotengine.org/en/stable/classes/[email protected]#class-globalscope-method-clampf

Note: For better type safety, use lerpf(), Vector2.lerp(), Vector3.lerp(), Vector4.lerp(), Color.lerp(), Quaternion.slerp() or Basis.slerp().
Note: For better type safety, use clampf(), clampi(), Vector2.clamp(), Vector2i.clamp(), Vector3.clamp(), Vector3i.clamp(), Vector4.clamp(), Vector4i.clamp(), or Color.clamp().
Flaunt answered 2/8, 2023 at 7:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.