3D tutorial with brownian-ish motion enemies
This commit is contained in:
@@ -2,7 +2,8 @@ extends CharacterBody3D
|
||||
|
||||
@export var speed = 14
|
||||
@export var fall_acc = 75
|
||||
@export var jump_impulse = 40
|
||||
@export var jump_impulse = 50
|
||||
@export var bounce_impulse = 40
|
||||
|
||||
var target_vel = Vector3.ZERO
|
||||
|
||||
@@ -35,5 +36,22 @@ func _physics_process(delta: float) -> void:
|
||||
if is_on_floor() and Input.is_action_just_pressed("jump"):
|
||||
target_vel.y = jump_impulse
|
||||
|
||||
# Iterate through all collisions that occurred this frame
|
||||
for index in range(get_slide_collision_count()):
|
||||
var collision = get_slide_collision(index)
|
||||
|
||||
# Avoid calling collision again after deleting
|
||||
if collision.get_collider() == null:
|
||||
continue
|
||||
|
||||
if collision.get_collider().is_in_group("mob"):
|
||||
var mob = collision.get_collider()
|
||||
# hitting it from above.
|
||||
if Vector3.UP.dot(collision.get_normal()) > 0.1:
|
||||
mob.squash()
|
||||
if !is_on_floor(): # TODO: This does not seem to work here
|
||||
target_vel.y = bounce_impulse
|
||||
break
|
||||
|
||||
velocity = target_vel
|
||||
move_and_slide()
|
||||
|
||||
Reference in New Issue
Block a user