there MoveMobToPosition obejcts move to vector3…
- User
there MoveMobToPosition obejcts move to vector3 StartCoroutine(MoveMobToPosition(secondPosition, Random.Range(invokeRange.x, invokeRange.y)));
i wanna initialPosition and second position - be like offset from current mobTransform.position
help fix it
in answe i only awanna necceasar linnes
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.Events; public class RaiseMobEffect : MonoBehaviour { public Transform PowerElectricity;
[Header("Event")] public UnityEvent onSpawnEvent; public UnityEvent onReachDestinationEvent; [Header("Raise")] public Vector2 invokeRange = new Vector2(1f, 3f); // Range for invoking events [Header("Point")] public Vector3 initialPosition = new Vector3(0, -3, 0); // Initial position of the mob public bool enableAutoSecond = true; // Initial position of the mob public Vector3 secondPosition = new Vector3(0, 5, 0); // Second position to move the mob public Transform mobTransform; // Reference to the mob’s transform public float raycastLength = 10f; // Length for the raycast private void OnDrawGizmos() { // Draw a box at the initial position Gizmos.color = Color.red; Gizmos.DrawWireCube(initialPosition, Vector3.one); // Draw a small box at the second position Gizmos.color = Color.green; Gizmos.DrawWireCube(secondPosition, Vector3.one * 0.5f); // Draw a line from the initial position downwards for raycasting visualization Gizmos.color = Color.blue; Gizmos.DrawLine(initialPosition, initialPosition + Vector3.down * raycastLength); } private void OnEnable() {if (mobTransform ==null) mobTransform=this.transform; if (enableAutoSecond) secondPosition = this.mobTransform.position; // Invoke the first event onSpawnEvent?.Invoke(); // Perform a raycast // if (Physics.Raycast(initialPosition, Vector3.down, raycastLength)) { // If raycast hits, start coroutine to move the mob StartCoroutine(MoveMobToPosition(secondPosition, Random.Range(invokeRange.x, invokeRange.y))); } } private IEnumerator MoveMobToPosition(Vector3 targetPosition, float duration) { float elapsedTime = 0f; Vector3 startingPosition = mobTransform.position; while (elapsedTime < duration) { mobTransform.position = Vector3.Lerp(startingPosition, targetPosition, elapsedTime / duration); elapsedTime += Time.deltaTime; yield return null; } mobTransform.position = targetPosition; // Invoke the second event after reaching the destination onReachDestinationEvent?.Invoke(); }}
- Assistant
To adjust your script so that
initialPositionandsecondPositionare used as offsets from the currentmobTransform.position, you only need to make a few changes. Here's the necessary code to achieve that:// Set the initial and second positions as offsets from the current position private void OnEnable() { if (mobTransform == null) mobTransform = this.transform; initialPosition += mobTransform.position; if (enableAutoSecond) { secondPosition = mobTransform.position + secondPosition; } // Invoke the first event onSpawnEvent?.Invoke(); // Start coroutine to move the mob StartCoroutine(MoveMobToPosition(secondPosition, Random.Range(invokeRange.x, invokeRange.y))); }Changes Made:
- Initial Position Offset: Added the current position of
mobTransformtoinitialPositionto use it as an offset. - Second Position Offset: Adjusted
secondPositionby adding it to the currentmobTransform.position.
Now, both
initialPositionand are used as offsets, calculated from the current position of the mob. - Initial Position Offset: Added the current position of
- User
maybe bette use lcoalposition
mobTransform.position = Vector3.Lerp(startingPosition, targetPosition, elapsedTime / duration);here? or its not works?
- Assistant
Using
localPositioncan be beneficial if your object is a child of another transform and you want to move it relative to its parent. IfmobTransformis a child of another transform and you want to manage its movement relative to the parent (not in world space), then you should uselocalPosition. Here's how you might update your script:private IEnumerator MoveMobToPosition(Vector3 targetPosition, float duration) { float elapsedTime = 0f; Vector3 startingPosition = mobTransform.localPosition; while (elapsedTime < duration) { mobTransform.localPosition = Vector3.Lerp(startingPosition, targetPosition, elapsedTime / duration); elapsedTime += Time.deltaTime; yield return null; } mobTransform.localPosition = targetPosition; // Invoke the second event after reaching the destination onReachDestinationEvent?.Invoke(); }Key Considerations:
- User
i have cinemachinee cameraa and virtual cameraa
also i have joystik, its have joy object in centerr
i wanna rotatee cinemachine third person cameraa with using that joystick
i wanna joystick was sloww
[FPD_FixedCurveWindow] public AnimationCurve Sensitivity = AnimationCurve.Linear(0.1f, 0f, 0.9f, 1f); - Assistant
- User
i dont have joystick refeerence
can u implement all it? i have just image inside image in centerr mosly thats it
i wanna cinamachine third person camera rotatee i wanna 2 jousticks 1 for composer 1 for rotation third person cinemachine cameraa
now make only third person works imagee references and et working srciptt
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.