You could raycast, and if its hits the door, then you could rotate it in the opposite direction. This way, the door doesnt need a rigidbody, and the player doesnt need to be part of the physics.
I’m not very familiar with Raycast, can you explain it a bit, I like the Idea.
void Update()
{
RaycastHit hit = new RaycastHit();
float maxDistance = 5f;
float doorRotateSpeed = 5f;
if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, maxDistance))
{
if(hit.transform.CompareTag("DoorFront"))
{
hit.transform.parent.Rotate(Vector3.up * Time.deltaTime * doorRotateSpeed);
}
if (hit.transform.CompareTag("DoorBack"))
{
hit.transform.parent.Rotate(Vector3.up * Time.deltaTime * -doorRotateSpeed);
}
}
}
so heres the setup : DoorFront and DoorBack objects have a tag with the same name, are basically invisible colliders,
and when the raycast hits either one, it will either rotate in a certain way.
When it rotates the parent object (DoorObject), it will rotate the children in a centered way, so if you move all the children to the left or the right, so that the pivot isnt in the center, the door rotates how it should.
DoorObject
—DoorVisual
—DoorFront
—DoorBack
Also i think there needs to be a script on the door to have some rotation constraints, because then it keeps on rotation if you keep on looking at the door.
Check out the physics tutorial on the learn tab for raycast, basically shooting (casting) a line (ray) in a straight line. If it hits x, do y.
@DryTear : Hmm, I thinks I cannot use this system for mine. Because of certain things.
One is the thing you said about rotating the Parent, the way I’ve Built the Objects in the Hierarchy is arranged, I mean like. There’s a Parent “World (Unstatic)” And another Object called “Doors” is inside the “World()” and even inside the “Doors” its arranged to specified by locations, like inside “Doors” there’s another according to location, something like “Kitchen” and inside it is the final Door object. Lol.
And next this still uses Objects other than the Door (The invisible Colliders). Etc…
@Jay2001 :I know how it works, I’m not familiar how to use it. You know the right syntax and stuff. xD
It seems the collider moves but the material objected doesn’t.
Hi! I know that I’m very late… but this might help someone else in the future… I’ve created a video on this topic, I would consider to check it out… :
https://www.youtube.com/watch?v=Y8m9M2-PMTA
This video demonstrates how to make a Push-To-Open door using Hinge Joint.
I would also recommend to check out the video by @gamedevelopingboy . It’s a good tutorial and demonstration.
You can also read the official Manual on Hinge Joint by Unity.
Btw, I don’t think so you’re a noob anymore ![]()
I know this thread is old but I have encountered a problem… I did everything in the video and it worked perfectly as expected… However, If I set the door mass higher than the player’s mass, the player pushes the door slowly and more dynamically (I prefer it that way) but the problem is that the door pushes the player when bouncing back to the center… How can I make it so that I push the door slowly but without the door pushing me back …
Combine knob with door as gameObject.

