Unity3D Physics - Rigidbodies, Colliders, Triggers
Вставка
- Опубліковано 29 лис 2024
- Check out the Course: bit.ly/3i7lLtH
-------
We'll learn about Unity3D physics for beginners, everything from rigidbodies and moving objects around, to bouncing and sliding.
I'll show how to use triggers and collisions / colliders to interact with your game in code. We'll use OnTriggerEnter and OnCollisionEnter in some example physics scenarios and use physics materials to make things bouncy.
More Info: unity3d.colleg...
Join the Group: unity3d.group
Patreon: patreon/unity3dcollege
I just wanted to say "Thanks a lot, Jason". I have been doing Unity game development as professional game developer for 5 years now and your videos even about the basic stuff still help me improve a lot. Please, keep up the good work.
i love how after you explain stuff 100 people already tried to explain me, i get it. all these people are too stuck in their current knowledge about the engine and scripting. while you can easly re-live your newbie days and explain if you are explaining it to passed you. and thats a skill to admire. well done sir
Even though I've been using Unity for 2 years now, this helps me improve alot
"We should be able to watch. Our ball. Fall."
"Let's hit play"
*Ball falls*
*Blep*
._.
*Thunderous applause*
"I want my ball to be bouncy."
Ummmm...... okay. But keep in mind that testing may prove painful...
Made my night
@@TheOneTaboo I am James, maker of nights :3
thanks for this: I was going nuts tilting planes and not having objects fall off them and couldn't figure out what was going on. This video was really helpful and helped me understand Unity physics - my game might even work now :)
I often see questions from people about why their characters are jittering when on the ground, or why triggers do not register when objects pass through, and I usually find in their code that they are moving the objects or characters with Transform.Translate which effectively bypasses the physics system with teleportation. They often think that as long as they do these types of movements in FixedUpdate, then it should not be an issue. Too often I see coders spending lots of time trying to recreate systems that the engine already does very well. The gravity system is a large source of confusion for newer coders, in this regard.
True! Do you have more tips so we can learn too? let me contact you on twitter or instagram if you got a list please. I often find myself confused as to what movement systems to use like translate or rb.vel forward and what not
Great video, very thorough.
26:55 In my limited experience I've found Force amounts are in the 100s, Rotation are in the 10s, and Movement are in the 1s. I was using the same value for rotation and movement speeds and spent hours trying to figure out why my thing wasn't rotating properly ... its was, just not very fast at all. Once I bumped that up it worked fine.
I know the basics of these but there were still quite a good things that I got from this. And that about swapping OnCollisionEnter with OnTriggerEnter, oh man, been there done that several times even in my limited experience with Unity. Good to know it keeps happening.
Knew about most of those, but it's nice having a video explaining all the stuff, good job.
Even though I've been using Unity for a full week this has still helped me tremendously :D But seriously, it's videos like this that make all the difference, thank you!
Thank you for the tutorial, this really got me. keep making other tutorials to help those who are still beginners and need knowledge in using unity like me XD
All we want to say is "Thank you, Jason." as this is an alternative to the source engine in our eyes.
And we might actually compare it to Source, Source 2, Unreal Engine Chaos, and definitely not ROBLOX, as it's just a garbage game engine with a blocky art style on a $5 budget.
I literally am doing a lab due Monday on this subject as i got your notification. This helps alot!
Liked keyboard shortcut, then you started showing off Rider IDE Shortcuts. Lovely. As always, thanks for sharing the insights and things we might find useful :)
Finally, now I understood what was the problem in my game
Excellent very Helpful.
Life would be a lot simpler without any Physics
Nice video again Jason. I like that you have a good mix of beginner all the way through to advanced videos (something for everyone).
I think something important to note that changed in 2019.3 due to an NVIDIA PhysX update is that trigger vs trigger colliders do not throw trigger callbacks to each other anymore. Other than that, great tutorial :) good job!
Thank you for pointing that out. I am curious how other people will solve this issue. I have my ideas, but, I am not sure if it is correct.
@@SteveTheExploiter a child game object that isn't is trigger on a layer that can only collide with the istrigger layer
@@Spherous That's how I've been doing it. Great!
Very simple helpful and straight to the point.
Thanks! This is a good introduction to all the physics stuff I plan on learning.
16:35 Trigger vs Collisions
Excellent tutorial sir.. I am following all your videos. Thank you very much.
Loved the CTRL+SHIFT+F Shortcut for moving to Camera position shortcut, thanks. I'm here to learn more about using Physics and worried about physics and performance if I'm doing things wrong. Love your content. Hoping to delve more deeply into the massive world of "Destruction". Starting with C# Algorithms looping through mesh verts... Slooooow. Maybe through Voxels and on to Geometry Shaders.
Thank you so much!! I have been struggling with this things since i got into Unity, you really helped me a lot
Nice tutorial about basics of physics system
Very well explained. Thanks!
France this video is awesome.
"Share the video, it helps more than anything else you can do"
Wow... you really motivate people to do nothing else
Hi Jason,
Could you please make a video on PhysX limitations and best practices to avoid strange physics behaviour in Unity?
I'm especially interested in the effects of the PhysX limitations on Unity joints. There is a lot of issues related to joints acting strange due to PhysX not being able to handle heavy objects with children connected using joints.
Best regards
even though i just downloaded Unity, this tutorial helped bunches!
Really nice video! Congrats!
I've learned alot from this video! Thanks!
Thank you for showing us things that work, a refreshing change. Good job Jason, Merry Xmas and a Happy 2021 🎅🎄🌟✨🔔⛄️👏👏👏
AMAZING
Thanks for another great video! You are the man!
Thanks for the good explanation. It helps a lot.
잘 보고 가용~~~ ㅎㅎㅎ
Very helpful, thanks!
Thank you very much for your efforts and awesome tutorial.
you brought me back to the counter strike days when you said "God Mode" lol, classic
great vid, thanks
Thank You!
In the tile script. Where did you bind the A & D key in the script for the floor?
BTW, great tutorial. 👍
by default Input.GetAxis uses WASD, so the Input.GetAxis("Horizontal") automatically returns -1 or 1 with A & D
I just started unity and it is very confusing for me, but this video help with these stuff,Thanks
super helpful thanks a lot
Thank your very much for your Tutorial.
thanks for this video it is really awesome
Hi Jason, massive thank you for these kind of videos, they are a massive help when getting my head around the engine. It's actually reminded me of a question that's been bugging me for a while. I'm trying to create a 2.5D type platformer but having a real problem getting my head around locking the movement to only two axis with the correct kind of physics to allow proper collisions with platforms etc. Can you suggest any good resources?
(also, I agree with the comment about your shirt and your chair. You look like a floating head!).
Good video.
Thank you
So the Rigidbody tells the object how to move, and the collider defines the physical boundary of the object
subscribed
So good
I see Jesse Schell's book of lenses in background :)
Thank you sir
Is there tutorial on how to push objects around the scene with players rigid body. Also need one to interact with virtual computer (switch from player camera to static on screen and back). TY
Hey there, how would you face the following problem :
You have a sphere which represent a tennis ball
You want the physic of the ball to be pretty realistic without having to implement complex laws of physics.
Why did super collider go on + off recently?
Many thx for this tutorial, Jason. I am very new, and this helped me a lot. I mean, a lot.
That being said, I was trying to use this ChangeColorOnCollision script to have a surface (the same cube you used in the examples) change color when Ellen contacted it (ran it into it, or jumped on it). The player "Ellen" I refer to is the character in the Unity 3D game kit. And it does not work. I tried adding a rigidbody to Ellen (had to make her kinematic/else fall through floor) and a mesh collider, but still no avail.
Also, I'm not sure if this is part of an update, from 2019.3 to 2019.3.6, which I am using, or maybe you forgot, but I had to change the "layer" of the gameObjects to "collider" for any of it to work. or, Did I miss something there?
If you have time, could you please explain to me how to make the character cause this changeColor via collision?
Many thx,
Wannabee Dev 101
I don't understand why the balls jump higher and higher with a bounciness of 1 and no friction when the bounce combine is on maximum and bounciness drops quickly when bounce combine is on average. I just want an eternally bouncy ball, not one that bounces out of control. What do I need to do?
So I set it up exactly as you did but my mesh fell through the floor :/ idk why
Thanks!!!
Jason! Why'd u use Awake() instead of Start()?? Is it better?
What code editor is being used? Love the tutorial!
Thx duude
how do you add angular gravity for wall running
thank u
You are awesome
So, get component is an expensive call? Whenever i make projectiles i get a reference to other. GetComponent() and subtract the damage from other.Status.health and destroy my projectile, is there a better way to go about this? Sure for a bullet hell shooter it would be better to let the enemies check if they've been hit, but this approach seems awkward for games where the player only occasionally shoots an arrow.
Bro.i want to create roulette wheel and ball.but when roulette object rotate ball go out.what to do?
Hi Jason. Thanks for all the videos you brought to the game developer community. Really really helpful. May I ask you to consider to create a video/series on anti-cheating. In particular I have an interest in creating a puzzle game with a back-end service. All my user data and achievements I would like to have in the back end. So I would like to know what techniques high level are available to me to ensure that the user has actually completed the level. What I am thinking is some business logic, which checks the sequence, timing of the requests hitting the back end service, but really would like some advise from the professional with experience. Manny thanks.
Does this apply to vr? I keep falling through floor
why does my player with a rigid body slightly clip through the ground when it lands
I'm trying to make good rigidbody movement ...... for me the best is with rb.velosity ..... but you are professional so if you think something about rigidbody movement 😉 🤔
Great tutorial. I've seen in fighting games, shooters and other competitive games that you can apply collision shapes to each individual limb of a character and have each of them react differently depending on where it's hit (the most obvious example being headshots). Is there a way to parent collision shapes like cubes and capsules to a specific bone on the character's rig or is it more complicated than that? I know having too many collision checks and triggers could drastically slow down the game if I overdo it, but, you know, in case the need arises...
On my player, I have a character Controller, animator, and player script and on the obstacle, I have a box collider and the script. When my player tries to jump close to the obstacle and hit the box collider, the player files of the game in the y-direction. When the player jumps from afar from the obstacle then nothing abnormal happens. Do you know what can be the reason for this? I am using on triggerEnter.
Jason, is it okay to use a CharacterController instead of a Rigidbody in big game projects?
wdym by big game projects? they are 2 valid ways to do two different related things.
is there a plugin for VS editor which shows inline parameter hints as Rider do?
how do I have a collider on an object that isnt a cube, sphere, cylinder, etc. (I'm using a chair) and I know I could just make the collider a cube for the chair, but how do I get an exact collider for the object?
mesh collider
Hi! Someone help me please! How can I determine the coordinates of the vertices of the Box Collider? If the object's rotation is not (0, 0, 0), then collider.bounds doesn't help.
Dots physics too?
Nice!! I will try today...
Jason, can you some day create a tutor using MULTIPLES BALLS COLLISIONS in Unity?
i search about on UA-cam but no find nothing about...
Thanks!!
What are you confused about? You just have several balls all with their own colliders?
Grate video. What abort a video like this but for animations :)
great video man ! did some one told you that you look like dan harmon?
if I want everything to fall faster, is increasing the gravity value the right thing to do? Seems very weird, but I find the default fall speed to be very slow for my game. (drag already set to 0)
increase the weight of the rigig body component
Hey. I am making top down shooter for mobile and i have problem with making projectiles. I tryed using rigidbody continuous dynamic collision detection but this didn't detect hits when bullet goes faster. Also tryed raycasting between last and current position for detecting collisions but this method is really performance heavy. So can you help me with dome ideas ? How can i make mobile friendly accurate bullets.? Thanks.
how far and fast are the bullets going? normally with bullet type shots I don't even spawn projectiles and just use raycasts, but it depends a lot on the game. Are the things they're hitting extremely small too btw? Any extra info you can give will hopefully help us get you going in the right direction and get it resolved :)
@@Unity3dCollege bullets should only go for 30-50 meters. I can use raycasting but its instant and i wanna have a bullet traces so that's why i am trying make it physical. And i want them to go slow enough that player can see where his bullets are going.
If your bullets are slow enough to be clearly seen by your player then they are definitively not fast enough to go through an object without detecting it in continuous dynamic mode. Are the layers of your objects colliding with each other ?
@@MrTenergy01 i know and that's the problem i am facing. and yes i've setup layers and tags correctly
does collider trigger matters? i am checking for OnTriggerEnter on my code and bullet's collider is set to trigger.(i've read on forums that it's faster so that's why)
huh, attaching a rigid body doesn't appear to provide any sort of gravity for me, no matter the type of object I create. You don't appear to have any script attached to your sphere. Maybe they updated this? Not that it's any problem to write gravity code, but I did spend some time trying to recreate exactly what you did and could not.
Did you Check that Gravity=True set on the Rigid Body component? It normally defaults to True, and as such no additional Script is required for it to fall. Unless you had also Kinematic checked as well. Typically I would either have Gravity = True + Kinematic = False, for typical physics OR I would have Gravity = False + Kinematics=True for when I want to remove the impact of physics.
:c i'm not getting a red line when i attach the debug to the Sphere
oh lol, i needed to rotate the ball
if unity is the force, you are a luke skywalker. Thanks
Make a video about full Android fps/tps multiplayer game
How do we define collisions and kinematic motion and physic-materials in Unity ECS? Or do we have to have a hybrid system where some of the game physics uses old MonoBehaviours?
My man writing codes on light theme
I find Unity very inconsistent and difficult to understand. If I create the ground as a plane which comes with a mesh collider attached. The ball falls straight through the floor. If I create the ground as a cube which comes with a box collider the ball will stop falling when it hits the cube. Why does the mesh collider not stop the ball falling? I have to manually add a box collider to the plane to get the ball to stop falling.
I also swapped the ball for a tall rectangle. The rectangle fell straight down and then bounced perfectly straight back up. This looked totally unatural. In real life the tall rectangle would fall over. So I guess I have to use a script to make the bounce more random and natural
I used a plane and i worked just fine
@@Mayawayya I am using 2022.2.5f1 I should have mentioned that. Different Unity versions can act differently
@@cargorunnerUK oh that makes sense I'm using a version from 2019
Does this man ever smile
share the files pls
I struggle to make friction based movement, like in real life.
Hey JAson - Great content - each and every time.. keep on doin what youre doing... but one odd request - Please *wear a shirt different colour from the chair* - I cant un-see your flying head !
Is this a 1st world problem?
I got a rigidbody here for ya har har har
It's videos like these that makes me want to give up before I start!
(As a newbie)I typed all the code as per the video and in the very first piece of code I get 2 errors! I don't understand them and cannot fix them.
Below is my code and the error reported on the console. (Remember I am a beginner and this video is aimed at beginners....right?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChangeColorOnCollision : MonoBehaviour
{
private void OnCollisionEnter(Collision collision)
{
Color randomlySelectedColor = GetRandomColor();
GetComponent().material.color = randomlySelectedColor;
}
private void GetRandomColor()
{
return new Color(
r: UnityEngine.Random.Range(0f, 1f),
g: UnityEngine.Random.Range(0f, 1f),
b: UnityEngine.Random.Range(0f, 1f));
}
}
ChangeColorOnCollision.cs(16,9): error CS0127: Since 'ChangeColorOnCollision.GetRandomColor()' returns void, a return keyword must not be followed by an object expression
Will you tell me what is wrong please??
And: Cannot implicitly convert type 'void' to 'UnityEngine.Color'
@@nicobrits2019 Hello Nico , The problem is that Your " Private Void GetRandomColor() " is a void method so it is returning nothing to your " randomlySelectedColor " variable in order to make a function or method return a result you need to replace void with what you would like to return for Example :
Your code -->
private void GetRandomColor()
{
return new Color(
r: UnityEngine.Random.Range(0f, 1f),
g: UnityEngine.Random.Range(0f, 1f),
b: UnityEngine.Random.Range(0f, 1f));
}
Working code ---->
private Color GetRandomColor()
{
return new Color(
r: UnityEngine.Random.Range(0f, 1f),
g: UnityEngine.Random.Range(0f, 1f),
b: UnityEngine.Random.Range(0f, 1f));
}
I am new to coding to but i hope this helps :)
26:25
I still remember trying to explain to someone why making the jump of a character physics based was better then 4 hours of coding it in., lol. why reinvent the wheel.
привет
*привет*
-привет-
_привет_