Forum begins after the advertisement:
[part 10] dive causes unity to freeze completely
Home › Forums › Video Game Tutorial Series › Creating a Metroidvania in Unity › [part 10] dive causes unity to freeze completely
- This topic has 45 replies, 3 voices, and was last updated 2 months ago by Niyam Shah.
-
AuthorPosts
-
October 18, 2024 at 11:37 pm #16110::
i dont want to jinx it but it seems to be fixed….. im not experiencing the issue anymore…
heres the jump script anyway
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class WoodenBotJump : StateMachineBehaviour { Rigidbody2D rb;
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { rb = animator.GetComponentInParent<Rigidbody2D>(); } override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { DiveAttack(); } void DiveAttack() { WoodenBot.Instance.Flip(); Vector2 _newPos = Vector2.MoveTowards(rb.position, WoodenBot.Instance.moveToPosition, WoodenBot.Instance.speed * 3 * Time.fixedDeltaTime); rb.MovePosition(_newPos); float _distance = Vector2.Distance(rb.position, _newPos); if (_distance < 0.1f) { WoodenBot.Instance.Dive(); } if (WoodenBot.Instance.TouchedWall()) { WoodenBot.Instance.moveToPosition.x = rb.velocity.x; _newPos = Vector2.MoveTowards(rb.position, WoodenBot.Instance.moveToPosition, WoodenBot.Instance.speed * Random.Range(2, 4) * Time.fixedDeltaTime); } } override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { }
}`
heres the new dive script:
<code>using System.Collections; using System.Collections.Generic; using UnityEngine; public class WoodenBotDive : StateMachineBehaviour { Rigidbody2D rb; bool callOnce; // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { rb = animator.GetComponentInParent<Rigidbody2D>(); } override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { WoodenBot.Instance.divingCollider.SetActive(true); if (WoodenBot.Instance.Grounded()) { WoodenBot.Instance.divingCollider.SetActive(false); if (!callOnce && DivingPillar.count < 10) { Debug.Log("callOnce is true"); WoodenBot.Instance.DivingPillars(); animator.SetBool("Dive", false); WoodenBot.Instance.ResetAllAttacks(); callOnce = true; } } } override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { callOnce = false; Debug.Log("CallOnce is false"); } }</code>
thanks so much for your help
lets hope i dont get any errors with part 10.5………
-
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: