Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | AliAdel |
I was trying to make a spiderman like game and when i tried to use the damped spring 2d joint it didn’t rotate the player like the PinJoint2D and i tried to make my own script but it’s not that good and that would be nice if someone helped me.
The script i made for it:
if Input.is_action_just_pressed("LMB"):
mouse_down = true
rot_weight = 0 #How smoothly the body look at the web position
#Stuff
elif Input.is_action_just_released("LMB"):
mouse_down = false
if linear_velocity.x < 0:
angular_velocity = 3 + linear_velocity.x / 350
elif linear_velocity.x > 0:
angular_velocity = -(3 + linear_velocity.x / 350)
#More stuff
if mouse_down:
#look at web position smoothly
var pos = web_position.global_position - global_position
var angle = pos.angle()
var rot = global_rotation
global_rotation = lerp_angle(rot,angle,rot_weight)
if rot_weight < 1:
rot_weight += 0.005