KinematicBody Collision
I am trying to make 2 KinematicBodies collide and bounce of of each other. For some reason the script for the actual player works fine, but the dummy player doesn't work until I disable it's gravity and make it float in the air. Does anyone know how to fix this? Any help will be appreciated.
I am a Godot SuperNoob btw
Player script:
extends KinematicBody
var direction = Vector3()
var speed = 3000
var mousesens = 0.08
var canshoot = false
var canstop = false
var gravity = 0.5
var velocity = Vector3()
var acceleration = 1.25
var collision
var friction = 9
onready var camhead = $Camera
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
$ShootTimer.start()
$StopTimer.start()
func _input(event):
if event is InputEventMouseMotion:
rotate_y(deg2rad(-event.relative.x * mousesens))
camhead.rotate_x(deg2rad(-event.relative.y * mousesens))
camhead.rotation.x = clamp(camhead.rotation.x, deg2rad(-50), deg2rad(50))
func _physics_process(delta):
direction = Vector3()
if Input.is_action_pressed("stop") and canstop == true:
canstop = false
$ShootTimer.start()
velocity = Vector3()
if Input.is_action_just_pressed("forward") and canshoot == true:
direction -= transform.basis.z
$ShootTimer.start()
canshoot = false
if Input.is_action_just_pressed("backward") and canshoot == true:
direction += transform.basis.z
$ShootTimer.start()
canshoot = false
if Input.is_action_just_pressed("left") and canshoot == true:
direction -= transform.basis.x
$ShootTimer.start()
canshoot = false
if Input.is_action_just_pressed("right") and canshoot == true:
direction += transform.basis.x
$ShootTimer.start()
canshoot = false
direction = direction.normalized()
if not is_on_floor():
direction.y -= gravity * delta
for index in get_slide_count():
var collision = get_slide_collision(index)
if collision.collider.is_in_group("player"):
direction = collision.normal / friction
velocity = velocity.linear_interpolate(direction * speed, acceleration * delta)
velocity = move_and_slide(velocity, Vector3.UP,true,50,deg2rad(100),true)
func _on_ShootTimer_timeout():
canshoot = true
func _on_StopTimer_timeout():
canstop = true
Dummy script:
extends KinematicBody
var direction = Vector3()
var speed = 3000
var gravity = 0.5
var velocity = Vector3()
var acceleration = 1.25
var friction = 9
func _ready():
pass
func _input(event):
pass
func _physics_process(delta):
direction = Vector3()
direction = direction.normalized()
for index in get_slide_count():
var collision = get_slide_collision(index)
if collision.collider.is_in_group("player"):
direction = collision.normal / friction
print(collision.collider)
if not is_on_floor():
direction.y -= gravity * delta
velocity = velocity.linear_interpolate(direction * speed, acceleration * delta)
velocity = move_and_slide(velocity, Vector3.UP,true,50,deg2rad(45),true)