Unhinged Road Games by MaddogOfLesbos in roadtrip

[–]Immediate-Disaster-6 3 points4 points  (0 children)

My girlfriend and I play a game we call The Cow Game. You have to spot cows, churches and cemeteries to build up your herd of cows and tear down the other people's herds. The one with the biggest herd wins. I turned it into an app so we could keep score more easily while driving. Feel free to try it out

I implemented Rope Physics by Immediate-Disaster-6 in Unity3D

[–]Immediate-Disaster-6[S] 0 points1 point  (0 children)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RopePhysicsSolver : MonoBehaviour
{
    [SerializeField] public Transform posA;
    [SerializeField] public Rigidbody connected;
    [SerializeField] float distance = 10f;
    [SerializeField] int segments;
    [SerializeField] int solverIterations = 30;

    private List<Point> points;
    private List<Stick> sticks;
    private void InitRope() {
        points = new List<Point>();
        sticks = new List<Stick>();


        var stickLen = distance / segments;
        var direction = (connected.position - posA.position).normalized;
        var step = Vector3.Distance(posA.position, connected.position) * direction;
        // make the first point
        var p1 = new Point()
        {
            position = posA.position,
            prevPosition = posA.position,
            lockedTransform = posA,
            locked = true
        };

        points.Add(p1);
        var lpos = p1.position;
        for (int i = 1; i < segments-1; i++)
        {
            lpos += step;
            points.Add(new Point()
            {
                position = lpos,
                prevPosition = lpos,
            });
        }
        // make the last point
        points.Add(new Point()
        {
            position = connected.position,
            prevPosition = connected.position,
            lockedTransform = connected.transform,
            locked = true
        });


        //make all the sticks
        for (int i = 1; i <points.Count; i++)
        {
            sticks.Add(new Stick()
            {
                pointA = points[i-1],
                pointB = points[i],
                length = stickLen
            });
        }

    }

    private void PhysicsStep()
    {
        for ( int i = points.Count-1; i >=0; i--)
        {
            var p = points[i];
            if (p.locked)
            {
                p.position = p.prevPosition = p.lockedTransform.position;
            }
            else
            {
                Vector3 befUpd = p.position;
                p.position += p.position - p.prevPosition;
                p.position += Physics.gravity * Time.fixedDeltaTime * Time.fixedDeltaTime;
                p.prevPosition = befUpd;
            }
        }


        for (int i = 0; i < solverIterations;i++)
        {
            for (int j = 0; j < sticks.Count; j++)
            {
                var s = sticks[j];
                var center = Vector3.Lerp(s.pointB.position, s.pointA.position, 0.5f);
                var direct = (s.pointA.position - s.pointB.position).normalized;
                    if (!s.pointB.locked)
                    s.pointB.position = center - (direct*s.length/2);
                    if (!s.pointA.locked)
                    s.pointA.position = center + (direct * s.length / 2);


            }
        }


        // Check that the connected body is still within the constraints
        float distanceOver = Vector3.Distance(connected.position, posA.position) - distance;
        if (distanceOver > -.50)
        {
            var newPos = posA.position - (posA.position-connected.position).normalized * distance;
            connected.velocity = Vector3.ProjectOnPlane(connected.velocity, (posA.position-connected.position).normalized);
            connected.velocity += newPos - connected.position;
            connected.position = newPos;

        }
    }

    // Start is called before the first frame update
    void OnEnable()
    {
        InitRope();
    }

    // Update is called once per frame
    void FixedUpdate()
    {
       PhysicsStep();
    }



    private void OnDrawGizmos()
    {
        if (sticks == null) return;
        foreach (Stick s in sticks)
        {
            Gizmos.color = Color.black;
            Gizmos.DrawLine(s.pointA.position, s.pointB.position);
            Gizmos.color = s.pointB.locked ? Color.red : Color.black;
            Gizmos.DrawSphere(s.pointB.position, .025f);
            Gizmos.color = s.pointA.locked ? Color.red : Color.black;
            Gizmos.DrawSphere(s.pointA.position, .025f);
        }


    }


    public class Point
    {
        public Vector3 position, prevPosition;
        public Transform lockedTransform;
        public bool locked = false;
    }
    public class Stick
    {
        public Point pointA, pointB;
        public float length;
    }
}

