godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.47k stars 21.07k forks source link

Rect2 class lacks definitions of `lerp()`/`cubic_interpolation()` and error occurs when interpolating negative values #80627

Open 2fd5 opened 1 year ago

2fd5 commented 1 year ago

Godot version

v4.1.1.stable.flathub [bd6af8e0e]

System information

Linux pop-os 6.4.6-76060406-generic, RTX3060

Issue description

When animating texture_scale with cubic mode there is a flood of this error message E 0:00:03:0438 intersects_transformed: Rect2 size is negative, this is not supported. Use Rect2.abs() to get a Rect2 with a positive size. <C++ Source> core/math/rect2.cpp:113 @ intersects_transformed() I assume animation is trying to set the value to something out of range, I would expect that would be handled by the editor and this situation will be prevented in AnimationPlayer or somewhere else.

Steps to reproduce

  1. Create a scene of type PointLight2D
  2. add AnimationPlayer
  3. Animate texture_scale property from minimal 0.01 in frame 1
  4. to 0.2 in next keyframe
  5. Set interpolation mode to cubic for this animation track
  6. set animation to auto play
  7. start the scene

Minimal reproduction project

animation_issue.zip

2fd5 commented 1 year ago

I'll try to add minimal project as I see there might be other factors included to replicate that. Added. Just run the game. The main scene should start triggering the error message.

TokageItLab commented 1 year ago

I think this is expected behavior, since cubic interpolation generates a curvilinear interpolation with overshoot from the previous and next points.

A correct way to fix this would be to implement lerp()/cubic_interpolate() in the Rect2 class correctly to avoid error as same as Vector2/Vector3/Quaternion etc.

Abhiraj-Shrotriya commented 1 year ago

@TokageItLab

I would like to solve this issue and contribute to the Godot Engine. Can you please assign me?

Thank you

AThousandShips commented 1 year ago

Issues aren't assigned like that, you open up a PR if you have a solution, welcome!

Abhiraj-Shrotriya commented 1 year ago

Oh, alright. Someone had to be assigned in the repository I worked in the last time so I thought the same workflow was followed here too.

Will try to solve this.

Thanks :)

AThousandShips commented 1 year ago

Make sure to read here and here

AThousandShips commented 1 year ago

@Abhiraj-Shrotriya are you still looking into this? If not there's no need now

mateuseap commented 1 year ago

@Abhiraj-Shrotriya sorry for not asking if you're working on this before opening my PR.

Abhiraj-Shrotriya commented 1 year ago

@mateuseap @AThousandShips

Hi, I got a little busy in other problems. I am sorry. I did not get the time to look at this issue. Thanks for solving it.