Smooth camera transition (2D & 3D) in Godot (under 5 MINUTES)

Поделиться
HTML-код
  • Опубликовано: 26 дек 2024

Комментарии • 48

  • @vinnmarty
    @vinnmarty Год назад +41

    To anyone having trouble making this work with Godot 4, replace the code after "transitioning = true" at 3:42 with this and it should work:
    tween = create_tween()
    tween.set_parallel(true)
    tween.set_ease(Tween.EASE_IN_OUT)
    tween.set_trans(Tween.TRANS_CUBIC)
    tween.tween_property(camera3D, "global_transform", to.global_transform, duration).from(camera3D.global_transform)
    tween.tween_property(camera3D, "fov", to.fov, duration).from(camera3D.fov)
    # Wait for the tween to complete
    await tween.finished

    • @mrelipteach
      @mrelipteach  Год назад +1

      Thanks for your comment! This also works with 3.5 as the SceneTreeTween was added in 3.5

    • @jorisoosterbeek9440
      @jorisoosterbeek9440 Год назад

      This generates a slew of errors for me sadly, do you have any idea why?:
      Line 3:Could not find type "Camera" in the current scope.
      Line 4:Cannot assign a value of type Node to variable "tween" with specified type Tween.
      Line 14:Could not find type "Camera" in the current scope.
      Line 14:Could not find type "Camera" in the current scope.

    • @michaelorlev9925
      @michaelorlev9925 Год назад

      @@jorisoosterbeek9440 is your "camera" a variable? or a built in type?

    • @jmvr
      @jmvr Год назад +1

      @@jorisoosterbeek9440 1. "Camera" is no longer a type, replaced by "Camera3D" instead. 2. Tween is no longer a Node, now being a misc type. 3. Probably related to #1

  • @Daelon_Suzuka
    @Daelon_Suzuka 2 года назад +33

    The real red pill is to only have one camera and just move it where you want it.

    • @mrelipteach
      @mrelipteach  2 года назад +9

      it might work in some games for sure!

    • @Dark_Peace
      @Dark_Peace 2 года назад +3

      The only true way

    • @maximkulkin2351
      @maximkulkin2351 Год назад +1

      Exactly. Kind of like Cinemachine in Unity, where they have a number of "virtual cameras" and main camera switches or transitions between them. The only caveat is that you can have different camera settings on cameras (e.g. cull layers) which could be useful, but with a single camera copying those settings is extra work.

  • @sung3n
    @sung3n Год назад +5

    If you're trying to tween to a moving camera, create a variable to hold a "tween.follow_property()" and then set the 4th argument of interpolate_property() to the variable.

  • @michaelc9285
    @michaelc9285 2 года назад +3

    I swear I was just trying to do this with not much luck literally last night. Tysm for this you saved me a lot of time ;)

  • @Doogin21
    @Doogin21 Год назад +3

    This tutorial is excellent. Thank you!

  • @fnanfne
    @fnanfne Год назад +2

    Thanks for the video, appreciated! As always, I dislike all the drastic changes whenever a new version of godot is released. The difference between 3 and 4 is just staggering. You get contributors changing the names of functions because for them, it's "weird". As a beginner coder just doing this for fun, it's extremely frustrating as most of the tutorials in existence are from version 3. I should have just started with version 3!
    It seems like the "current" property was removed from Camera2D (again, as some contributor felt it was "weird", urgh) and replaced with "enabled". Note that it's not "is_current", but "enabled". So in the code from this video, instead of using "camera2D.current = false", use "camera2D.enabled = false".

  • @mrelipteach
    @mrelipteach  2 года назад +6

    ✨ Get it on the Asset Lib
    godotengine.org/asset-library/asset/1574
    💻 Checkout the sources
    github.com/MrEliptik/godot_camera_transition
    Tell me what kind of tutorials you'd like to see next 👇

    • @saulnores3477
      @saulnores3477 2 года назад

      Great video. Can you make a video explaining Class and Classname and what they are used for, please?

  • @TheFilipFonky
    @TheFilipFonky 2 месяца назад +1

    My alternative way is to teleport a Marker3D to the target location first, then Tween the camera towards it.

  • @rashSLG
    @rashSLG Год назад

    Very helpful very fast! thank you thank you!

  • @lukaspaver
    @lukaspaver 10 месяцев назад

    I didn't even knew about Tween in Godot. Kinda suprised that this is built into the engine. I had to modify a few thing because I'm working with Godot 4

    • @mrelipteach
      @mrelipteach  10 месяцев назад

      Tween are incredible! I'm going to make a video on the subject

  • @Dark_Peace
    @Dark_Peace 2 года назад +1

    Wait a minute, I know this man

  • @rj_enoz
    @rj_enoz 8 месяцев назад +2

    Thank you for the tutorial!!!
    😊
    My solution for godot 4.1.1
    (Usage 3D CameraMovements)
    ===========FIxing=============================
    Have to change >
    1. @onready var camera: Camera3D = $Camera >
    @onready var camera3D: Camera3D = $Camera
    2. func transition_camera3D(from: Camera, to: Camera, duration: float = 1.0) -> void:
    >func transition_camera3D(from: Camera3D, to: Camera3D, duration: float = 1.0) -> void:
    3. add *var* tween infront of it
    (Copy @vinnmarty Comment Code from above)
    4. Remove 2D camera.
    Apparently the 2D camera block my ui.
    ==========APPLYING==========
    1. Create new Function for u to call about in your scene :
    func CameraTransitionAnimation() -> void:
    CameraTransition.transition_camera3D(Camera1,Camera2, 3.0)
    2. Put in call method in animation player to switch to the camera.

  • @dyuhychbeitz5796
    @dyuhychbeitz5796 Год назад +2

    But what if camera that i want to switch to is moving?Transition camera goes at wrong place because camera that i want to switch to is gone.

    • @jatoxo
      @jatoxo Год назад +2

      Use the follow_property function from the tween node instead

    • @sung3n
      @sung3n Год назад

      @@jatoxo How would you do that?

  • @ukrsolid
    @ukrsolid 2 года назад

    cool feature

  • @foreverAnkh
    @foreverAnkh 2 года назад +5

    I respectfully disagree on this method. Though there are many ways of getting the same result, this is over complicating the solution. You shouldn't need more cameras unless you are using those cameras. You should rewrite this code using the Position3D node instead if all you care is about position. Better yet, use Path and PathFollow nodes for better control of camera movement.

    • @mrelipteach
      @mrelipteach  2 года назад

      This is a transition camera. The whole point of my solution is to not move your other cameras, that way you don't have to remember their original postion or whatever. I think this is not complicated at all, especially in terms of usage, you simply call a function..

    • @foreverAnkh
      @foreverAnkh 2 года назад +3

      @@mrelipteach The problem isn't the function at all, it is that cameras are being used as place-markers when simpler nodes can achieve the same effect. I think this is better grasped if you think of it in terms of scalability. I would rather have 100 Position3D nodes rather than 100 cameras for efficiency sake.

    • @Namrevetahw
      @Namrevetahw 2 года назад

      Yeah, I was thinking the same, like a fifth wheel on a motorcycle.

    • @KrystofKlestil1337
      @KrystofKlestil1337 2 года назад +8

      I thought about this as well, and at the beginning would have agreed, but then I thought about two things that make this system work well:
      1. you can reference, set and animate all of the other camera parameters (could make a custom class extending node3D)
      2. Get a preview of what that camera will be looking at, quickly, tweak it, move it, trash it. This is a boost in workflow, often undervalued i find.
      Specifically 2. is sometimes priceless when you either looking for the right angle or just tweaking it to perfection

  • @Ukysseus
    @Ukysseus Год назад +1

    I'm on Godot 4 and everything involving tween doesn't work. Actually all I want to do is to make my camera 2D slide to a Marker2D's position. Is there an easier way to do that?

    • @mrelipteach
      @mrelipteach  Год назад

      Yeah the tween node doesn't exist in Godot 4, you have to use Tween just from code docs.godotengine.org/en/stable/classes/class_tween.html

  • @KazoWAR
    @KazoWAR 2 месяца назад

    i cant find a tween node

    • @mrelipteach
      @mrelipteach  2 месяца назад

      Tween node doesn't exist in Godot 4. It's just a Tween class now similar to SceneTreeTween in Godot 3

  • @lv99redchocobo
    @lv99redchocobo 6 месяцев назад

    do you know if you can use both 2d and 3d in 1 game in godot?

    • @mrelipteach
      @mrelipteach  6 месяцев назад +1

      There's a Godot demo for 2D in 3D, that can be helpful godotengine.org/asset-library/asset/129

    • @lv99redchocobo
      @lv99redchocobo 6 месяцев назад

      @@mrelipteach thank you

  • @AleksandarPopovic
    @AleksandarPopovic 2 года назад

    Nice idea, but where is your Global camera?

    • @mrelipteach
      @mrelipteach  2 года назад

      What do you mean where is it? In the tutorial I create a scene that I put in autoload. In the scene there are two cameras: a 2D camera and a 3D one

  • @akash0156
    @akash0156 2 года назад

    Are you used c# or gd script?
    Which one is better for Godot

    • @mrelipteach
      @mrelipteach  2 года назад

      @DevRealm is right. Just to add to this, it depends what "better" is for you. GDScript is made for Godot, so its really well integrated and it probably has more tutorials using it. For most games, it's probably fast enough. The major bonus is that it's easy to write.
      Now, if you prefer C# or you need it because you want to integrate some C# library, it's a different story. Also C# might give you some performance boost if you need to do some specific things.

  • @OriginalJoka
    @OriginalJoka 11 месяцев назад

    I can't find how this method is working in godot 4

    • @mrelipteach
      @mrelipteach  11 месяцев назад +2

      It's the same idea but Camera.current is now Camera.enabled