Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derived instance of CollisionShape2D using parent parameters instead of their own #13835

Closed
gururise opened this issue Dec 2, 2017 · 5 comments

Comments

@gururise
Copy link
Contributor

gururise commented Dec 2, 2017

Operating system or device, Godot version, GPU Model and driver (if graphics related):
Linux - Godot 3.0 Beta

Issue description:

Colliders in derived scenes do not use their position or size, instead they use the parent scene Collider position/size.

I would expect the derived scene CollisionShape2D to use its position and size for performing collisions, as other nodes (ie. Sprite) in the derived class make use of their own properties (ie. transform, texture).. otherwise, inheritance for character scenes will really only work for sprites/characters that are the same size.

A clear example of the problem:
image

Steps to reproduce:
I have the following base scene:
Character (KinematicBody2D)
|-Sprite
|-CollisionShape2D (Capsule Collider)

I derive two scenes from the above:

  • Skeleton
  • Player

Note: In each of the derived scenes, the Shape2D sub-resource of the associated CollisionShape2D has been made "Local to Scene".

On the left is the parent character scene. On the right is the derived skeleton scene:
image

Scene setup (all nodes are at the same y position), only sprites are scaled. (right - child scene player, center - parent scene character, left - child scene skeleton).

The scale of the CollisionShape2D and the KinematicBody2D are all (1,1). The derived CollisionShape2D capsules have been re-positioned and resized (but not scaled):
image

After running the scene (with gravity):
image

  • Notice the physics engine appears to be using the parent capsule collider position and size rather than the derived scenes capsule collider parameters.

  • Even making the Shape2D sub-resource "Local to Scene" in each derived CollisionShape2D does not fix the problem. Running the test scene, I've also confirmed that each CollisionShape2D object in each of the three character scenes is different, although I don't see a way in the editor/debugger to view the Shape2D sub-resource.

@gururise gururise changed the title Derived CollisionShape2D use parent parameters instead of their own Derived CollisionShape2D using parent parameters instead of their own Dec 2, 2017
@leoddd
Copy link
Contributor

leoddd commented Dec 2, 2017

The same goes for CollisionPolygon2D, meaning it's not an issue of sharing a resource as CollisionPolygon2D has no proper resource attached, just a PoolVector2Array to define the points.
collisioninheritance

@mrcdk
Copy link
Contributor

mrcdk commented Dec 2, 2017

This happens because the only times the shape transform is updated between the visual representation and the physics world happens when it's parented and when the local transform is updated: https://github.com/godotengine/godot/blob/master/scene/2d/collision_shape_2d.cpp#L51-L77

It looks like modifying the transform in a instanced scene isn't triggering the NOTIFICATION_LOCAL_TRANSFORM_CHANGED notification.

Not sure what to do with this but maybe this info helps someone else with it.

@gururise gururise changed the title Derived CollisionShape2D using parent parameters instead of their own [3.0] Derived CollisionShape2D using parent parameters instead of their own Dec 3, 2017
@gururise
Copy link
Contributor Author

gururise commented Dec 5, 2017

Note: The docs seem to imply that any changes to derived scenes should affect instances of the derived scene. So the behavior above does appear to be a bug:
http://docs.godotengine.org/en/stable/learning/editor/unity_to_godot.html?highlight=%20change%20#where-are-my-prefabs

@gururise gururise changed the title [3.0] Derived CollisionShape2D using parent parameters instead of their own [3.0] Derived Instance of CollisionShape2D using parent parameters instead of their own Dec 5, 2017
@akien-mga akien-mga added this to the 3.0 milestone Dec 8, 2017
@akien-mga akien-mga changed the title [3.0] Derived Instance of CollisionShape2D using parent parameters instead of their own Derived instance of CollisionShape2D using parent parameters instead of their own Dec 8, 2017
@gururise
Copy link
Contributor Author

gururise commented Dec 9, 2017

I've attached a minimal project demonstrating the problem:
image

inheritedScene.zip

@RandomShaper
Copy link
Member

Investigation in progress...

RandomShaper added a commit to RandomShaper/godot that referenced this issue Jan 11, 2018
This is needed because the final startup values for shapes may change between parenting and entering the scene tree. For instance, if the collision shape belongs to a inherited scene.

Fixes godotengine#13835.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants