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

Path (3D) seems to make a wrong rotation #27137

Closed
rogeriodec opened this issue Mar 16, 2019 · 5 comments · Fixed by #60151
Closed

Path (3D) seems to make a wrong rotation #27137

rogeriodec opened this issue Mar 16, 2019 · 5 comments · Fixed by #60151

Comments

@rogeriodec
Copy link

Godot version:
3.1

OS/device including version:
Windows 10 x64

Issue description:
I did a Path / Pathfollow (by GdScript) with a form more or less equal to this (a capsule):
image

The coordinates in the code are:

	var p = $Path.curve
	# right curve
	p.add_point(Vector3(0, 0.35, 0), Vector3(0, 0, 0), Vector3(0, 0, 0))
	p.add_point(Vector3(0.35, 0, 0), Vector3(0, 0.35, 0), Vector3(0, -0.35, 0))
	p.add_point(Vector3(0, -0.35, 0), Vector3(0, 0, 0), Vector3(0, 0, 0))
	
	# left curve
	p.add_point(Vector3(-dist_eixos, -0.35, 0), Vector3(0, 0, 0), Vector3(0, 0, 0))
	p.add_point(Vector3(-dist_eixos - 0.35, 0, 0), Vector3(0, -0.35, 0), Vector3(0, 0.35, 0))
	p.add_point(Vector3(-dist_eixos, 0.35, 0), Vector3(0, 0, 0), Vector3(0, 0, 0))
	
	#close path
	p.add_point(Vector3(0, 0.35, 0), Vector3(0, 0, 0), Vector3(0, 0, 0))

I did a mesh like a tile to follow the Path. 0 rotation.
However, the mesh is following the Path with a sligth rotation.

Steps to reproduce:

Run the Scene on the attached project

Minimal reproduction project:
path.zip

@wombatstampede
Copy link
Contributor

I jumped on a similar issue and did my own code to follow the path. It is slightly different, as I limited the following and rotation to X/Z (so rotating around Y) and the object positions between two points according to its length. You also get any errors free. But perhaps it helps someone out until the fix is done and in a release.:

tool
extends Spatial

export(float,0.0,1.0,0.001) var offset_relative = 0.0 setget set_offset_relative
export(float) var object_length = 15.0

func _ready():
	doUpdate(offset_relative)

func set_offset_relative(newval):
	offset_relative=newval
	doUpdate(newval)

func doUpdate(newval):
	var p = get_parent()
	set_physics_process(false)
	if p is Path:
		var plen=p.curve.get_baked_length()
		var absOffs=fmod(plen*newval,plen)
		var offs1=max(absOffs-(object_length/2.0),0)
		var offs2=min(absOffs+(object_length/2.0),plen)
		var p1=p.curve.interpolate_baked(offs1)
		var p2=p.curve.interpolate_baked(offs2)
		var newpos=p1+((p2-p1)/2.0)
		transform.origin=Vector3(newpos.x,transform.origin.y,newpos.z)
		global_transform=global_transform.looking_at(p.global_transform.xform(Vector3(p2.x,transform.origin.y,p2.z)),Vector3(0,1,0))

@marcosn41
Copy link

Thanks for this code wombatstampede! Save my project! This bug stopped me for weeks. I only changed to affect Y too bacause this problem for me only appear when i change Y coord.

@KoBeWi
Copy link
Member

KoBeWi commented Oct 24, 2020

Still valid in 8718107
Although this might be an issue with the path.

@QbieShay
Copy link
Contributor

Still valid on 20/3/2021

simplescreenrecorder-2021-03-20_14.09.03.mp4

@fossegutten
Copy link
Contributor

Still valid in 4.0 alpha 1.
Also in my project it seems on a looped Curve3D the rotations get more and more wrong for each lap the PathFollow3D does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants