Forum begins after the advertisement:


[Part 3] “knife” (arrow) code

Home Forums Video Game Tutorial Series Creating a Rogue-like Shoot-em Up in Unity [Part 3] “knife” (arrow) code

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #19315
    Tristin Bartlett
    Level 1
    Participant
    Helpful?
    Up
    0
    ::

    Instead of a knife i made an arrow, it has the same orientation as the knife (pointed to top right) and even when i change the prefab to be -45, it still comes out pointed to the top right, i’ve tried it with other prefabs and they all do the same thing.

    please help, here’s my Arrow (knife) Controller code requested by Terresquall the code is a 1 to 1 of the KnifeController code, but i just replaced all the words with knife with arrow, the code seems to work.

    using UnityEngine;
    
    public class ArrowController : WeaponController
    {
        // Start is called once before the first execution of Update after the MonoBehaviour is created
        protected override void Start()
        {
            base.Start();
        }
    
        protected override void Attack()
        {
            base.Attack();
            GameObject spawnedArrow = Instantiate(prefab, transform.position, Quaternion.identity);
            // Set the position of the spawned arrow to the position of the weapon
            spawnedArrow.transform.position = transform.position;
            spawnedArrow.GetComponent<ArrowBehaviour>().DirectionChecker(pm.moveDir);
        }
    
    
    }
    View post on imgur.com
    #19316
    Alp Apustaja
    Level 10
    AI Assistant
    (BETA)
    Helpful?
    Up
    0
    ::

    Hello Tristin! I see the issue – you’re passing pm.moveDir to DirectionChecker(), but according to the tutorial, you should be passing pm.lastMovedVector instead.

    Change this line:

    spawnedArrow.GetComponent().DirectionChecker(pm.moveDir);

    To this:

    spawnedArrow.GetComponent().DirectionChecker(pm.lastMovedVector);

    The lastMovedVector tracks the last direction the player moved, which is what the DirectionChecker() method expects to properly orient your arrow in all 8 directions.

    #19317
    Tristin Bartlett
    Level 1
    Participant
    Helpful?
    Up
    0
    ::

    that is not what the tutorial says in the video or the forum posts. god i hate ai

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: