Godot 3: Kinematic to Rigid Body Interaction

Поділитися
Вставка
  • Опубліковано 7 сер 2019
  • A common question: how to handle interaction between a kinematic character and a rigid body.
    Text version:
    kidscancode.org/godot_recipes/...
    Support me on Patreon: / kidscancode

КОМЕНТАРІ • 120

  • @GameEndeavor
    @GameEndeavor 5 років тому +59

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

    • @Kidscancode
      @Kidscancode  5 років тому +5

      Glad it helped!

    • @Jonathan.R.Pereira
      @Jonathan.R.Pereira 3 роки тому

      @@Kidscancode Hi there, I'm unable to move objects.

    • @Jonathan.R.Pereira
      @Jonathan.R.Pereira 3 роки тому

      @@Kidscancode This is the code I'm using, what am I doing wrong? :
      extends KinematicBody2D
      var motion = Vector2()
      const UP = Vector2(0, -1)
      const GRAVITY = 20
      const ACCELERATION = 50
      const MAX_SPEED = 200
      const JUMP_HEIGHT = -550
      export (int, 0, 200) var inertia = 100
      func get_input():
      var friction = false
      if Input.is_action_pressed("Player_Left"):
      motion.x = max(motion.x-ACCELERATION, -MAX_SPEED)
      elif Input.is_action_pressed("Player_Right"):
      motion.x = min(motion.x+ACCELERATION, MAX_SPEED)
      else:
      friction = true

      if is_on_floor():
      if Input.is_action_just_pressed("Player_Jump"):
      motion.y = JUMP_HEIGHT
      if friction == true:
      motion.x = lerp(motion.x, 0, 0.2)
      else:
      if friction == true:
      motion.x = lerp(motion.x, 0, 0.05)
      func _physics_process(delta):

      #Calling the Input Functions
      get_input()
      motion.y += GRAVITY
      motion = move_and_slide(motion, Vector2.UP, false, 4, PI/4, false)
      for index in get_slide_count():
      var collision = get_slide_collision(index)
      if collision.collider.is_in_group("bodies"):
      collision.collider.apply_central_impulse(-collision.normal * inertia)

  • @rafaeu292
    @rafaeu292 3 роки тому

    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 :)

  • @LucyJong
    @LucyJong 5 років тому +6

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

  • @easyU2B
    @easyU2B 4 роки тому +3

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

  • @freya9107
    @freya9107 3 роки тому

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

  • @IronBrandon22
    @IronBrandon22 4 роки тому +3

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

  • @chepulis
    @chepulis 4 роки тому +4

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

  • @juliosardinha
    @juliosardinha 3 роки тому +1

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

  • @copperbadge1
    @copperbadge1 4 роки тому

    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!

  • @ARiverSystem
    @ARiverSystem 4 роки тому +1

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

  • @susmiasyaefudin5000
    @susmiasyaefudin5000 5 років тому +4

    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.

  • @AdventurersTavern
    @AdventurersTavern 4 роки тому +1

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

  • @HonsHon
    @HonsHon 3 роки тому

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

  • @ianmclean9382
    @ianmclean9382 Рік тому

    still one of the best tutorials

  • @guru332
    @guru332 4 роки тому

    What a great video!! So well explained. Thanks so much!

    • @Kidscancode
      @Kidscancode  4 роки тому

      Thank you - glad you found it helpful.

  • @potatopen5282
    @potatopen5282 4 роки тому +1

    Hey man! Love your work! I wanted to ask, can you make a tutorial on how to implement dialogue in godot? How to branch out choices, and how to call a function within the dialogue, you know, stuff like that?

  • @jamesmunroe6558
    @jamesmunroe6558 Рік тому

    Extremely helpful. Thanks!

  • @hidemat5141
    @hidemat5141 5 років тому

    I was just having this issue. Well time post thanks.

  • @SoloCodeNet
    @SoloCodeNet 5 років тому

    excellent vidéo ! simple and precise !

  • @darkexior
    @darkexior 4 роки тому

    amazing video, thank you!

  • @arlleylp2308
    @arlleylp2308 4 роки тому

    that's all i need, thank you very much

  • @MrHarumakiSensei
    @MrHarumakiSensei 3 роки тому

    I changed apply_central_impulse to apply_impulse so my rigidbodies would spin if you hit them on an edge:
    collision.collider.apply_impulse(collision.position, (-collision.normal * inertia))
    ...but I get weird behaviour where SOMETIMES the impulse is applied correctly, but sometimes the impulse is in the opposite direction. I.e. the rigidbody moves back towards the kinematic body that hit it.
    Edit: it turns out 'sometimes' is whenever a contact is reported as a little red square when 'visible collision shapes' is turned on under the debug menu.

  • @AosaLetsPlays
    @AosaLetsPlays 2 роки тому

    Great video. Works perfectly. One question I have: how can you get this working for point2d nodes? I'm able to set up point2d nodes and they interact with rigid bodies as expected. By when a kinematic rigid body interacts with them they don't react.

  • @MrDaduh59
    @MrDaduh59 5 років тому +1

    Fantastic tip!

  • @ahmadtakhimi6839
    @ahmadtakhimi6839 5 років тому +1

    Can you please do an example or tutorial for 3d ragdoll ? Thanks

  • @Yuhara_rev
    @Yuhara_rev 3 роки тому

    Thank you so much, that was very useful

  • @McHumaty
    @McHumaty 4 роки тому

    Very nice!! ...and if I want to pull an object? How could this be done?!

  • @revolentertainment2411
    @revolentertainment2411 3 роки тому

    great tutorial! i have a question tho, when lets say i hit a ball(rigid2d) with my kinematic and the ball bounces and hit me back,my kinematic moves a bit,why is that happen? thank you.

  • @jvstAsYouAre
    @jvstAsYouAre 4 роки тому

    @KidsCanCode For some reason after some time where I have been pushing around my cube it almost seems "fall into place" so that I can no longer move it around. I'm working in 3D and it is usually when I get the cube right up against a corner or if I jump on it. Any ideas why that would happen?

  • @jared0801
    @jared0801 4 роки тому

    Any idea why my rigidbody2d always falls through tiles with one-way collision?

  • @mmorenopampin
    @mmorenopampin Рік тому

    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

  • @Ruptured_AU
    @Ruptured_AU 3 роки тому +1

    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.

  • @deransartmatteo4774
    @deransartmatteo4774 Рік тому

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

  • @ryscale4014
    @ryscale4014 Рік тому

    How does it work with 3D kinematic bodies and vehiclebodies?

  • @recarsion
    @recarsion 3 роки тому

    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.

  • @Vincent-kl9jy
    @Vincent-kl9jy 3 роки тому

    this was great, but how do you make this work over multiplayer?

  • @chomiyeons
    @chomiyeons Рік тому

    is there anyway for this to happen in 3d? i tried doing what u did in 3d but im having glitches

  • @baconator2391
    @baconator2391 2 роки тому

    im having problems in 3d where the rigid body starts to move but then it just stops like it has lots of friction

  • @sirgrem2988
    @sirgrem2988 3 роки тому +1

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

  • @AnKlMa
    @AnKlMa Рік тому

    How can this be solved in Godot 4?

  • @DanziG523
    @DanziG523 5 років тому

    Thank you!

  • @macgyver7457
    @macgyver7457 5 років тому +1

    thank you

  • @OsamaBombLyrics
    @OsamaBombLyrics 4 роки тому

    Hello, first off this and all the other videos have helped immensely. I am working on a top down game and have put 'false' for the infinite inertia in the move and slide method. My player interaction with the rigid bodies works great except for when I push from the top. When my Player collides with the rigid body from the north side moving down it seems like all these other vectors are being applied. I have gone into project settings and turned gravity off everywhere there is an option too. I would like to understand why this is happening. If anyone can help I would greatly appreciate it.

    • @OsamaBombLyrics
      @OsamaBombLyrics 4 роки тому

      Okay so I went into the script for my RigidBody and created the integrate_forces method. From there I just clamped the linear_velocity. After that I just set the mode to Character to keep it simple and my problem seems to be solved.

  • @toadyproductions2106
    @toadyproductions2106 3 роки тому +1

    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 Input.is_action_pressed("ui_right"):
    dir += 1
    if Input.is_action_pressed("ui_left"):
    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 Input.is_action_just_pressed("jump"):
    if is_on_floor():
    velocity.y = jump_speed
    for index in get_slide_count():
    var collision = get_slide_collision(index)
    if collision.collider.is_in_group("bodies"):
    collision.collider.apply_central_impulse(-collision.normal * push)

    • @ssenna207
      @ssenna207 3 роки тому +2

      how did u fixed it?

    • @toskunchik
      @toskunchik 2 роки тому

      how did u fixed it

    • @toskunchik
      @toskunchik 2 роки тому

      @@ssenna207 do you know how to fix this

    • @toadyproductions2106
      @toadyproductions2106 2 роки тому +1

      @@toskunchik I don't really remember how fixed it anymore also it maybe because your using a different version of Godot

  • @Gloria-mq3lu
    @Gloria-mq3lu Рік тому

    invalid call. nonexistent function 'apply_central_impulse' in base Rigidbody

  • @josephastrahan6403
    @josephastrahan6403 4 роки тому

    For those wanting to know how to do this in 3D, the code for the for loop looks like this, for index in get_slide_count():
    var collision : KinematicCollision = get_slide_collision(index)
    var obj = collision.get_collider()
    if obj.is_in_group("bodies"):
    print(obj)
    collision.collider.apply_central_impulse(Vector3(inertia,0,0))
    Only I don't have the vector3 correct for applying the impulse.

    • @Kidscancode
      @Kidscancode  4 роки тому

      You would still use the collision normal to align the impulse.

    • @josephastrahan6403
      @josephastrahan6403 4 роки тому

      okay I figured it out, for index in get_slide_count():
      var collision : KinematicCollision = get_slide_collision(index)
      var obj = collision.get_collider()
      if obj.is_in_group("bodies"):
      collision.collider.apply_central_impulse(Vector3(inertia * -collision.normal.x,inertia * -collision.normal.y,inertia * -collision.normal.z))

    • @Kidscancode
      @Kidscancode  4 роки тому +1

      Or just
      collision.collider.apply_central_impulse(-collision.normal * inertia)
      If you need some help on working with vectors, there's a really good doc here:
      docs.godotengine.org/en/latest/tutorials/math/vector_math.html

    • @eyeemotion1426
      @eyeemotion1426 4 роки тому

      Where is the "index" coming from? I get an error that index isn't declared in the current scope.
      I'm trying to get an object "fly off" when the car hits it. Thought that making the object a rigidbody would already make it interactable. There are so few tutorials about this (for Godot in 3D) or only partial information, it really gets annoying not being able to do things that should be straightforward.

  • @majorbarnulf2608
    @majorbarnulf2608 3 роки тому +1

    hey, thanks a lot

  • @harrylbonyoutube6981
    @harrylbonyoutube6981 5 років тому

    These videos have been a great help as I try to learn Godot! I have a question that isn't related to the video however. I'm working on creating a 2D game, but for stylistic purposes, putting it in a 3D environment. I want my character's arm to point at the cursor, but the easy way of doing that in 2D doesn't work in 3D. I've tried to figure it out myself, and it seems the answer has to do with raycasting, and folks have some code snippets I could grab, but I just can't wrap my head around it. Any chance of doing a video on finding the cursor location in a 3D space and getting a 3d object to look at it? Keep up the good work.

  • @vihn78
    @vihn78 3 роки тому

    Hello, nice tutorial. Would you mind getting even more deep on this topic, like for example how to hold a rigid body, making it follow the kinematic body, and then how to hit it, applaying force, like for example a soccer player getting the ball, dribling with it without losing it and then being able to kick the ball in a desired direction?

    • @Kidscancode
      @Kidscancode  3 роки тому

      This might help you get started: kidscancode.org/godot_recipes/physics/rigidbody_drag_drop/

  • @markolazic6352
    @markolazic6352 4 роки тому

    Great tut, can you give me some advice on doing this in 3d because i still cant jump on object without it slipping through floor??

    • @Kidscancode
      @Kidscancode  4 роки тому

      It should work the same. Maybe you're applying too much downward force, so the rigid body sees the kinematic as really "heavy". Maybe there's a problem with your collision shapes, or the thickness of your floor. You'll need to experiment on your particular setup.

    • @markolazic6352
      @markolazic6352 4 роки тому

      @@Kidscancode I was just checking all the things you mentioned and I had another vector for falling and i edited it too, so now it works. Thank you so much! :-)

  • @upyours2707
    @upyours2707 5 років тому

    thanks!

  • @DenerWitt
    @DenerWitt 5 років тому +2

    I really wish physics were easier to mess with in any engine
    Always had a hard time with them

  • @abhilashpawar1875
    @abhilashpawar1875 4 роки тому

    Hey, my script isn't working I cant push the objects although the script is the same! pls help!

    •  4 роки тому +1

      I guess you forgot the add the rigidbody to the a group. If you select the rigidbody than you will find the groups menu in the Node tab. I hope this was your problem.

  • @ImraneDev
    @ImraneDev Рік тому

    thanks

  • @efimov90
    @efimov90 4 роки тому +1

    Is there some way to detect collision of 2 static bodies? By some function maybe? I try to find something about this for 2 days along, but can't find anything usable.

    • @Kidscancode
      @Kidscancode  4 роки тому

      Static bodies by definition don't move, so they can't collide. They don't detect collisions because the purpose of them is to be lightweight, non-moving objects with no functionality other than to provide a body *other* objects can collide with.

    • @efimov90
      @efimov90 4 роки тому

      @@Kidscancode sure, in stage of gameplay it's normal, but i think may it be some way to play around this and detect somehow collision of 2 static body or they collision shapes manualy by some function? I don't want they can move, only detects if they intersect each other. Basicaly i trying to make some level generation by placing modelled rooms, but i stucked at moment when they placed in other rooms.

    • @Kidscancode
      @Kidscancode  4 роки тому

      @@efimov90 Static bodies don't detect collisions.

    • @efimov90
      @efimov90 4 роки тому

      @@Kidscancode sure, but i found solution: there are class "PhysicsDirectSpaceState" with methods collide_shape and intersect_shape which accepts "PhysicsShapeQueryParameters" which accepts shape from CollisionShape (not sure, but only convex). Anyway right now i can't use it, output is different from i expected, so i need to figure out what exact goes wrong. One problem is that it detect collision with own static body, but it's not big problem, second problem is wrong collision detection. I make a test scene where i try to intersect cube and prism, suddenly Query result show collision with cube where i dont expect it, but if move prism away - detection stops (only own Static body left).

    • @efimov90
      @efimov90 4 роки тому

      @@Kidscancode i fix a problem with wrong position - i just use get_world at mesh (because i see it earlier somewhere), but needed use just get_world as get_tree - alone

  • @linasjaniques
    @linasjaniques 2 роки тому

    NICE! 2022 and still helping, but I have a bouncing ball and the faster I am when I hit it, the less it will bounce. Can't figure why

    • @linasjaniques
      @linasjaniques 2 роки тому

      So... If I'm not jumping and the ball falls on my head, the collision.normal.y returns 1, but if I AM jumping, it returns less than 1... That's why just multiplying it by the inertia, it will return a lower value when there's player movement at the time of the collision.

  • @candle-likeghost9523
    @candle-likeghost9523 4 роки тому +2

    I found an issue here, when you try to stand on top of the rigidbodies, the kinematicbody is going to shake like hell. And if the rigidbody is on the kinematicbody, you cannot jump...

    • @tuxinal5661
      @tuxinal5661 4 роки тому

      The reason that you cannot jump is that you are not standing on the ground you are standing on the rigid body which will not trigger the is_on_floor function

  • @sadiewinterlord6908
    @sadiewinterlord6908 3 роки тому

    Help, I get this error:
    The method "get_input" isn't declared in the current class

    • @benvella1728
      @benvella1728 3 роки тому

      it's just a function he made containing the usual "if Input.get_action_pressed("game_left") direction = Vector2.LEFT" stuff. He did that to clean up code from user's controls and separate it from physics processes

  • @winhtetlu4069
    @winhtetlu4069 4 роки тому +1

    is there any way to make the block to stop rotating?? plz help

    • @Kidscancode
      @Kidscancode  4 роки тому +1

      Rigid bodies can be set to "character" mode, which prevents them from rotating.

    • @winhtetlu4069
      @winhtetlu4069 4 роки тому

      @@Kidscancode thank you sir

    • @winhtetlu4069
      @winhtetlu4069 4 роки тому

      @@Kidscancode I have tried changing to "character mode" ,but the block move to certain distance when pushed then get stuck at point.

  • @eirikb3463
    @eirikb3463 3 роки тому +2

    I wish I knew what groups were before I watched this tutorial.

  • @NgaeGameStudio
    @NgaeGameStudio 4 роки тому

    Thanks

  • @outhander3941
    @outhander3941 9 місяців тому

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

  • @nicowagner8655
    @nicowagner8655 3 роки тому +1

    Mine didnt work until i gave the "top_on_slope" an extra false. no idea why but hey.

    • @ssenna207
      @ssenna207 3 роки тому

      where did u put it?

  • @Sam01951
    @Sam01951 4 роки тому +1

    Nice tutorial, but my player doesn't move when applying this script.

    • @Kidscancode
      @Kidscancode  4 роки тому +1

      Check your code again, you need to find what you did wrong.

    • @Sam01951
      @Sam01951 4 роки тому

      @@Kidscancode Thanks.

  • @ali32bit42
    @ali32bit42 2 роки тому +1

    i like the tip about infinite inertia but the solution is a bit too basic for more advanced games designs. for more complex movement styles where max velocity can vairy alot between actions it might not work or be really inacccurate, fast moving characters wont have enough force and slow moving ones might have too much. what i would do it keep track of the velocity which is possible by comparing the last locaton with the current location each frame using delta time as the T (you can use the velocity for move_and_slide function too but this might help if you calculate velocity in a strange manner). then use the velocity to calculate a more accurate innertia for the kinematic body which will also use a "mass" number to be more realistic. after that i would not use central impulse to add force to the rigid body and instead apply the impulse at the collision point which is more accurate and will ensure colliding with a corner for example rotates the boxes more accurately . i would also try to take some physics data from the rigid body objects themselves to ensure my kinematic body can also react to colliding with other objects. as sometimes godot does not apply rigid body collisions in an accurate manner which is partially causing the whole collision problem since rigid body objects cant "fight back" the kinematic body. overall the best solution for this problem is a bit more complex but its what you need to do in order to have the most perfect system.

    • @christiansktt6903
      @christiansktt6903 2 роки тому

      Hi Ali, seems like you know what your taslking about, I see the same issues and are looking for an example done the right way - No glitching. I'm not a programmer, so don't know how to program it, but I need it for a game i'm thinking of. Would you be able to help?

    • @ali32bit42
      @ali32bit42 2 роки тому

      @@christiansktt6903 hi . i recommand doing some research on the real life physics of inertia and the formulas involved. look for a formula that can convert velocity and mass to inertia for impact. you can use the get_last_slide_collision() function to get data for which objects you have collided with. then you must get the velocity and point of impact for each object that you have collided with and then after that you must get the nodes that you have collided with and store them in an array then use a "for each" loop to quickly check for rigid body objects in the array . then for each rigid body in the collision array you must calculate the correct innertia using the velocity and mass of your kinematic body then send a signal to the rigid body object and trigger their _apply_impulse() function with the force of inertia and location of the impact for the function input. sorry if its confusing . the process is a bit complicated

    • @dmr12jmy
      @dmr12jmy Рік тому

      That's a great comment here. Do you have any suggestions where I can learn about solutions to the rigid bodies "fighting back" the kinematic bodies? I see this issue a lot, especially with solid bodies, which rotate. Thanks

    • @ali32bit42
      @ali32bit42 Рік тому

      @@dmr12jmy i have been researching this myself. the subject is a little heavy with math but if you look up something like "rigid body collision response" you will find a bunch of articles that show how to do it . there was also newtons law of restitution which if you understand well you can implement yourself. i dont have the link but a document from chris hecker has more info about it

  • @SimpleTrax
    @SimpleTrax 3 роки тому +3

    Compared to other engines, this still seem glitchy in my opinion. I love godot, free and easy to use, but its physics gives me headaches sometimes. Better off writing a physics simulation in 2D. I also noticed that when I push one rigidbody and then 2 rigidbodies, their combined mass remains the same as if I moved just one rigidbidy.

    • @ali32bit42
      @ali32bit42 2 роки тому +1

      its because the "solution " is not very effective. what he should have done is apply some more code to calculate realistic innertia instead of having a static one. and make sure the kinematic body can also retrive innertia from rigid body objects so it does not stand still when something hits it at a high velocity. also the impulse is applied at the center which is flat out wrong. it should be applied at the collision point not the center of the rigid body object.

    • @christiansktt6903
      @christiansktt6903 2 роки тому

      ​@@ali32bit42 Hi Ali, seems like you know what your taslking about, I see the same glitchy issues and are looking for an example done the right way. I'm not a programmer, so don't know how to program it, but I need it for a game i'm thinking of. Would you be able to help?

  • @kirkula
    @kirkula 4 роки тому +1

    oh my friggin jeeeeeez...I've spent the last few days trying to find out why my space ship will move my darn asteroids around like they're nothing, but everything I tried I couldn't figure out why I wasn't detecting a collision the other way around...all I needed to do was add a ", false" aaarrrgghh!! I'm glad I finally found this, but holy crap that was staring me in the face this WHOLE time too hahaha, I was ike "nahhh, I'll leave the infinite inertia boolean set to false, I don't think THAT'S the problem, it's not even showing a collision!" oh my f'n g....wow...ok...steam let loose....rant over...I'm very thankful I found this video, my google-fu failed me immensely on this one.

    • @kirkula
      @kirkula 4 роки тому

      oops, "...boolean set to *true" is what I meant to say

    • @kirkula
      @kirkula 4 роки тому

      oh wow, now looking through the docs I see why I missed it. I'm using move_and_collide, which in the docs doesn't give any info about infinite inertia. I didn't look at the arguments for move_and_slide being I wasn't using that....and THAT'S where infinite inertia is explained in the docs. a "see 'infinite inertia in move_and_slide" would have been nice to see so I didn't miss that...grr

  • @Ufol
    @Ufol 5 років тому

    The following link doesn't work: "It’s assumed that you have at least some general programming experience. If you’re completely new to programming, click HERE for tips on how to get started."

  • @hgsp137
    @hgsp137 2 роки тому

    Actually like the default physics.. the game should react with objects a little like a game and a little like real life

  • @cinomontague
    @cinomontague 4 роки тому +4

    You have comments enabled which means according to UA-cam this is in fact not for kids.

  • @Ihavetoreturnsomevideotapes
    @Ihavetoreturnsomevideotapes 4 роки тому

    from reddit

  • @tato6418
    @tato6418 3 роки тому +2

    Thanks for this fantastic tip, its a (literal) game changer.
    I used it on my top down game and it works wonders, but i discovered it doesnt "spin" the object as it normally should, so after some (a ton) trial and error, i came up with this bit of code to solve that: (Just add it after the "apply_central_impulse" bit)
    var spin

    if collision.normal.y < 0 and abs(collision.normal.y) > abs(collision.normal.x):
    spin = -(collision.collider.get_global_position().x - get_global_position().x)

    elif collision.normal.y > 0 and abs(collision.normal.y) > abs(collision.normal.x):
    spin = collision.collider.get_global_position().x - get_global_position().x

    elif collision.normal.x < 0 and abs(collision.normal.x) > abs(collision.normal.y):
    spin = -(get_global_position().y - collision.collider.get_global_position().y)

    elif collision.normal.x > 0 and abs(collision.normal.x) > abs(collision.normal.y):
    spin = get_global_position().y - collision.collider.get_global_position().y

    collision.collider.apply_torque_impulse(spin)
    EDIT: Nevermind, this "works" but breaks as soon at the body completes a half rotation, i'll leave it anyways in case someone wants to continue or i come up with a solution

    • @ali32bit42
      @ali32bit42 2 роки тому

      the code made a mistake here. central impulse is not effective for this problem. use apply_impulse() instead. you can take the exact collision point for the rigid body and kinematic body and use it like this _apply_impulse(collision_location,innertia * collision_normal)