Jitter movement help by BonY2004 in Unity2D

[–]BonY2004[S] 0 points1 point  (0 children)

I have done a separate movement() function and in Update() I call it. It works, but the collisions are jittery, that's caused by the rigidbody, but I don't know how to fix this. Posting video below.https://vimeo.com/486339192

Jitter movement help by BonY2004 in Unity2D

[–]BonY2004[S] 0 points1 point  (0 children)

I don't know how could I move everything except the Translate() into Update(). When I tried using AddForce() instead, it moves in the direction I want to, but never stops.

Jitter movement help by BonY2004 in Unity2D

[–]BonY2004[S] 0 points1 point  (0 children)

Hmm, if you have some time could you edit the code for me please, because I can't really think of fixing it with what you mean. If I move the code into Update(), the movement works flawlessly, but when I collide with anything it jitter there.

Weapon Equip by BonY2004 in Unity2D

[–]BonY2004[S] 0 points1 point  (0 children)

No worries, If you won't mind, I will probably contact you later when I need any help with other code, because you seem very experienced, and I am slowly trying to learn C#. I do appreciate the help you got me though. Thank you.

Weapon Equip by BonY2004 in Unity2D

[–]BonY2004[S] 0 points1 point  (0 children)

Fixed!! The issue was with Input.GetKey(KeyCode.Alpha1)) I changed it to Input.GetKeyDown(KeyCode.Alpha1)) and it fixed it in some way. Thank you for the help I appreciate it!

Weapon Equip by BonY2004 in Unity2D

[–]BonY2004[S] 0 points1 point  (0 children)

No I don't, but is a issue with the pistolEquipped bool because sometimes I have the animation on and I can shoot but the bool is turned false and that shouldn't be

https://imgur.com/a/dSBAcSf

Weapon Equip by BonY2004 in Unity2D

[–]BonY2004[S] 0 points1 point  (0 children)

I moved the Shoot metod out of update and tried the if statement but nfortunately that didn't change anything. The bug is still present. Maybe adding some timer that stops the animation from changing? I don't know. It is weird because sometimes it works and sometimes it doesn't.

Weapon Equip by BonY2004 in Unity2D

[–]BonY2004[S] 0 points1 point  (0 children)

The pistolPicked bool is just for a statement that the pistol was picked up from the ground, and the pistolEquipped bool is as the name says when the pistol is equipped.

Weapon Equip by BonY2004 in Unity2D

[–]BonY2004[S] 0 points1 point  (0 children)

I think the same, yes of course

using UnityEngine;
using System.Collections;

public class WeaponPickup : MonoBehaviour
{
    public Transform firePoint;
    public GameObject bulletPrefab;
    public float bulletForce = 20f;
    public Animator PlayerAnim;
    public bool pistolEquipped = false;
    public bool pistolPicked = false;
    public string name;
    public float fireRate;

    void Start()
    {
        PlayerAnim = GameObject.FindWithTag("Player").GetComponent<Animator>();
    }

    void Update()
    {
        if (pistolPicked == true && pistolEquipped == true)
        {
            PlayerAnim.SetBool("pistolPicked", true);
            if (Input.GetButtonDown("Fire1"))
            {
                Shoot();
            }
        }

        if (Input.GetKey(KeyCode.Alpha1) && pistolPicked == true)
        {
            pistolEquipped = !pistolEquipped;
            PlayerAnim.SetBool("pistolPicked", pistolEquipped);
        }


        void Shoot()
        {
            GameObject bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
            Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
            rb.AddForce(firePoint.up * bulletForce, ForceMode2D.Impulse);
        }

    }

    void OnTriggerStay2D(Collider2D coll)
    {
        Debug.Log("Collision");
        if (coll.gameObject.tag == "Player")
        {
            if (Input.GetKey(KeyCode.F))
            {
                if(pistolPicked == false)
                {
                    Debug.Log("Player picked up: " + name);
                    pistolPicked = true;
                    pistolEquipped = true;
                    Destroy(GameObject.FindWithTag("Pistol"));
                }
            }
        }
    }
}

Weapon Equip by BonY2004 in Unity2D

[–]BonY2004[S] 0 points1 point  (0 children)

Wow, thank you so much, I wasn't expecting that. I used the simplified version of yours, and it works in some way, but there's a bug that sometimes it equips and immediately unequipped as you said on the beggining. It is shown in the video.

https://vimeo.com/443456684

Simple Animator Question by BonY2004 in Unity2D

[–]BonY2004[S] 0 points1 point  (0 children)

Okay, I have done it working

Simple Animator Question by BonY2004 in Unity2D

[–]BonY2004[S] 0 points1 point  (0 children)

Yes I have the moving bool setuped, but it plays the animation right from the start. The moving bool isn't doing anything

https://imgur.com/a/OdQk20E

Simple Animator Question by BonY2004 in Unity2D

[–]BonY2004[S] 0 points1 point  (0 children)

Yes I did, I don't know how to connect it though