1

My Godot 2d game contains lines that servers as platforms and walls, they are defined as segmentShape2D which contain a start point and an endpoint:

var staticBody2D = new StaticBody2D();
Vector2 a = new Vector2((float)foothold.X1, (float)foothold.Y1);
Vector2 b = new Vector2((float)foothold.X2, (float)foothold.Y2);
Vector2 direction = (b - a).Normalized();

var collisionShape = new CollisionShape2D();
collisionShape.OneWayCollision = true;
var segmentShape = new SegmentShape2D();
segmentShape.A = a;
segmentShape.B = b;
collisionShape.Shape = segmentShape;

staticBody2D.SetMeta("direction", direction.Rotated(Mathf.RadToDeg(90f)));
staticBody2D.SetMeta("layer", layer);
staticBody2D.AddChild(collisionShape);
AddChild(staticBody2D);

For platforms my character behaves normally, it can jump from below to the current platform. But for walls, my character passes through from both left&right sides, as oneWayCollision only detects collision from UP or Downside. enter image description here

So My question is how to implement a one-way collision wall or slope based on its direction in Godot?

1 Answer 1

0

Since the character should not enter the ground (I suppose), you could use a CollisionPolygone2D instead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.