Godot Version
3.6
Question
Hey guys,
I am trying to program this mechanic where I can push the enemy player. It’s something how a bull would fight. I just couldn’t figure out the collision and that “pushing” mechanic thing. This is the script, I know it is terrible but I really appreciate your help!
var mousepos:Vector2
var difference
var velocity
var speed = 0.05
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _input(event):
var direction = Vector3.ZERO
if event is InputEventMouseMotion:
direction.x += event.relative.x
direction.z += event.relative.y
velocity = move_and_slide(direction)
var fast = (abs(velocity.x)+abs(velocity.z))/2
for index in get_slide_count():
var collision := get_slide_collision(index)
var body := collision.collider
if body.name == "enemy" and fast >= 7:
print("Hit")
$"../enemy".direction.x += direction.x
$"../enemy".direction.z += direction.z
$"../enemy".move_and_slide($"../enemy".direction*0.1)
else:
print ("Weak")
fast = 0
#move_and_slide(velocity)
func _physics_process(delta):
if velocity != Vector3.ZERO:
rotation.y = lerp_angle(rotation.y, atan2(-velocity.x, -velocity.z), delta / speed)