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

Must Know Difference Among CodeIgniter, Laravel, & Phalcon

Here's How I Designed a Twitter Bot for Skiley.

Sorting with BubbleSort

Code Your Own WordPress Theme

Timeline Control Quick Tips

Flutter Animation : Creating medium’s clap animation in flutter

The Online Courses I Took that Helped Me Advance as a Student Journalist

Flutter Setup With Concept

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

Unity Tutorial — Toon Shade in HLSL

Setting up a Unity Project for the High Definition Render Pipeline (HDRP)

2D Mobile: Setting Up The Player

How to Build an Interactive Security Camera System in Unity