- Home /
How to move an object in boundaries of a cuboid or a cube?
I am working of flocking algorithm of Youtube Channel Bits to Board, [Video Tutorial Link][1] The aim is to keep the flock agents within a certain boundary, the video creator moves the flock in a sphere by using this code
using System.Collections; using System.Collections.Generic; using UnityEngine; [CreateAssetMenu(menuName = "Flock/Behavior/Stay In Radius")] public class StayInRadiusBehavior : FlockBehavior { public Vector3 center; public float radius = 15f; public override Vector3 CalculateMove(FlockAgent agent, List<Transform> context, Flock flock) { Vector3 centerOffset = center - agent.transform.position; float t = centerOffset.magnitude / radius; if (t < 0.9f) { return Vector3.zero; } return centerOffset * t * t; } }
Now I want to move the flock in a room like shape or a cube or a cuboid like the flock bouncing away from the walls. Can anybody guide me, I am a beginner please? [1]: https://www.youtube.com/watch?v=kmwVDSUivkg&list=RDCMUCifiUB82IZ6kCkjNXN8dwsQ∈dex=9