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

Document simplest way to turn 3D node towards an axis with interpolation #4478

Closed
DevMagicLord opened this issue Sep 26, 2018 · 13 comments
Closed

Comments

@DevMagicLord
Copy link

Instead of coding many lines of code each time,
a high level simplified function to rotate an object to face another object position.

TurnTo ( Vector3 position, Vector 3 axisTurn, bool direct, float speed, bool lerping)

Vector3 position: object to turn to
Vector 3 axisTurn : axis rotation to use
bool direct : turn directly , don' t use speed
float speed : rotation speed for turn
bool lerping : should use lerping when it uses speed

@groud
Copy link
Member

groud commented Sep 26, 2018

It's already simple enough. You can use the set_look_at(...) and interpolate_with(...) functions of Transform to achieve such behavior easily.

What you propose is too specific to end up into the core.

@groud
Copy link
Member

groud commented Sep 26, 2018

Or basically follow the comments there godotengine/godot#21383.

@DevMagicLord
Copy link
Author

DevMagicLord commented Sep 26, 2018

As your link, this new function is to avoid all those code lines.

About look_at, you can' t restrict two axis.
Fore example Vector(0,1,0) ; will allow the object to rotate on Y and X axes.
While it should be possible to allow only Y rotations for example.

Godot needs some high levels functions for very common things, like those Unity has.

@groud
Copy link
Member

groud commented Sep 26, 2018

About look_at, you can' t restrict two axis.

Yes you can, you simply have to change the look target. By basically putting your target as the same coordinates on the axis you want to restrict.

Godot needs some high levels functions for very common things, like those Unity has.

No, that's not Godot philosophy.

It might be a common thing, but there are a lot of ways to handle such movement. That's why such proposal is mostly pointless as too specific. The look_at and interpolate_with functions ease the work enough.

@DevMagicLord
Copy link
Author

Same coordinates as target is some good idea, unfortunately there was no examples on documentation to show different ways to use it :(

I don't understand, how can you rotate with lerp some object to another using look_at ?
When you use look_t the object is directly rotated you can't no more use lerp.

Why not combininig the two in some look_at_lerp() ?

@groud
Copy link
Member

groud commented Sep 27, 2018

Here we are, three lines of code :

func _process(delta):
	var target = $"../target".global_transform.origin
	var target_transform = Transform().looking_at(target, Vector3(0,1,0))
	global_transform = global_transform.interpolate_with(target_transform, 1 * delta)

output

Why not combininig the two in some look_at_lerp() ?

Because there is not more reason for that than implementing color_lerp() or anything_lerp(). We have generic functions for that, adding specific function for each case is just bloat into the API.

@DevMagicLord
Copy link
Author

DevMagicLord commented Sep 27, 2018

That's a good explanation.

Could those be in the docs ?

Yes you can, you simply have to change the look target. By basically putting your target as the same coordinates on the axis you want to restrict.

func _process(delta):
var target = $"../target".global_transform.origin
var target_transform = Transform().looking_at(target, Vector3(0,1,0))
global_transform = global_transform.interpolate_with(target_transform, 1 * delta)

@akien-mga
Copy link
Member

I agree that this should go in the docs as it's often requested, and though it's relatively simple as shown by @groud, it's not always trivial to come up with from scratch.

@godotengine/documentation any advice on where to put it?

@mhilbrunner mhilbrunner self-assigned this Sep 28, 2018
@mhilbrunner mhilbrunner reopened this Sep 28, 2018
@mhilbrunner mhilbrunner changed the title TurnTo (params) [DOCS] TurnTo Sep 28, 2018
@akien-mga akien-mga changed the title [DOCS] TurnTo [DOCS] Document simplest way to turn 3D node towards an axis with interpolation Sep 28, 2018
@DevMagicLord
Copy link
Author

Yes, it's one of the most used and requested features for 3D games.
It should be in the docs.

@DevMagicLord
Copy link
Author

About look_at, you can' t restrict two axis.

Yes you can, you simply have to change the look target. By basically putting your target as the same coordinates on the axis you want to restrict.

Thanks, it worked.

var lookPos = player.global_transform.origin
lookPos.y = global_transform.origin.y 
look_at(lookPos,Vector3(0,1,0))

Look At on Y axis is the most used , it could be added to the manual.

@StraToN
Copy link
Member

StraToN commented Oct 29, 2018

@akien-mga I have 2 places in docs to propose:

@DevMagicLord
Copy link
Author

The example would feet very well in "3D transform"
Or in a sub section named "How to"
https://docs.godotengine.org/en/3.1/tutorials/3d/using_transforms.html

@Calinou Calinou transferred this issue from godotengine/godot Dec 24, 2020
@Calinou Calinou changed the title [DOCS] Document simplest way to turn 3D node towards an axis with interpolation Document simplest way to turn 3D node towards an axis with interpolation Dec 24, 2020
@cbscribe
Copy link
Contributor

Closing as there's been no activity for some time and as per #3390, tutorials are being moved out of core docs. Here's one that covers this: http://kidscancode.org/godot_recipes/3d/rotate_interpolate/

Feel free to open a new issue if you feel the need is still there.

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

7 participants