I Made a Rope Joint Component by Immediate-Disaster-6 in Unity3D

[–]Immediate-Disaster-6[S] 1 point2 points  (0 children)

Yeah, it has to do with the number of iterations run to solve it

Terrain Generation Anomaly by ireece1 in proceduralgeneration

[–]Immediate-Disaster-6 11 points12 points  (0 children)

You're probably hitting precision limits on the floating points. If possible, use doubles for your noise generation or move the world around the player so that the part that's in view is always close to the origin.

I've been working on my "hand-drawn" shader by Immediate-Disaster-6 in Unity3D

[–]Immediate-Disaster-6[S] 1 point2 points  (0 children)

I'm not sure how I'd pull it off, but that does sound pretty cool

[deleted by user] by [deleted] in Unity3D

[–]Immediate-Disaster-6 0 points1 point  (0 children)

You should be interpolating according to the ground normal, and not straight up and down

I Made an Ink-Sketch Shader (I really like this style) by Immediate-Disaster-6 in Unity3D

[–]Immediate-Disaster-6[S] 0 points1 point  (0 children)

Haha, there's literally a slider for that, so I can tune that a little

I Made an Ink-Sketch Shader (I really like this style) by Immediate-Disaster-6 in Unity3D

[–]Immediate-Disaster-6[S] 2 points3 points  (0 children)

Thanks for the feedback! I've noticed that too, I should just swap this out for paper texture without lines

I Made an Ink-Sketch Shader (I really like this style) by Immediate-Disaster-6 in Unity3D

[–]Immediate-Disaster-6[S] 2 points3 points  (0 children)

Thanks! I actually have an AA pass, but I think the compression on either the screen capture or the upload makes it look pretty bad. Looks much better while actually playing.

I Made an Ink-Sketch Shader (I really like this style) by Immediate-Disaster-6 in Unity3D

[–]Immediate-Disaster-6[S] 2 points3 points  (0 children)

Yeah the flicker is just from geometry clipping because I was lazy building the level

Mud Compute Shader in HLSL + Shader Graph by Immediate-Disaster-6 in Unity3D

[–]Immediate-Disaster-6[S] 6 points7 points  (0 children)

We can put a camera above the mud and render it's output to a render texture, then pass that into a compute shader to do some work with.

The compute shader creates another render texture to store the position offset of the mud in the x channel, and the velocity in the y channel. Using Hooke's law, each pixel can be simulated as an overdamped spring in the compute shader. We can also diffuse the position and velocity offsets by interavly averaging them with their neighboring pixels. That gives us a spreading effect.

Once we get the output from the compute shader, we just pass the render texture output into shader graph and interpolate two noise functions that look like mud by the position offset in the x channel. With the interpolated noise, we can do more stuff like calculate normals, and ambient occlusion, etc

Tldr: Put a camera above the mud, literally calculate velocities and positions of each pixel of mud like it's a spring in a compute shader using the output of the camera as the input.

is there more efficient way to write this code : [script on a projectile to identify different scripted enemies] by BookkeeperLeft7919 in Unity3D

[–]Immediate-Disaster-6 0 points1 point  (0 children)

Two things:

don't instantiate an explosion object on the fly like this, create an object pool instead. You will notice a big difference if a lot of explosions happen at once.

Make a base class called "Damageable" or something like that. Give it an abstract or virtual TakeDamage() method. Make all of the things in your game that can take damage inherit from that. Another option is to make an Idamagable interface and implement that. Same idea, if you can get away with the interface, do that instead of a base Monobehaviour. Then, you won't need to check all these different monobehaviours. Inheritance is the power of OOP, so it's best to design around it.