Untitled

mail@pastecode.io avatar
unknown
python
a year ago
775 B
6
Indexable
Never
func _physics_process(delta):
	#gravity
	direction.y += gravity_speed * delta
	
#	var theta=Vector2(1,0).angle_to(to_local(pivot)) * -1 # angle between local x_axis & pivot point vector 
#	var sin_theta=sin(theta)
#	var cos_theta=cos(theta)
#	direction.x= direction.x + direction.y*sin_theta*cos_theta - direction.x*cos_theta*cos_theta
#	direction.y= direction.y + direction.x*sin_theta*cos_theta - direction.y*sin_theta*sin_theta
	
	# simplified above to
	direction=direction.project(to_local(pivot).tangent())
	
	# fix for Error
	var err_magnitude=get_position().distance_to(pivot) - rod_length
	var err_vector=get_position().direction_to(pivot)
	direction += err_magnitude * err_vector
	
	direction=move_and_slide(direction,Vector2.UP)
	
	rod.points[1]=rod.to_local(pivot)