Sprint #2.5 - Daily Scrum #07
Product: Tetris2P AI
Sprint Summary
Daily Objectives
- Learn more about and implement basic colliders for the physics engine
Notes
Let’s set up daily goals today: I’m at a cafe right now, and it might close soon lmao Where did I leave off from yesterday? I finished adding in the position anchors, adding canvas position and world position variables. When I want to do collision detection, I want to make sure I’m using the canvas positions instead of anchor positions. I’m putting off the right and scroll wheel clicks for now. When I want to make the ‘physics’ engine how do I want to test it and stuff?
A minimum viable example would be placing a player square on a floor, and then getting hit when it touches an enemy object. Before that, I can have the bouncing ball touch and settle on a different objects.
Should I introduce a physics layer? How would I describe what that is? It’s more of a list of objects in a physics space, and applying certain rules to the physics space? I think a good place to do a bit of research is check how you’d make a bouncing ball in unity2d.
Looking up tutorials on how to make physics objects in Unity2D.
Notes from: video:
Required Components:
- Transform Rect
- Position of object
- Sprite Renderer
- The ‘draw’ function
- Circle Collider 2D
- Physics material (defines friction and bounciness; aka: physics properties?)
- Defines physics properties
- Allows component to ‘participate’ in physics events but can’t ‘initiate’ them
- Doesn’t react to physics forces or gravity
- Physics material (defines friction and bounciness; aka: physics properties?)
- Rigidbody 2D
- Allows object to be affected by physical forces
- Forces include gravity
- Allows object to participate in physical events, like collision and triggers
- Unnecessary for static nonmoving items\
Colliders interact with other colliders! Having a collider lets you check for collisions with other colliders.
A rigid body adds ‘physics’ forces and updates to an object.
So colliders determine what happens on collision, but rigid bodies determine what happens on each update loop.
next video: video
- Can create a ‘layer collision matrix’ to determine what collider objects can collide with what
- Objects are in a ‘layer’, and the ‘layer collision matrix’ determines if objects in a ‘layer’ should collide with objects in a different layer
- Rigidbody2d.cast(direction, results, distance, contactFilter)
- Should pad the distance for protection? So you can’t pass inside another collider? Cast is used to check if you’d collide with another collider.
- Can use triggers or layer masks?
- They’re using the groundNormal to detect if a player is standing on something.
- When a player hits head along an object, change the y value to 0
- If a player hits a wall, change the x value to 0
- This is so you can stop movement only in the relevant direction
- Also change velocity to accommodate for loss of axis direction
Misc videos: brackeys
- Create ground check and ceiling check, to check if standing or under a ceiling
- Rigidbody objects DON’T OVERLAP as per the physics engine
- Collider objects CAN OVERLAP, and trigger collision functions
- Layers have a rendering order, maybe I should introduce a similar concept.
- Have to add objects to a layer in order to have their draw function called! :D
- Collider also prevents other objects from passing though?
https://answers.unity.com/questions/42558/whats-the-difference-between-a-rigid-body-and-a-co.html
- A Collider is the “physical form” of objects. There are several types of colliders, such as box shaped, sphere shaped, capsule shaped or even custom (mesh) shaped (and then some!).
- A Colliders’ responsibility is to aid collision detection in any way. It can be used for triggers, for physics or other uses.
- A Rigidbody is a representation of a rigid body in space. It is used by the physics engine to perform collision response and movement of objects.
- A Rigidbody makes use of a Collider to define its shape.
Having a boxCollider with the ‘isTrigger’ checkmarked, will have OnTriggerEnter, Stay, Exit. If you have the ‘isTrigger’ set to true, the collider will no longer behave as a physics object. sIC cOoL, mAkeS sEnSE.
So what’s on the to do now that I’ve figured it out at 3:08 am.
- Create a dictionary of Layers; with a Layer Collision Matrix
- The developer adds AABB objects to the layer
I have to decide whether or not to check for collisions before or after the update loop. Should I just add collision to an event list? Or should I actually have them trigger ‘onCollisionEnter’ and ‘onCollisionExit’ functions when they’re detected?
Now I have to figure out whether I want to add rigidbodies or not. Rigidbodies just add simulated ‘gravity’ and ‘friction’ to an object.
What are the types of things again?
- ColliderTriggers
- ColliderPhysics
- RigidBodies
RigidBodies and ColliderPhysics both cannot overlap, except gravity only applies to RigidBodies. ColliderPhysics object is mostly used for objects such as the ground or floating platforms. I think I should combine the two objects for my project, and the developer can write in their own physics update stuff. The basic rule is that ‘RigidBodies’ cannot overlap. If an object tries to overlap with another object, the movement is prevented. Gravity and forces can be simulated in the ‘update’ function of a game object. Should the developer be aware of these kind of things?
Note-ing down: the physics should be correct before the draw portion of the update loop. Maybe I should implement a cast function, for the developer to use. The cast function is used to check if moving an object into a certain position would be legal. So the developer would use the cast function to check if movement is legal. If not, adjust the new position or run a collision function. Since only one object is being checked at one time, I don’t think there’ll be any synchronization issues? AKA, two objects moving towards each other: first object moves into second object and runs collider function, and then second object runs into first object and runs a second collider function. Hmm, I guess that could be an issue. We can have the first object let the second object know a collider was already detected. This is getting weird because are we assuming any collisions are already detected before the update loop, or will collisions be detected during the updated loop.
Let’s redo the example. Player A checks if moving towards a monster will collide. Cast function returns yes, so Player A executes pseudo-on-collision function. On the same update loop, monster tries to move towards player, and detects the collision. In this case there’s work arounds, like the monster not checking for collisions. BUT, I think the Player A can add itself to the monster’s ‘handledCollisions’ list, for an update loop.
Casting Movements is a way to check for collisions before a movement.
BUT, for ColliderTriggers, I should figure out if I want them checked before the update loop or during the update loop.
Example:
checkCollisions return statement can be a list of collided objects + collision orientations.
Objectives Completed
- watched tutorial videos of how Unity provides physical object functionality and colliders for reference