Hot answers tagged

2

We can also use physics itself to do the clamping, at the end of each FixedUpdate: // Project where our velocity will take us by the end of the frame. Vector3 positionAtEndOfStep = rb.position + rb.velocity * Time.deltaTime; // Limit that projected position to within our allowed bounds. positionAtEndOfStep.x = Mathf.Clamp(positionAtEndOfStep.x, min, max); ...


2

Your problem is the use of FixedUpdate() for position clamping. You are correct to apply the forces in FixedUpdate() but clamping the position should be done in Update() or LateUpdate(). public Vector3 dir; public Vector3 min; public Vector3 max; Rigidbody rb; void Awake() { rb = GetComponent<Rigidbody>(); } void FixedUpdate() { rb....


1

I wanted to comment but I can't yet (not enough reputation) so I'll ask here: The CalculateCenter function make the targets(objects) to change positions I'm not sure it's true, since this function doesn't change any transform of any object. I assume you meant the calculation in this function is incorrect? See 2 for that. You said the objects vanish far ...


1

Your algorithm only appends links to a chain to the first encountered pair in the chain, but it does not ensure a is the first item in the chain. The result is that an example like { 1,2, 0,1, 2,3} will sort to {1,2, 2,3, 0,1} instead of {0,1, 1,2, 2,3}, so links might be split up. You could check whether the pair at b comes before the pair at a, but with ...


1

Myself, I'd let the InventoryUI script own the interaction with the inventory. When a player opens the InventoryUI, you call something like InventoryUI.ShowInventoryFor(PlayerCharacter character). This procedure handles any initial setup of the menu (populating the slots, etc.) and caches the character it was given as its currentUser member variable. Each ...


Only top voted, non community-wiki answers of a minimum length are eligible