How to Move an Object Using a Custom Point Instead of Its Center in GDevelop

Hey everyone! I’m trying to change an object’s position in GDevelop, but instead of moving it based on its center, I want to move it using a specific point that I added (e.g., “SnapPoint”).

For example, if ObjectA collides with ObjectB, I want ObjectA.Point(“SnapPoint”) to align with ObjectB.Point(“TargetPoint”).

I tried using ObjectA.X() = ObjectB.X() but that moves it by the center, not by the custom point.

Does anyone know how to properly set the position using custom points instead of the object’s center? Any help would be appreciated!

Thanks in advance!

Hi,

You just need to write the name of your point in quotation marks inside the bracket.

Like:

The point name will occur in the dropdown.

1 Like

Thanks for the response. That method moves the object to the position of the custom point, but I want to move the object by the custom point. That means the object’s position should change relative to the point I added, not just move to that point’s coordinates. I need a way to shift the entire object based on a specific point rather than just aligning it to that point. Is there a way to do that?

Object.X() + (Object.PointX("PointName") - Object.X())

Same for Y

For clarification, it seems like most of the replies so far are about mocing an object to a custom point, rather than move it with a custom point. ZeroX4’s post is close, but is missing some context.

Short answer: If you just want to move based off something over than the upper left corner and don’t need to keep the origin point there, just move the origin point and you won’t have to do anything special in events

Long answer:

Assuming I’m understanding the question correctly, you need to understand a few concepts:

  1. Object’s positions are based off their origin point. Not their center.
  2. The origin point can be moved, but that will also change where the object appears when placing it in the scene.
  3. Position and rotation are unrelated. Rotation will always be based on whereever the point names ‘center’ is located.

If you just want to move based off something over than the upper left corner and don’t need to keep the origin point there, just move the origin point and you won’t have to do anything special in events.

Otherwise, if you must keep the origin point on the upper left, it depends on where your point is in relation to the origin. You will always track (Object.PointX(yourpoint) - Object.X()) in whatever movement action you use, or keep it as an object variable. You will do the same for Y. You then have to add this value to whatever position you are moving to.

If your custom point is going to be to the 10 pixels left of the origin point, and the origin point is currently at X 15, this means you end up with (x10 - x15) -5. So when you move the object to x100, you would do ‘Move Object to 100 + (Object.PointX(yourpoint) - Object.X())’ which results in being moved to 95.

The same works if the point is to the right of the origin (e.g. x15-x10 becomes +5)

Hopefully that helps.

Edit: for your specific example in the op
Set X position of ObjectA to: ObjectB.PointX(“TargetPoint”) + (ObjectA.PointX(“SnapPoint”) - ObjectA.X())

1 Like