Godot 3: Kinematic to Rigid Body Interaction

preview_player
Показать описание
A common question: how to handle interaction between a kinematic character and a rigid body.

Text version:

Рекомендации по теме
Комментарии
Автор

Fantastic topic. I absolutely loved the article on this and have already used this several times in my work.

GameEndeavor
Автор

Great! I applied this in 3D and it worked very well. Thanks!

juliosardinha
Автор

Damn dude, its when i look at videos like this that i realize i know too little about Godot, i din't even know you could check for what you are colliding, neither getting theyr information, thx for the video man, you help thousands of people and that's sick, you're really talented and i really respect people like you, thx again :)

rafaeu
Автор

I wondered how this worked for so long, thank you for this video!

LucyJong
Автор

That is really great help indeed! My kids have put a beach ball in there first level and it's a rigid body. It's great fun to interact with the ball but after a short time the ball is lost because it's pushed into the floor. We are gonna try the piece of code you provide so kindly.

susmiasyaefudin
Автор

This is a great tutorial, my custom physics engine for my game has broken several times because the rigidbodies kept going through the world

IronBrandon
Автор

Fiddling with the properties and PhysicsMaterialOverride of my RigidBodies resulted in unexpected behaviour and after some questioning of my very understanding of physics, while temporary descending into madness, I can now safely say:
Things make sense again.

Thank you!

copperbadge
Автор

Any idea why (with infinite inertial = false) that my player CAN push things around but only for a short duration thenevetyhing becomes immovable. Its like it starts with some inertia that dispates. Cant figure out where it comes from.

Ruptured_AU
Автор

Exactly what i needed. You're great, as always.

chepulis
Автор

Just what I was looking for! Thank you very much. This was a very informative and clear tutorial! :)

easyUB
Автор

For some reason, the apply_central_impulses were not in the auto-complete of the editor. I was damn confused.

sirgrem
Автор

Hi! thanks for this tutorial!
The zip file is no longer hosted on your page, could you reupload it?

deransartmatteo
Автор

I know this is old, but holy crap this helped so damn much. Thank you so much

HonsHon
Автор

Thanks so much, this didn't completely fix my issue, but it definitely got me moving in the right direction.

freya
Автор

This was a really good tutorial and very relaxing to watch, cheers

ARiverSystem
Автор

EDIT: NVM FIXED
the rigid body does not move but I can go on top of it.
my script

extends KinematicBody2D

export (int) var speed = 200
export (int) var jump_speed = -600
export (int) var gravity = 1000
export (float, 0, 1.0) var friction = 0.1
export (float, 0, 1.0) var acceleration = 0.25
export (int, 0, 200) var push = 100

var velocity = Vector2.ZERO

func get_input():
var dir = 0
if
dir += 1
if
dir -= 1
if dir != 0:
velocity.x = lerp(velocity.x, dir * speed, acceleration)
else:
velocity.x = lerp(velocity.x, 0, friction)

func _physics_process(delta):
get_input()
velocity.y += gravity * delta
velocity = move_and_slide(velocity, Vector2.UP,
false, 4, PI/4, false)
if
if is_on_floor():
velocity.y = jump_speed
for index in get_slide_count():
var collision = get_slide_collision(index)
if
* push)

toadyproductions
Автор

This only seems to work if the RigidBody is at rest or low velocity. In my case I have a bucket that's a KinematicBody2D and you have to catch eggs that are falling downwards, which are RigidBody2D. Setting infinite inertia to false only made things worse, the smallest impact catapults the eggs out to the moon. I tested what happens if the eggs are still and the bucket hits them, and then it works, but not if they fall into the bucket or they have high velocity. I also tried using much simpler collision shapes, just in case the complex shapes are the cause but it still happens with the simplest rectangular shapes. Not to mention the eggs also move the bucket around, which is not supposed to be happening. I want the eggs to have absolutely zero impact on the bucket, but I want the bucket to be able to carry the eggs around, and that only seems to work with infinite inertia, but then the eggs get stuck in the bucket's hitbox. Is there any solution at all to this? I mean this all seems so trivial, there must be something we can do?

Edit: I tried continuous detection too, doesn't work.

recarsion
Автор

it works fine when pushing one rigidbody but colliding with multiple bodies results in strange behavior like bodies or character accelerating too fast

outhander
Автор

this was exactly what i was hoping to achieve! great thanks!

AdventurersTavern
Автор

how could we add friction? so that when I stop pushing a box it doesn't keep sliding so much? I'm using godot 3.5 btw

mmorenopampin
welcome to shbcf.ru