xamarin / urho

Code to integrate with the Urho3D engine
Other
463 stars 122 forks source link

Bug with collision shape size #288

Open Alan-FGR opened 6 years ago

Alan-FGR commented 6 years ago

Hi there. When you create a collision shape, say:

CollisionShape shape = child.CreateComponent<CollisionShape>();
shape.ShapeType = ShapeType.Box;

the shape size is 1,1,1, although the shape doesn't show in the debugger and is not detectable by raycasts nor GetRigidBodies (which I've bound 😃)... and the strange part is that even when you do say this:

shape.Size = Vector3.One;

for some reason that does not affect it at all, debugger still shows no collision shape whatsoever, but when you do this:

shape.Size = Vector3.One*0.99f;

then it works properly.

My guess is that the shape has zero size although UrhoSharp shows 1, and when you set it to 1 for some reason the value is discarded possibly because it checks whether value is different, but that seems to be on Urho side (managed Shape.SetSize (Size property) and native CollisionShape_SetSize (C wrapper) don't check that).

gleblebedev commented 6 years ago

@Alan-FGR have you tried to call SetBox instead of assigning shape type?

Alan-FGR commented 6 years ago

@gleblebedev no I haven't. I didn't even know there is such a method and personally I'm not a big fan of that kind of API, so Shape has a "Set___" for each shape type? That doesn't seem good API imho.

EgorBo commented 6 years ago

@Alan-FGR it sounds like a bug in urho3d. It does have the check you mentioned: https://github.com/xamarin/Urho3D/blob/master/Source/Urho3D/Physics/CollisionShape.cpp#L764 the constructor sets Size to Vector3.ONE so SetSize(Vector.One) won't have any effect.