How to do this with 2D? - 3D KinematicBody Align with terrain - (Kids can code Tutorial)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By bingbong

From this (rather good!) tutorial

I need this in a 2D setting, theres a few people asking in the comments, but no ones filled in any clues…

Im guessing its changing this align function

func align_with_y(xform, new_y):
	xform.basis.y = new_y
	xform.basis.x = -xform.basis.z.cross(new_y)
        xform.basis = xform.basis.orthonormalized()
	return xform

but not sure how to approach it, ‘basis’ is for xyz, is it transform2D to use here (for xy)? Not sure that cross product is relevant here for 2D either!!

Thanks in advance!

Not sure what the problem is, but in 2D you dont have transform and basis and all that fancy stuff(since you dont need).
3D holds 3 rotational axis 3 planes and 3 movement axis, while 2D holds only 1 rotational axis, 1 plane and 2 movement axis. Thus in 2D you simply have rotation/rotation_degrees and position/global_position, you don’t need to have transform and basis since you have a much simpler world to work in

rustyStriker | 2020-11-02 09:32

:bust_in_silhouette: Reply From: kidscancode

There is a 2D version of this:

http://kidscancode.org/godot_recipes/2d/2d_align_surface/

ooh! Awsome! This actually answers another (unrelated) question I had.

rustyStriker, I had gone through the docs and saw that the transform only seemed to deal with 2 axis, so was only guessing at that point, but yeah, much simpler than Im making it - as usual!

Thanks for your replies!

bingbong | 2020-11-02 21:28