Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using UnityEngine;
- namespace Katamari
- {
- [spaar.Mod("Katamari",author="ITR",version="1.0")]
- public class MainClass : MonoBehaviour
- {
- public BallScript ballScript = null;
- public static string UP = "up";
- public static string DOWN = "down";
- public static string LEFT = "left";
- public static string RIGHT = "right";
- public static bool SuperSticky = false;
- public void Start() {
- spaar.Commands.RegisterHelpMessage("Katamari commands:\n UP [key]\n DOWN [key]\n LEFT [key]\n RIGHT [key]\n acceleration [acceleration]\n maxSpeedMult [speed]\n posDiv [div]\n posDiv [mult]\n SuperSticky [bool]");
- spaar.Commands.RegisterCommand("UP",(args,namedArgs) => {
- if(args.Length<1) {
- return "Current UP key is "+UP;
- }
- string key = args[0].Replace("_"," ").ToLower();
- try {
- Input.GetKey(key);
- }
- catch {
- return "Not a valid key";
- }
- UP = key;
- return "Set UP to "+UP;
- },"Changes the UP key");
- spaar.Commands.RegisterCommand("DOWN",(args,namedArgs) => {
- if(args.Length<1) {
- return "Current DOWN key is "+DOWN;
- }
- string key = args[0].Replace("_"," ").ToLower();
- try {
- Input.GetKey(key);
- }
- catch {
- return "Not a valid key";
- }
- DOWN = key;
- return "Set DOWN to "+DOWN;
- },"Changes the DOWN key");
- spaar.Commands.RegisterCommand("LEFT",(args,namedArgs) => {
- if(args.Length<1) {
- return "Current LEFT key is "+LEFT;
- }
- string key = args[0].Replace("_"," ").ToLower();
- try {
- Input.GetKey(key);
- }
- catch {
- return "Not a valid key";
- }
- LEFT = key;
- return "Set LEFT to "+LEFT;
- },"Changes the LEFT key");
- spaar.Commands.RegisterCommand("RIGHT",(args,namedArgs) => {
- if(args.Length<1) {
- return "Current RIGHT key is "+RIGHT;
- }
- string key = args[0].Replace("_"," ").ToLower();
- try {
- Input.GetKey(key);
- }
- catch {
- return "Not a valid key";
- }
- RIGHT = key;
- return "Set RIGHT to "+RIGHT;
- },"Changes the RIGHT key");
- spaar.Commands.RegisterCommand("acceleration",(args,namedArgs) => {
- if(args.Length<1) {
- return "Current acceleration "+BallScript.acceleration;
- }
- try {
- BallScript.acceleration = float.Parse(args[0]);
- }
- catch {
- return "Could not parse acceleration";
- }
- return "Set acceleration to "+BallScript.acceleration;
- },"Changes the acceleration");
- spaar.Commands.RegisterCommand("maxSpeedMult",(args,namedArgs) => {
- if(args.Length<1) {
- return "Current maxSpeedMult "+BallScript.maxSpeedMult;
- }
- try {
- BallScript.maxSpeedMult = float.Parse(args[0]);
- }
- catch {
- return "Could not parse speed";
- }
- return "Set maxSpeedMult to "+BallScript.maxSpeedMult;
- },"Changes the maxSpeedMult");
- spaar.Commands.RegisterCommand("posDiv",(args,namedArgs) => {
- if(args.Length<1) {
- return "Current posDiv "+Sticky.posDiv;
- }
- try {
- Sticky.posDiv = float.Parse(args[0]);
- }
- catch {
- return "Could not parse div";
- }
- return "Set posDiv to "+Sticky.posDiv;
- },"Changes the amount blocks get displaced when put on the spinning thingy");
- spaar.Commands.RegisterCommand("posMult",(args,namedArgs) => {
- if(args.Length<1) {
- return "Current posMult "+Sticky.posMult;
- }
- try {
- Sticky.posMult = float.Parse(args[0]);
- }
- catch {
- return "Could not parse mult";
- }
- return "Set posMult to "+Sticky.posMult;
- },"Changes the amount blocks get displaced when put on the spinning thingy");
- spaar.Commands.RegisterCommand("SuperSticky",(args,namedArgs) => {
- if(args.Length<1) {
- return "Current SuperSticky "+SuperSticky;
- }
- try {
- SuperSticky = bool.Parse(args[0]);
- }
- catch {
- return "Could not parse bool";
- }
- return "Set SuperSticky to "+SuperSticky;
- },"Duh");
- }
- public void FixedUpdate() {
- if(ballScript==null) {
- if(AddPiece.isSimulating) {
- GameObject startingBlock = GameObject.Find("bgeL0");
- if(startingBlock!=null) {
- ballScript = startingBlock.AddComponent<BallScript>();
- }
- }
- }
- }
- }
- public class BallScript : MonoBehaviour {
- public static Rigidbody rigidBody;
- float originalMass = 1;
- public static Vector3 position = Vector3.zero;
- public void Start() {
- Collider col = GetComponent<Collider>();
- Destroy(col);
- col = gameObject.AddComponent<SphereCollider>();
- rigidBody = GetComponent<Rigidbody>();
- originalMass = rigidBody.mass;
- rigidbody.mass = 5;
- gameObject.AddComponent<Sticky>();
- size = 2*2*2;
- }
- public static float acceleration = 30000;
- public static float size = 0;
- public void FixedUpdate() {
- if(!AddPiece.isSimulating) {
- rigidBody.mass = originalMass;
- Destroy(this);
- }
- Vector3 left = new Vector3(Camera.main.transform.forward.x,0,Camera.main.transform.forward.z).normalized;
- Vector3 forw = new Vector3(left.z,0,-left.x);
- if(Input.GetKey(MainClass.UP)) {
- rigidBody.AddTorque(forw*Time.fixedDeltaTime*acceleration,ForceMode.Acceleration);
- }
- if(Input.GetKey(MainClass.DOWN)) {
- rigidBody.AddTorque(-forw*Time.fixedDeltaTime*acceleration,ForceMode.Acceleration);
- }
- if(Input.GetKey(MainClass.LEFT)) {
- rigidBody.AddTorque(left*Time.fixedDeltaTime*acceleration,ForceMode.Acceleration);
- }
- if(Input.GetKey(MainClass.RIGHT)) {
- rigidBody.AddTorque(-left*Time.fixedDeltaTime*acceleration,ForceMode.Acceleration);
- }
- Vector3 vec = rigidbody.angularVelocity;
- if(vec.magnitude*Mathf.Sqrt(size)>maxSpeedMult) {
- rigidbody.angularVelocity = vec.normalized*maxSpeedMult;
- }
- }
- public static float maxSpeedMult = 1.7f;
- }
- public class Sticky : MonoBehaviour {
- public static float posDiv = 20;
- public static float posMult = 19;
- public static string nameToCheck = "";
- public void Start() {
- FinishLine finishLine = FindObjectOfType<FinishLine>();
- if(finishLine!=null) {
- nameToCheck = finishLine.nameToCheck;
- Debug.Log(nameToCheck);
- }
- }
- public void OnCollisionEnter(Collision col) {
- if(col.gameObject.name=="Katamari")
- return;
- Rigidbody rb = col.gameObject.GetComponent<Rigidbody>();
- if(rb!=null) {
- List<GameObject> toBeAttached = new List<GameObject>(){col.gameObject};
- List<Joint> jointsOfAttached = new List<Joint>();
- jointsOfAttached.AddRange(col.gameObject.GetComponentsInChildren<Joint>());
- for(int i = 0;i<jointsOfAttached.Count;i++) {
- if(jointsOfAttached[i].connectedBody!=null) {
- if(!toBeAttached.Contains(jointsOfAttached[i].connectedBody.gameObject)) {
- toBeAttached.Add(jointsOfAttached[i].connectedBody.gameObject);
- jointsOfAttached.AddRange(jointsOfAttached[i].connectedBody.GetComponentsInChildren<Joint>());
- }
- }
- }
- for(int i = 0;i<toBeAttached.Count;i++) {
- for(int j = 0;j<toBeAttached[i].transform.childCount;j++) {
- GameObject go = toBeAttached[i].transform.GetChild(j).gameObject;
- if(!toBeAttached.Contains(go)) {
- toBeAttached.Add(go);
- }
- }
- }
- float totalMass = 0;
- float totalSize = 0;
- for(int i = 0;i<toBeAttached.Count;i++) {
- Vector3 s = Vector3.zero;
- try {
- totalMass += toBeAttached[i].GetComponent<Rigidbody>().mass;
- s = toBeAttached[i].GetComponent<Renderer>().bounds.size;
- }
- catch {
- continue;
- }
- totalSize += s.x*s.y*s.z;
- }
- if((totalMass<=BallScript.rigidBody.mass*1.1&&totalSize<BallScript.size*1.1f)||MainClass.SuperSticky) {
- BallScript.rigidBody.mass += totalMass;
- BallScript.size += totalSize;
- List<Component> des = new List<Component>();
- foreach(GameObject go in toBeAttached) {
- if(go.name!=nameToCheck)
- go.name = "Katamari";
- go.transform.parent = transform;
- BleedOnJointBreak bleedOnJointBreak = go.GetComponent<BleedOnJointBreak>();
- if(bleedOnJointBreak!=null) {
- bleedOnJointBreak.injuryControllerCode.Kill();
- bleedOnJointBreak.AddToPercentageBar();
- }
- Component[] components = go.GetComponents(typeof(Component));
- for(int i = 0;i<components.Length;i++) {
- string comName = components[i].ToString().ToLower();
- if(comName.Contains("transform")||comName.Contains("collider")||comName.Contains("ballscript")||comName.Contains("mesh")) {
- continue;
- }
- try {
- Destroy(components[i]);
- }
- catch {
- des.Add(components[i]);
- }
- }
- go.transform.localPosition *= posMult/posDiv;
- }
- foreach(Component d in des) {
- Destroy(d);
- }
- }
- }
- }
- public void FixedUpdate() {
- if(!AddPiece.isSimulating)
- Destroy(this);
- // if(transform.localPosition.magnitude>2)
- // transform.localPosition -= transform.localPosition.normalized*Time.fixedDeltaTime;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement