AKA, creating a rectangle the size of the texture. Set_pos(start_pos) # it did, so reset position to beginning, what's old is new again!Įssentially what you are doing here is creating a RectangleShape2D using the boundaries of each Sprite’s texture image. If(llide(get_transform(),box2,sprite2.get_transform())): #Now check to see if box1 at sprite1's pos collided with box2 and sprite2's position # values are relative to center, thus half width and heightīox1.set_extents(Vector2(self.get_texture().get_size().width/2,self.get_texture().get_size().height/2)) # set the boundaries of each RectangleShape2D to those of the texture making up our sprite Var sprite2 = get_node("/root/SceneRoot/Sprite 2") Let’s take a look at the script now: extends Sprite This script updates the position of the left sprite until a collision occurs, at which point it resets to the beginning and does it all over again. I then attached a script to the one on the left. It’s simply two sprite objects side by side. Let’s start with checking collisions between two objects, in this case, two different Sprite objects. You can watch the video here, or embedded below. So if you struggle to understand what I am talking about here, be sure to quickly check the video, it may have the answer. There is also a video of this tutorial and this might be one of those times, due to all of the motion in the results, that you may in fact want to refer to the video even if you prefer text based tutorials. This of course also includes handling collisions. Physics on the other hand simulates the movement and interaction of game objects based on physical properties. Collision Detection is simply detecting if two objects overlap. In this tutorial we are going to take a look at two key topics in Godot game development, Collision Detection and Physics Simulations.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |