Skip to content

Vector3.snapped gives incorrect result with negative values #6399

@eon-s

Description

@eon-s

Operating system or device - Godot version:
Windows 7 64bit - Tested on Godot 2.03, 2.1 and current sources

Issue description (what happened, and what was expected):
What happened:
Vector3.snapped rounds to the higher number (less negative) instead of the closest to the given argument when the value is negative.

What was expected:
Same behavior/result as GDScript.stepify or Vector2.snapped (rounded to the closest number).

Steps to reproduce:
Running a script with the following lines:

    print("original      : ",Vector3(-9.8,9.8,0.6))
    print("V3 snapped: ",Vector3(-9.8,9.8,0.6).snapped(0.5))
    print("V2 snapped: ",Vector2(-9.8,9.8).snapped(Vector2(0.5,0.5)))
    print("stepify       : (",stepify(-9.8,0.5),", ",stepify(9.8,0.5),", ",stepify(0.6,0.5),")")

Gives as output:

original : (-9.8, 9.8, 0.6)
V3 snapped: (-9.5, 10, 0.5)
V2 snapped: (-10, 10)
stepify : (-10, 10, 0.5)

The second line has a wrong snapped x value.

Link to minimal example project (optional but very welcome):

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions