Day 83 — Pushing Objects to Complete Puzzles

private float _pushSpeed = 2.0f;private void OnControllerColliderHit(ControllerColliderHit hit)
{
if (hit.transform.tag == "Box")
{
Rigidbody box = hit.collider.GetComponent<Rigidbody>();
if (box != null)
{
Vector3 pushDirection = new Vector3(hit.moveDirection.x, 0, 0);
box.velocity = pushDirection * _pushSpeed;
}
else
{
Debug.LogError("Box is null");
}
}
}
private void OnTriggerStay(Collider other)
{
if (other.tag == "Box")
{
float distance = Vector3.Distance(transform.position, other.transform.position);
if (distance < 0.05f)
{
Rigidbody box = other.GetComponent<Rigidbody>();
if (box != null)
{
box.isKinematic = true;
}
MeshRenderer renderer = GetComponentInChildren<MeshRenderer>(); if (renderer != null)
{
renderer.material.color = Color.green;
}
Destroy(this);
}
}
}

--

--

--

Hey and welcome! My name is Connor and my goal here is to put out a daily post for a full year about my game development journey.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Machine Learning Powered Data Pipeline

Update: Elevator

Salesforce and WSDL : a SOAP opera

Android Trends in 2020

Cloning of Revv Website…

Cost of an Error: Who Pays for Programming Blunders?

State Of Matterless #5

My Journey through the path of android programming

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Connor Fullarton

Connor Fullarton

Hey and welcome! My name is Connor and my goal here is to put out a daily post for a full year about my game development journey.

More from Medium

In just 4 steps, Make a modular moving platform in Unity

Learn to code by making 2 D space shooter game.

2.5D Platformer — Improving the Ledge Grab #10

Installing Unity