What's the difference between these scripts, I know script 2 is updated version of 1 but…
- User
What's the difference between these scripts, I know script 2 is updated version of 1 but how exactly please. Script 1 using UnityEngine; using UnityEngine.UI;
[RequireComponent(typeof(Rigidbody))] public class HoverBoardControl : MonoBehaviour { private float boardslideSoundTime; private bool boardSlideCheck; private bool noseSlideCheck; private bool tailSlideCheck;
public bool IsSteeringLeft { get { return isSteeringLeft; } } public bool IsSteeringRight { get { return isSteeringRight; } } [Header("Hover Settings")] public float hoverForce = 1500f; public float hoverHeight = 6f; public GameObject[] hoverPoints; [Header("Movement Settings")] public float forwardAcceleration = 100.0f; public float backwardAcceleration = 25.0f; [SerializeField] private float turnStrength = 10f; // Made it serializable for editor control [Header("UI & Scoring")] public Text scoreText; public int currentScore; public HUD hud; public TrickManager trickManager; [Header("Boost Settings")] public float boostMultiplier = 2.0f; [Header("Rotation Settings")] public float minRotation = -20.0f; public float maxRotation = 0.0f; [Header("Timer Settings")] public float timer = 5.0f; [Header("Miscellaneous")] public bool moving; public GameObject board; [Header("Input Settings")] public KeyCode moveForwardKey = KeyCode.W; public KeyCode moveBackwardKey = KeyCode.S; public KeyCode turnLeftKey = KeyCode.A; public KeyCode turnRightKey = KeyCode.D; [Header("Customizable Keys")] [SerializeField] private KeyCode ollieKey = KeyCode.Space; [SerializeField] private KeyCode boostKey = KeyCode.LeftControl; int layerMask; float currentThrust; float currentTurn; Rigidbody rb; private GrindDetection grindDetection; // Reference to the GrindDetection script public bool IsGrounded { get; set; } public AudioSource GrindAudio { get; set; } public Vector3 BoardTilt { get; set; } private bool isSteeringLeft; private bool isSteeringRight; void Awake() { rb = GetComponent<Rigidbody>(); hud = FindObjectOfType<HUD>(); trickManager = GetComponent<TrickManager>(); grindDetection = GetComponentInChildren<GrindDetection>(); GrindAudio = GetComponent<AudioSource>(); isSteeringLeft = false; isSteeringRight = false; } // Add the following methods to match GrindDetection expectations public void GrindAudioVolumeLerp(float targetVolume, float lerpSpeed) { GrindAudio.volume = Mathf.Lerp(GrindAudio.volume, targetVolume, lerpSpeed * Time.deltaTime); } public void RotateAround(Vector3 point, Vector3 axis, float angle) { rb.transform.RotateAround(point, axis, angle * Time.deltaTime); } public void Rotate(Vector3 axis, float angle, Space relativeTo) { rb.transform.Rotate(axis * angle * Time.deltaTime, relativeTo); } public void TransformLocalRotationLerp(Quaternion targetRotation, float lerpSpeed) { rb.transform.localRotation = Quaternion.Lerp(rb.transform.localRotation, targetRotation, lerpSpeed * Time.deltaTime); } public void TransformRotationLerp(Quaternion targetRotation, float lerpSpeed) { rb.transform.rotation = Quaternion.Lerp(rb.transform.rotation, targetRotation, lerpSpeed * Time.deltaTime); } // Add the following method to start the grind public void StartGrind() { grindDetection.StartGrind(); } void Start() { layerMask = 1 << LayerMask.NameToLayer("Characters"); layerMask = ~layerMask; if (scoreText == null) { GameObject canvas = GameObject.Find("Canvas"); if (canvas != null) { scoreText = Instantiate(Resources.Load("ScoreText", typeof(Text))) as Text; scoreText.transform.SetParent(canvas.transform, false); } else { Debug.LogError("Canvas not found. Make sure there is a Canvas GameObject in the scene."); } } } void OnEnable() { rb.isKinematic = false; rb.useGravity = true; } void OnDisable() { rb.velocity = Vector3.zero; rb.angularVelocity = Vector3.zero; rb.isKinematic = true; } void GetSteeringInput() { isSteeringLeft = Input.GetKey(turnLeftKey); isSteeringRight = Input.GetKey(turnRightKey); } void Update() { GetSteeringInput(); currentThrust = 0.0f; // Adjust currentTurn directly based on input if (isSteeringLeft) { currentTurn = -turnStrength; } else if (isSteeringRight) { currentTurn = turnStrength; } else { currentTurn = 0.0f; } // Allow adjustment of currentThrust from the Unity GUI inspector currentTurn = Mathf.Clamp(currentTurn, -1.0f, 1.0f); // Clamp the value between -1 and 1 scoreText.text = currentScore + " Points"; if (Input.GetKeyDown(ollieKey)) { trickManager.ExecuteOllieOrTrick(1500f); } if (hud != null) { if (Input.GetKeyDown(boostKey) && (hud.BoostInt > 0)) { forwardAcceleration = forwardAcceleration * boostMultiplier; backwardAcceleration = backwardAcceleration * boostMultiplier; if (hud.BoostInt <= 0) { forwardAcceleration = forwardAcceleration / boostMultiplier; backwardAcceleration = backwardAcceleration / boostMultiplier; } } if (Input.GetKey(boostKey)) { hud.BoostInt -= 0.2f; } } Vector3 currentRotation = transform.rotation.eulerAngles; currentRotation.x = Mathf.Clamp(currentRotation.x, minRotation, maxRotation); currentRotation.z = Mathf.Clamp(currentRotation.z, minRotation, maxRotation); transform.rotation = Quaternion.Euler(currentRotation); float aclAxis = Input.GetAxis("Vertical"); if (aclAxis > 0.1f) currentThrust = aclAxis * forwardAcceleration; else if (aclAxis < -0.1f) currentThrust = aclAxis * backwardAcceleration; // Remove the following block of code related to currentTurn // if (Mathf.Abs(currentTurn) > 0.1f) // { // if (isSteeringLeft) // currentTurn = -turnStrength; // else if (isSteeringRight) // currentTurn = turnStrength; // } // currentTurn = Mathf.Clamp(currentTurn, -1.0f, 1.0f); // Remove this line // Check for grinding input if (Input.GetKeyDown(grindDetection.GrindKey)) { StartGrind(); } } void FixedUpdate() { ApplyHover(); ApplyMovement(); ApplyTurning(); ApplyGrinding(); } void ApplyHover() { for (int i = 0; i < hoverPoints.Length; i++) { var hoverPoint = hoverPoints[i]; RaycastHit hoverHit; if (Physics.Raycast(hoverPoint.transform.position, -Vector3.up, out hoverHit, hoverHeight, layerMask)) { rb.AddForceAtPosition(Vector3.up * hoverForce * (1.0f - (hoverHit.distance / hoverHeight)), hoverPoint.transform.position); } else { if (transform.position.y > hoverPoint.transform.position.y) { rb.AddForceAtPosition(hoverPoint.transform.up * hoverForce, hoverPoint.transform.position); } else { rb.AddForceAtPosition(hoverPoint.transform.up * -hoverForce, hoverPoint.transform.position); } } } } void ApplyMovement() { if (Mathf.Abs(currentThrust) > 0) { rb.AddForce(transform.forward * currentThrust); } } void ApplyTurning() { if (currentTurn != 0) { rb.AddRelativeTorque(Vector3.up * currentTurn * turnStrength); } } void ApplyGrinding() { if (grindDetection.IsGrinding()) { // Apply grinding logic here // Access grindDetection properties and methods as needed // Example: Reduce hover height and force during grinding // Add your custom logic here based on the skateboard script if (boardSlideCheck || noseSlideCheck || tailSlideCheck) { boardslideSoundTime += Time.deltaTime; if (boardslideSoundTime > 0f && boardslideSoundTime < 0.1f && !GrindAudio.isPlaying) { GrindAudio.Play(); // Assuming GrindAudio is your AudioSource } } else { boardslideSoundTime = 0f; GrindAudio.Stop(); // Assuming GrindAudio is your AudioSource } // Add the rest of your custom logic from the skateboard script // Adjust rotations, movements, and other parameters as needed } else { // Reset hover height and force when not grinding // Add the rest of your logic for when not grinding // Reset any adjustments made during grinding, if necessary } }}
Script 2 using UnityEngine; using UnityEngine.UI;
[RequireComponent(typeof(Rigidbody))] public class HoverBoardControl : MonoBehaviour { private float boardslideSoundTime; private bool boardSlideCheck; private bool noseSlideCheck; private bool tailSlideCheck;
public bool IsSteeringLeft { get { return isSteeringLeft; } } public bool IsSteeringRight { get { return isSteeringRight; } } [Header("Hover Settings")] public float hoverForce = 1500f; public float hoverHeight = 6f; public GameObject[] hoverPoints; [Header("Movement Settings")] public float forwardAcceleration = 100.0f; public float backwardAcceleration = 25.0f; [SerializeField] private float turnStrength = 10f; // Made it serializable for editor control [Header("UI & Scoring")] public Text scoreText; public int currentScore; public HUD hud; public TrickManager trickManager; [Header("Boost Settings")] public float boostMultiplier = 2.0f; [Header("Rotation Settings")] public float minRotation = -20.0f; public float maxRotation = 0.0f; [Header("Timer Settings")] public float timer = 5.0f; [Header("Miscellaneous")] public bool moving; public GameObject board; [Header("Input Settings")] public KeyCode moveForwardKey = KeyCode.W; public KeyCode moveBackwardKey = KeyCode.S; public KeyCode turnLeftKey = KeyCode.A; public KeyCode turnRightKey = KeyCode.D; [Header("Customizable Keys")] [SerializeField] private KeyCode ollieKey = KeyCode.Space; [SerializeField] private KeyCode boostKey = KeyCode.LeftControl; int layerMask; float currentThrust; float currentTurn; private GrindDetection grindDetection; // Reference to the GrindDetection script public bool IsGrounded { get; set; } public AudioSource GrindAudio { get; set; } public Vector3 BoardTilt { get; set; } private bool isSteeringLeft; private bool isSteeringRight; private Rigidbody rb; private bool isOnRamp; private Quaternion targetRampRotation; void Awake() { rb = GetComponent<Rigidbody>(); hud = FindObjectOfType<HUD>(); trickManager = GetComponent<TrickManager>(); grindDetection = GetComponentInChildren<GrindDetection>(); GrindAudio = GetComponent<AudioSource>(); isSteeringLeft = false; isSteeringRight = false; } // Add the following methods to match GrindDetection expectations public void GrindAudioVolumeLerp(float targetVolume, float lerpSpeed) { GrindAudio.volume = Mathf.Lerp(GrindAudio.volume, targetVolume, lerpSpeed * Time.deltaTime); } public void RotateAround(Vector3 point, Vector3 axis, float angle) { rb.transform.RotateAround(point, axis, angle * Time.deltaTime); } public void Rotate(Vector3 axis, float angle, Space relativeTo) { rb.transform.Rotate(axis * angle * Time.deltaTime, relativeTo); } public void TransformLocalRotationLerp(Quaternion targetRotation, float lerpSpeed) { rb.transform.localRotation = Quaternion.Lerp(rb.transform.localRotation, targetRotation, lerpSpeed * Time.deltaTime); } public void TransformRotationLerp(Quaternion targetRotation, float lerpSpeed) { rb.transform.rotation = Quaternion.Lerp(rb.transform.rotation, targetRotation, lerpSpeed * Time.deltaTime); } // Add the following method to start the grind public void StartGrind() { grindDetection.StartGrind(); } // Add the following method to set the hover height public void SetHoverHeight(float height) { hoverHeight = height; } void Start() { layerMask = 1 << LayerMask.NameToLayer("Characters"); layerMask = ~layerMask; if (scoreText == null) { GameObject canvas = GameObject.Find("Canvas"); if (canvas != null) { scoreText = Instantiate(Resources.Load("ScoreText", typeof(Text))) as Text; scoreText.transform.SetParent(canvas.transform, false); } else { Debug.LogError("Canvas not found. Make sure there is a Canvas GameObject in the scene."); } } } void OnEnable() { rb.isKinematic = false; rb.useGravity = true; } void OnDisable() { rb.velocity = Vector3.zero; rb.angularVelocity = Vector3.zero; rb.isKinematic = true; } void GetSteeringInput() { isSteeringLeft = Input.GetKey(turnLeftKey); isSteeringRight = Input.GetKey(turnRightKey); float aclAxis = Input.GetAxis("Vertical"); currentThrust = aclAxis * ((aclAxis > 0) ? forwardAcceleration : backwardAcceleration); } void Update() { GetSteeringInput(); // Adjust currentTurn directly based on input if (isSteeringLeft) { currentTurn = -turnStrength; } else if (isSteeringRight) { currentTurn = turnStrength; } else { currentTurn = 0.0f; } // Allow adjustment of currentThrust from the Unity GUI inspector currentTurn = Mathf.Clamp(currentTurn, -1.0f, 1.0f); // Clamp the value between -1 and 1 if (Input.GetKeyDown(ollieKey)) { trickManager.ExecuteOllieOrTrick(1500f); } if (hud != null) { if (Input.GetKeyDown(boostKey) && (hud.BoostInt > 0)) { forwardAcceleration = forwardAcceleration * boostMultiplier; backwardAcceleration = backwardAcceleration * boostMultiplier; if (hud.BoostInt <= 0) { forwardAcceleration = forwardAcceleration / boostMultiplier; backwardAcceleration = backwardAcceleration / boostMultiplier; } } if (Input.GetKey(boostKey)) { hud.BoostInt -= 0.2f; } } // Check for grinding input if (Input.GetKeyDown(grindDetection.GrindKey)) { StartGrind(); } } void FixedUpdate() { ApplyHover(); ApplyMovement(); ApplyTurning(); // New code to align with ramp when on it if (grindDetection.IsGrinding() && isOnRamp) { // Align to the ramp’s angle AlignToRamp(); } ApplyGrinding(); } // New method to align the board with the ramp’s angle private void AlignToRamp() { rb.rotation = Quaternion.Slerp(rb.rotation, targetRampRotation, Time.deltaTime * 5f); // Note: ‘5f’ is a lerp speed factor that you can adjust as needed or expose as a public variable. } void ApplyHover() { for (int i = 0; i < hoverPoints.Length; i++) { var hoverPoint = hoverPoints[i]; RaycastHit hoverHit; if (Physics.Raycast(hoverPoint.transform.position, -Vector3.up, out hoverHit, hoverHeight, layerMask)) { rb.AddForceAtPosition(Vector3.up * hoverForce * (1.0f - (hoverHit.distance / hoverHeight)), hoverPoint.transform.position); } else { if (transform.position.y > hoverPoint.transform.position.y) { rb.AddForceAtPosition(hoverPoint.transform.up * hoverForce, hoverPoint.transform.position); } else { rb.AddForceAtPosition(hoverPoint.transform.up * -hoverForce, hoverPoint.transform.position); } } } } void ApplyMovement() { if (Mathf.Abs(currentThrust) > 0) { rb.AddForce(transform.forward * currentThrust); } } void ApplyTurning() { if (currentTurn != 0) { rb.AddRelativeTorque(Vector3.up * currentTurn * turnStrength); } } void ApplyGrinding() { if (grindDetection.IsGrinding()) { // Apply grinding logic here // Access grindDetection properties and methods as needed // Example: Reduce hover height and force during grinding SetHoverHeight(hoverHeight * 0.5f); // Adjust the hover height during grinding // Add your custom logic here based on the skateboard script if (boardSlideCheck || noseSlideCheck || tailSlideCheck) { boardslideSoundTime += Time.deltaTime; if (boardslideSoundTime > 0f && boardslideSoundTime < 0.1f && !GrindAudio.isPlaying) { GrindAudio.Play(); // Assuming GrindAudio is your AudioSource } } else { boardslideSoundTime = 0f; GrindAudio.Stop(); // Assuming GrindAudio is your AudioSource } // Add the rest of your custom logic from the skateboard script // Adjust rotations, movements, and other parameters as needed } else { // Reset hover height and force when not grinding // Reset the hover height when not grinding // Add the rest of your logic for when not grinding // Reset any adjustments made during grinding, if necessary } }}
- Assistant
Based on the information provided, it appears that "Script 2" is a refined version of "Script 1", with several updates and improvements. Here are the changes I've identified:
-
Removal of redundant code:
- In Script 1, there's a redundant code block for current thrust and current turn that has been removed in Script 2.
-
Code restructuring:
GetSteeringInputhas been updated. In Script 2, the code for getting thecurrentThrustvalue has been moved inside theGetSteeringInputmethod from theUpdatemethod, streamlining the input handling process.- The part of the code in
Updatethat clampscurrentTurnto the range of -1.0f to 1.0f, which incorrectly appears twice in Script 1, has been corrected and appears only once in Script 2.
-
Introduction of ramp alignment functionality:
- New private fields,
isOnRampandtargetRampRotation, have been added to Script 2 to handle the board's alignment with a ramp, possibly indicating physics or gameplay improvements. - A new method
AlignToRamphas been introduced to Script 2, which is responsible for aligning the hoverboard with a ramp when it's detected by the game logic. This method usesQuaternion.Slerpto interpolate between the current rotation and thetargetRampRotation.
- New private fields,
-
Modification in the Grinding logic:
- In Script 2, the
ApplyGrindingmethod has a new SetHoverHeight call, which suggests there's now a dynamic hover height adjustment during grinding. - The comment highlighting the necessity to adjust the hover height during grinding has been expanded with explicit code in Script 2, which likely leads to a more nuanced grinding experience.
- In Script 2, the
-
Cleanup and refactoring:
- Some comments in Script 1 regarding removing a code block have been acted upon in Script 2. The result is cleaner and clearer logic for hover and turn adjustments.
It's important to note that while these changes are identifiable from the code provided, without additional context or descriptions of the game's intended behavior or mechanics, it is difficult to say precisely what gameplay improvements or bug fixes these changes might correspond to. Nonetheless, these updates reflect a normal process of iterative development, where code is improved upon for clarity, efficiency, and functionality.
-
- User
Specifically around grinding and ramp detection
- Assistant
Focusing specifically on the changes and improvements related to grinding and ramp detection between Script 1 and Script 2, here are the key differences:
Script 1:
- Grinding logic seems to be in its initial stages.
- The
ApplyGrindingmethod contains custom logic with checks for different slide checks (boardSlideCheck,noseSlideCheck,tailSlideCheck). - Plays a grinding audio based on the checks and a timer (
boardslideSoundTime). - There is no explicit mention or handling of the ramp alignment.
Script 2:
-
Enhancements to the grinding functionality have been made.
-
The
ApplyGrindingmethod has been updated to explicitly control thehoverHeightduring grinding. This suggests that the board's behavior while grinding has become more dynamic and responsive, giving the character a more realistic interaction with the grind surface:// Apply grinding logic here // Access grindDetection properties and methods as needed SetHoverHeight(hoverHeight * 0.5f); // Adjust the hover height during grinding -
Ramp detection has been introduced, with two new private fields:
isOnRamp: A boolean flag to determine if the hoverboard is on a ramp.targetRampRotation: AQuaternionrepresenting the target rotation when aligning the hoverboard to a ramp.
-
A new method
AlignToRamphas been created to align the board with the ramp's angle during grinding:// New method to align the board with the ramp’s angle private void AlignToRamp() { rb.rotation = Quaternion.Slerp(rb.rotation, targetRampRotation, Time.deltaTime * 5f); // Note: ‘5f’ is a lerp speed factor that you can adjust as needed or expose as a public variable. } -
The
FixedUpdatemethod now includes logic to check if the board is on a ramp and, if so, to align it properly:if (grindDetection.IsGrinding() && isOnRamp) { // Align to the ramp’s angle AlignToRamp(); }
These updates suggest that the developers wanted to enhance the realism and the player's control over the hoverboard while grinding and add functionality for ramp interactions. This is achieved by dynamically adjusting the hover height and the board's rotation to match the ramp angle, providing a more immersive gaming experience. It will also likely help with performing tricks on ramps and controlling the hoverboard more accurately during gameplay.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.