#💻┃code-beginner

1 messages · Page 611 of 1

acoustic belfry
#

the speed was set by the enemy that shoots it

#
        {
            animator.Play("Base Layer.MortemRifleShooting");
            GameObject nuevoProyectil = Instantiate(proyectil, proyectilposition.position, Quaternion.identity);
            Vector3 direccion = (objetivo.position - proyectilposition.position).normalized;
            Rigidbody2D rb = nuevoProyectil.GetComponent<Rigidbody2D>();
            if (rb != null)
            {
                rb.linearVelocity = direccion * bulletspeed;
            }

            balas--;
        }```
rich adder
#

bullet needs its own script

acoustic belfry
#

no, it has it

#

but it doesnt has it speeds

rich adder
#

it does in the Rigidbody

acoustic belfry
#

this is all


public class MortemRifleProyectile : MonoBehaviour
{
    public int damage = 5;

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.transform.TryGetComponent(out ValeriaController player))
        {
            player.TakeDamage(damage);
            Destroy(gameObject);
        }
    }
}```
acoustic belfry
rich adder
#

store it in a vector3

#

Vector3 rigidbodyVelocity
FixedUpdate(){
rigidbodyVelocity = rb.linearVelocity

#

if its a trigger though it gets a bit more complicated

#

because with triggers You dont really get the normal

acoustic belfry
#

with triggers you mean the
private void OnTriggerEnter2D(Collider2D collision)?

rich adder
#

meaning the collider is a trigger yes

acoustic belfry
#

dont worry, i will use the same mechanic of harming an enemy, just that instead of damaging the proyectile (wich would be cursed) it will make the speed thing

rich ice
rich adder
cosmic dagger
#

You're checking meltdownTimer, but the value displayed is currentNumber, which is calculated after the check. Compare that variable instead . . .

nimble apex
rocky canyon
#

until i dont 🙂 lol

#

i barely caught that bug

cosmic dagger
#

Hahaha . . .

nimble apex
#
        texture.LoadImage(File.ReadAllBytes(filePath), true);
        if (texture.width > 480 || texture.height > 480)
        {
            texture.Reinitialize(480, 480);
        }

        texture.name = fileName;
        
        return texture;```
#

i gonna force texture like this first

acoustic belfry
#

cuz my idea was to make this inside a Void

#

thats how my meele works, it calls a state from the enemies

rich adder
#

wat?

acoustic belfry
#

this is how my weapon works, look

rich adder
#

inside a Void

acoustic belfry
#
 {
     // Cast a ray to detect if an enemy is in range

     Vector2 MacheteRange = new Vector2(attackRange, attackRange);
     Collider2D hitEnemy = Physics2D.OverlapBox(machetepos.transform.position, MacheteRange, 0f, demons);

     // If an enemy is detected, deal damage
     if (hitEnemy != null)
     {
         if (hitEnemy.TryGetComponent(out EnemyBase enemy))
         {
             enemy.TakeDamage(meleeDamage);
         }
     }
 }```
acoustic belfry
rich adder
#

OnTriggerEnter2D is also a "void" return method

acoustic belfry
#

but without needing to trigger the collision

#

cuz the machete and the player has the same collision

#

...so it would be a paradox

acoustic belfry
rich adder
#

confused to where the bullet part comes in?

acoustic belfry
#

the idea is

#

the same way i make enemies go into their hurt method

#

i will make the proyectile go into it reflect method

#

public class MortemRifleProyectile : MonoBehaviour
{
    public int damage = 5;

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.transform.TryGetComponent(out ValeriaController player))
        {
            player.TakeDamage(damage);
            Destroy(gameObject);
        }
    }
    public void Parried()
    { 
      things
    }
}```
#

it makes sense in my brain

rich adder
#

You would still want to track the velocity of projectile rigidbody in its own class

acoustic belfry
#

i suposse

#

the thing is, i tried to paste it inside the method, and it showered some errors

rich adder
#

paste wat?

#

dont mindless copy code without understanding what its doing

#

You can call Parried if you use a physics query sure

#

the rest is similiar

rich ice
drifting cosmos
#

so if you stache a reference to a game object you have to use _spawnedObj.getcomponent().Level unless you use Unit instead of gameobject type but what if you have other classes on a game object like if you have a mage class or something would you create another of that same game object but of type that class?

rich adder
#

maybe I misunderstood your question ?

acoustic belfry
rich adder
drifting cosmos
rich adder
acoustic belfry
#
using UnityEngine;

public class MortemRifleProyectile : MonoBehaviour
{
    public int damage = 5;
    public Rigidbody2D rb;


    private void OnTriggerEnter2D(Collider2D collider)
    {
        if (collision.transform.TryGetComponent(out ValeriaController player))
        {
            if (player.IsParry)
            {
                var collisionPoint = collider.ClosestPoint(rb.position);
                var dir = rb.position - collisionPoint;
                rb.linearVelocity = Vector3.Reflect(rigidbodyVelocity, dir.normalized);
            }
            else
            {
                player.TakeDamage(damage);
                Destroy(gameObject);
            }
        }
    }
    }```
drifting cosmos
rich adder
acoustic belfry
rich ice
#

!code

eternal falconBOT
acoustic belfry
#

got it

rich adder
# acoustic belfry got it

the only one needs to be set is rigidbodyVelocity in fixedupdate, the rest are already set on the trigger happening

acoustic belfry
#

but yeah, im pretty confused right now

acoustic belfry
#

sorry im just getting confused

rich adder
#

idk wat you mean how ?

#

also didnt you want to do from the weapon itself now you're back to trigger?

acoustic belfry
#

i realized my plan was dumb

#

or not idk, i just want this to work, i didnt knew making this would be so tiring

rich adder
#

you have to pick one or the other

#

either put the logic in the projectile or the parrying / deflecting object

drifting cosmos
rich adder
#

You can only grab 1 type return from Instantiate

#

but again once you have that either use a public field/property to access the other components from that script, or do a GetComponent on the instanced object like i shown above

rocky canyon
#

TryGet works well.. if thats what we're talkin bout

acoustic belfry
#

Holup.
What if i delete the proyectile, and make the player shoot a brand new proyectile with the same sprite as the enemy one?.
I did the same thing for a doom mod long ago

rocky canyon
#
public class Projectile : MonoBehaviour
{
    private void OnTriggerEnter2D(Collider2D collision)
    {
        // use collision to Try to Get CharacterController2D
        if(collision.TryGetComponent<CharacterController_2D>(out CharacterController_2D characterController))
        {
            // if we're here then our Trigger found a CharacterController_2D
            Debug.Log($"We activated Trigger. Reference to CharacterController: {characterController.name}");

            // we could do something w/ our CharacterController_2D if we wanted.

            // now we destroy this gameobject
            Destroy(this.gameObject);
        }
    }
}```
rocky canyon
acoustic belfry
#

Makes sense

rocky canyon
#

just little OnTrigger2D test i did real quick.. but thats before i read the entire thing..
this just shows the collision via that code i sent above ^

red cedar
#

Hello, I'm creating new project but I got this error already. Does anyone know how to resolve it?

rich adder
#

if problem persists go to package manager and remove Version Control package

vagrant chasm
#

hii im new to unity, can someone help me, why is my character is falling through the map

burnt vapor
#

Specifically, check if everything has a collider and check that these can communicate with eachother. Additionally, make sure you use the correct colliders. For example, don't use 2d colliders when you work in 3d.

rich ice
strange tapir
#

is there a nice way to disable the physics of a game object? for example, when the player dies i want all the objects on the map to stop moving, i was thinking of using a static bool but having to check everywhere if the player is dead seems unnecesary, i was wondering if a function like gameObject.DisablePhysics(); exists..

#

i know Time.timeScale exists, but that will also disable the player

naive pawn
#

gameobjects don't have physics

strange tapir
naive pawn
#

i think timeScale would be appropriate here

naive pawn
strange tapir
#

thanks

naive pawn
strange tapir
naive pawn
#

i think timescale would be most appropriate here, and there's a few ways to work around that

green badge
#

I'm using this parallax script:

using UnityEngine;

public class Parallax : MonoBehaviour
{
private float length, startpos;
public GameObject cam;
public float parallaxEffect;

void Start()
{
    startpos = transform.position.x;
    length = GetComponent<SpriteRenderer>().bounds.size.x;
}

void FixedUpdate()
{
    float temp = (cam.transform.position.x * (1 - parallaxEffect));
    float dist = (cam.transform.position.x * parallaxEffect);

    transform.position = new Vector3(startpos + dist, transform.position.y, transform.position.z);

    if (temp > startpos + length) 
        startpos += length;
    else if (temp < startpos - length) 
        startpos -= length;
}

}

And when I start the game it makes all 3 backgrounds snap into the same position, what are the possible fixes? the images are the before and after I start the game

strange tapir
naive pawn
eternal falconBOT
strange tapir
green badge
#

Maybe get some shit going on in your life

eternal needle
naive pawn
naive pawn
#

although you could simulate gravity under unscaled time yourself, it'd probably be a pain though

strange tapir
#

im thinking of just disabling manually

#

since all my :"Objects" live under Managers object

#

if i disable Managers i presume everything will stop too

naive pawn
#

it will not

strange tapir
#

dangit

naive pawn
#

enabled is a property of each component, it doesn't propagate to anything

#

you're thinking of SetActive

#

but that'll make everything disappear too

frosty hound
naive pawn
#

anyways @green badge what even is the issue with backgrounds snapping on play? do they move correctly according to parallax? do they tile correctly when you move far enough?

green badge
#

they do snap in front of the camera when u move out of range

#

But I got 3 different ones and they all go into the same position as the game starts idk if you understand what I mean

naive pawn
#

ah i see

green badge
#

I just thought of a fix

#

I'll do that rq

naive pawn
#

if that doesn't work, please format your code properly or use a paste site so we can actually read it

green badge
#

yea mb, thanks for the help

strange tapir
#

it somehow worked

naive pawn
#

you'll have to make sure everything is reenabled properly, and no state broke in the meantime

#

maybe it works, but imo seems like a pretty fragile system

strange tapir
#

well the thing is, the only thing that can happen from this state is that you reset the game

naive pawn
#

reset as in, reload the entire thing?

strange tapir
#

yeah

naive pawn
#

there's no respawn mechanic?

strange tapir
#

reload the game scene

strange tapir
naive pawn
#

oh i thought you meant reload the entire game, like close and reboot lmao

strange tapir
#

its just a 1:1 recreation of flappy bird im doing

eternal needle
#

you could just use events and subscribe to some global OnPlayerDeath event. then have the scripts disable themselves when the player dies

naive pawn
naive pawn
#

not perf wise, it just could have a lot of hidden consequences if you have more complex systems

eternal needle
#

in a flappy bird scenario, shouldnt you just have 1 script control the location of all pipes anyways?

#

then that one script can just stop moving them

strange tapir
#

i move pipes and the ground

#

they both have their own "Managers"

#

that sit under a Managers game object, i just take that Managers object and disable both of them

vagrant chasm
strange tapir
#

animations are gonna be the death of me

#

apparently "Exit" doesnt stop the animation 😭

#

it just goes back to "entry"

burnt vapor
#

But I would assume you just put it on the parent here since that's the main component

#

You could even make a third child purely for the collission if you want to organize it a bit and separate collission

#

Your issue is probably that you use either the wrong type of collission, or the collission is set incorrectly for it to work

vagrant chasm
#

still falling 😦

topaz mortar
#

Would this calculate correctly? Or would it get stuck/throw errors when values get too large for ints?
All the variables used in the formula are ints:
return (long)(baseXp + (baseXp * MathF.Floor(level / levelIncrease)));

naive pawn
naive pawn
topaz mortar
#

yes

naive pawn
#

you don't need that Mathf.Floor then

topaz mortar
#

what if level is 3 and levelincrease is 2?

naive pawn
#

you'd get 1

topaz mortar
#

oh k

naive pawn
#

int/int -> int

silk night
#

but its uses RoundToInt instead of floor

naive pawn
#

anyways if the result gets too large for an int, it'd overflow before you cast it to a long

naive pawn
#

it uses trunc

eternal needle
silk night
#

oh nvm

naive pawn
#

trunc is equivalent to floor for nonnegative values

topaz mortar
#

cool 🙂

topaz mortar
naive pawn
#

or have some value already be a long

topaz mortar
#

ah just one is fine?

naive pawn
topaz mortar
#

the int will be happy to hear that 🙂

naive pawn
#

you could also consider uint

topaz mortar
#

so:
return (long)baseXp + (baseXp * level / levelIncrease);

naive pawn
#

to answer your question more directly; if levelIncrease overflows to 0, you'll get a div by zero error.
anything other than that case won't error, you'll just get incorrect results.

topaz mortar
#

probably should get the 2nd baseXp, since that's the one going to get too big for int

naive pawn
topaz mortar
#

return baseXp + ((long)baseXp * level / levelIncrease);
It is eventually going to be too large for int, so might as well set it up right from the start not?

eternal needle
#

if any of these can get too large for ints, you should just move away from ints entirely there

#

its not like itll be converted correctly if the value already overflowed

topaz mortar
#

all individual values are fine as int, but the calculation result will not be

teal viper
#

Or you should handle the collision manually in code.

polar acorn
#

To be more accurate - Kinematic rigidbodies exert forces, but do not respond to them

faint osprey
#

how do i read the value of the individual things like depth and horizontal

    }

    private void OnDisable()
    {
        playerInput.Disable();

        playerInput.Player.Movement.canceled -= Handle_Movement;
    }

    private void Handle_Movement(InputAction.CallbackContext context)
    {
        Vector2 direction = new Vector2(context.ReadValue<>)
    }```
this is what i got so far and now i dont know how to get the individual values for depth and horizontal
wintry quarry
#

Remove all the bindings in the action.
Set the action type to Value and control type to Vector2.
Then add an up/left/right/down composite or whatever it's called

#

And add all 4 keys there

vagrant chasm
#

ill try

#

Btw how do i make an animation

#

Do i need blender?

wintry quarry
#

You don't need blender but blender is probably a good idea

#

Its tools for animating are better than Unity's

#

Look at mixamo too

graceful fractal
#

I have an incredibly confusing problem here.

Within this if statement, neither Log is being triggered, it is as if the entire If statement is being skipped.

However, this only happens if I click on the very first button of the list of attacks, for every single other attack, it fires through normally, and the information is updated.

What could possibly cause this?

naive pawn
#

well, what's above it?

graceful fractal
#

This is the full Update

lone sable
#

I think I might be stupid but... I'm trying to have an object follow the path of a lineRender. The problem, is that it seems to be traveling VERY slowly through it.. and I'm not really sure why that would be happening? I would figure it would be near instant.

private IEnumerator FollowPath() {
        transform.position = lineRenderer.GetPosition(0);
        Debug.Log("Duration: " + duration);

        for (int i = 0; i < lineRenderer.positionCount - 1; i++) {
            Vector3 pos = lineRenderer.GetPosition(i);
            transform.position = pos;
            yield return null;
        }
    }
naive pawn
eternal falconBOT
naive pawn
#

but anyways, try debugging before other conditionals

graceful fractal
#
    {
        if (state == BattleState.PlayerAttack)
        {
            if (EventSystem.current.currentSelectedGameObject != battleMenuControlSystem.currentlySelectedGameObjectByEventSystem)
            {

                TMP_Text _textHolder = null;

                foreach (var text in battleMenuControlSystem.attackText)
                {
                    if (EventSystem.current.currentSelectedGameObject != null && EventSystem.current.currentSelectedGameObject.TryGetComponent<Button>(out Button _button))
                    {

                        if (_button.GetComponentInChildren<TextMeshProUGUI>() == text && _textHolder == null)
                        {
                            _textHolder = EventSystem.current.currentSelectedGameObject.GetComponentInChildren<TMP_Text>();

                        }
                    }

                }
                if (_textHolder != null)
                {
                    Debug.Log(_textHolder.text);
                    foreach (var knownAttack in playerUnit.entity.knownAttacks)
                    {
                        if (_textHolder.text == knownAttack.Base.Attackname)
                        {
                            battleMenuControlSystem.UpdateAttackDetails(knownAttack);

                        }
                    }
                } else
                {
                    Debug.Log("Textholder is null");
                }

            }





        }
    }```
graceful fractal
polar acorn
naive pawn
graceful fractal
#

no... no it is not reached....

I'm actually mad at myself for not realizing that, thank you.

Today has been one of those days

polar acorn
#

Since there's a log in the if and else, if neither are printing, then it is definitely not reaching this if statement. Log the value before the if statements it is inside of to find out which isn't running

graceful fractal
#

I figured out what is causing it. Or at least I hope this is it

#

I fixed it

#

LOL it was such an easy fix after I figured out that if wasn't being reached. Thank you

#

So, in another script, I hap hazardly already set those values to be equal in a redundancy check, but that caused the first update to never fire, so the first button of the group would never get updated.

Cutting out that part of the redundancy check fixed it

frank rivet
#

this is my flight controller and camera script

using UnityEngine;

public class CameraFollow : MonoBehaviour
{
    [Header("Follow Settings")]
    public Transform target;
    public float mouseSensitivity = 100f;
    public float distance = 10f;
    public float height = 5f;
    public float smoothSpeed = 5f;
    public float minVerticalAngle = -80f;
    public float maxVerticalAngle = 80f;

    private float xRotation = 0f;
    private float yRotation = 0f;
    private Vector3 velocity = Vector3.zero;

    private void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible = false;
    }

    private void LateUpdate()
    {
        if (target == null) return;

        // Get mouse input
        float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
        float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;

        // Apply rotation with clamping
        xRotation -= mouseY;
        xRotation = Mathf.Clamp(xRotation, minVerticalAngle, maxVerticalAngle);
        yRotation += mouseX;

        // Calculate offset and rotation
        Quaternion rotation = Quaternion.Euler(xRotation, yRotation, 0);
        Vector3 offset = rotation * new Vector3(0, height, -distance);

        // Smoothly follow target
        Vector3 targetPosition = target.position + offset;
        transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothSpeed * Time.deltaTime);
        
        // Maintain focus on target
        transform.LookAt(target.position);
    }

    public Vector3 GetCameraCenterPoint()
    {
        return target.position + transform.forward * distance;
    }
}```
#

I am SOOOOO confused on how to make the plane face the center of the free cam

#

i just implemented the free cam and its kinda alright

#

but when I tried to make the aircraft turn to the center of it

#

it rotated without banking and using turning speed

faint osprey
#
{
    public Transform playerBody;
    public float mouseSensitivity;

    public Vector2 lookInput;
    private float xRotation;

    private void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible = false;
    }

    private void Update()
    {

        float mouseX = lookInput.x * mouseSensitivity * Time.deltaTime;
        float mouseY = lookInput.y * mouseSensitivity * Time.deltaTime;

        xRotation -= mouseY;
        xRotation = Mathf.Clamp(xRotation, -90f, 90f);
        transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);

        playerBody.Rotate(Vector3.up * mouseX);
    }
}```

i dont understand why camera movement is so jittery
swift crag
#

Do not multiply mouse input by deltaTime

#

mouse input is already an absolute amount of movement

#

unlike a thumbstick input, which is a rate of movement (and thus needs to be converted into an amount of movement by multiplying by deltaTime)

swift crag
#

When you multiply by deltaTime, you wind up making those long movements even longer

tender crater
#

can one of yall try help me in editor my games works perfectly fine but in builds i get a MethodNotFoundExeception and ive debugged alot the method is public ive made sure it doesnt get stripped i just dont know why

wintry quarry
#

share more details

tender crater
#

so my button uses a clickedOK method to delete the ui text and spawn another one for more text however when clicking on the Ok button it just says methodNotFoundExeception

#

and as a result my game cant be played because it wont progress until the ok button has been pressed

swift crag
#

what kind of build is this? PC/mac/linux, or Web?

#

how are you seeing this exception? did you make a development build?

tender crater
#

Windows Pc

#

yes development build

swift crag
#

is it IL2CPP or Mono?

tender crater
#

mono

swift crag
#

okay, so code stripping probably isn't the issue

#

can you show the exception message?

tender crater
#

just that really

#

nothing else

swift crag
swift crag
# tender crater

You may need to look in the log file to see more information. I forget how much appears in the in-game console..

tender crater
#

1 second

#

oh yeah i made a seperate debug log aswell to see

#

in the log it doesnt explain much either bascially the same thing im seeing in

#

the ingame console

swift crag
#

well that's vague

#

How is the button's target assigned?

#

did you set it up in the inspector, or did you add a listener via script?

tender crater
#

listener

swift crag
#

okay, so you did it via script

#

Can you show the relevant code?

tender crater
#

public void clickedOK()
{
Debug.Log("clickedOK was called");

    if (!isActiveUI())
    {
        Debug.LogWarning("clickedOK() called but UI is not active.");
        return;
    }
    if (textIndex < texts.Count)
    {
        displayCurrentMessage();
        playOpenSound();
        return;
    }
    close();
    if (onOK != null)
    {
        VNLUtil.getInstance().doStartCoRoutine(onOK);
    }
}
exotic jacinth
#

Hey everyone! I'm experiencing an FPS drop when playing footstep and sprinting sounds. My code just picks a random AudioSource from an array and plays it, but as soon as I add footsteps, my FPS drops significantly. I've checked the profiler, and audio seems to be causing the issue. Does anyone have tips on optimizing audio playback in Unity? I'd really appreciate any help

wintry quarry
eternal falconBOT
tender crater
#
public void clickedOK()
    {
        Debug.Log("clickedOK was called");

        if (!isActiveUI())
        {
            Debug.LogWarning("clickedOK() called but UI is not active.");
            return;
        }
        if (textIndex < texts.Count)
        {
            displayCurrentMessage();
            playOpenSound();
            return;
        }
        close();
        if (onOK != null)
        {
            VNLUtil.getInstance().doStartCoRoutine(onOK);
        }
    }
wintry quarry
#

like - how you hooked this method up to the button

tender crater
wintry quarry
#

none of this is standard unity stuff

#

How does this UI Button Message script work

#

And what does the inspector of the MessageUI object look like that you have there

swift crag
#

oh man that's an old inspector

wintry quarry
#

Is this like a Unity 4 or 5 thing

tender crater
wintry quarry
#
  • Why does this UI obejct have a box collider?
  • What are these UI Button Message things, why not normal Button component? (that existed in 2017... right?)
tender crater
wintry quarry
#

(the MessageUI object)

tender crater
#

I mean if it's really bad I'm willing to change it tbf

tender crater
#

just in builds it doesnt

wintry quarry
#

Can you show the inspector of that object

#

aalso what is the target platform you're using here? Windows?

tender crater
#

of the messageUI object?

wintry quarry
#

Yes

tender crater
#

btw if you wondering this is what the hirenarchy looks like for it

wintry quarry
#

how did you "make sure it doesn't get stripped"?

tender crater
#

[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
is this not correct?

wintry quarry
#

no

#

Use the [Preserve] attribute

tender crater
#

is this now correct?

wintry quarry
#

probably

tender crater
#

ok imma build now

#

dang it did not work

#

same error

wintry quarry
#

you sure it's the same method and not a different one this time?

tender crater
#

yes

exotic jacinth
# wintry quarry Can you show the profiler results you saw and your code?
using UnityEngine;

public class Footsteps : MonoBehaviour
{
    public AudioSource[] footsteps;
    public AudioSource[] Running;

    public void PlayFootStepAudio()
    {
        if (footsteps.Length == 0) return; // Prevent errors if no sounds are assigned

        int n = Random.Range(0, footsteps.Length);
        footsteps[n].Play(); // Play the selected footstep sound
    }

    public void PlaySprintAudio()
    {
        if (Running.Length == 0) return; // Prevent errors if no sprinting sounds are assigned

        int n = Random.Range(0, Running.Length); // Select a random sprinting sound
        Running[n].Play(); // Play the selected sprinting sound
    }
}



wintry quarry
#

662ms in RenderLoop

exotic jacinth
#

so how do i fix it?

pure drift
#

!code

eternal falconBOT
pure drift
#

i have this adjusted code for a weapon in my game https://paste.ofcode.org/aHrxTgB4H8E3eUKjx9Aj4g basically i want to instanitate it from my player like a bullet but im not sure how to go about it because of the target component in this script because i cant set it in the assets as i get a type mismatch

swift crag
#

You can't reference a scene object from a prefab

#

Whoever instantiates the prefab should give it the necessary scene references

pure drift
#

intresting thank you but if i instantiate it from the player how would it work because i reference the transform component in this script

swift crag
#
Thing instance = Instantiate(thingPrefab);
instance.foo = bar;
#

that kind of thing

pure drift
#

intresting thank you

hasty tundra
#

I have an object with a script running an OnTriggerEnter2D Function, and i want the trigger to count the hitbox of a child object. Is there a way to register the OnTriggerEnter of a collider not attached directly to the same object as the script?

rich adder
hasty tundra
#

Theres the issue, i forgot the rigidbody 🤦‍♂️

rich adder
#

if(collision.gameObject.TryGetComponent(etc..){

hasty tundra
#

Yeah i noticed that (editing old code and i had no clue with trygetcomponent back then lmao

rich adder
pure drift
#

to my previous question i have it set up something like this how would i change it up its not making sense to me right now

rich adder
#

UI should be something already inside the scene

#

the object in the scene should then reference the player when its spawned to track its stats to display

pure drift
#

from the player

rich adder
#

you haven't really explained what "hard time" means

#

whats preventing

pure drift
#

so i have a transform component but i cant really set that up in the prefab but i use that prefab in the player game object as seen above

rich adder
#

wdym you cant set that up

pure drift
#

because its in the hiearchy

rich adder
#

if the player prefab was placed already in the scene you can only add scene references to that player in the scene

pure drift
#

i want it as that middle circle to be the target

#

its its own gameobject

rich adder
pure drift
#

from the playerscript using instantiation

rich adder
#

you havent sent that

pure drift
rich adder
pure drift
#

so basically i launch it from the player and it uses the seek to go to the middle point basically

rich adder
#

okay but that doesnt answer the question nor does it say how is the "middle point" target created

#

just from what I seen so far
CousCous couscousInst = Instantiate(CousCousPrefab, SpawnPoint.position, Quaternion.identity);
couscousInst.target = myTarget

#

other than that you need to explain more, in your mind it makes sense. To someone outside looking in you have to explain exactly what you want to do

pure drift
#

so basically the player launches this power up from the spawnpoint position (in front of the player), it uses seek to go to the middle of the screen(target gameobject) to destroy all enemies(that part is not implemented yet). what i am having a a hard time with is using the targets transform properly

rich adder
#

is target already in the scene? or is it created at runtime

pure drift
#

its already in the scene its the empty gameobject in the middle and its at the bottom of the hiearchy

rich adder
#

btw this is pretty inefficient to do every frame..
GameObject[] enemiesArray = GameObject.FindGameObjectsWithTag("enemy");

#

if the player is already in the scene like you have it now, assign it from the instance in the scene then pass it that way.
Otherwise you need a tag / component you can search for at runtime

pure drift
#

im not really worried about finding the enemies right now im just trying to find a way to launch this missle from the player to reach the target

rich adder
#

pass the reference on instantiation or do a search at runtime (less efficient)

pure drift
#

thank you i will look into these options

shy orbit
#

Trying to get player to rotate based on my mouse position but it wont follow my mouse, only rotates towards the position of the mouse where it was when i start the game when i move the player

shy orbit
#

This is the code

public class PlayerMovement : MonoBehaviour
{
    [SerializeField] private float playerSpeed;
    public Rigidbody2D rb;

    private Vector2 moveDirection;
    private Vector2 mousePosition;
    [SerializeField] private Camera sceneCamera;
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    

    // Update is called once per frame
    void Update()
    {
       ProcessInput(); 
    }

    void FixedUpdate()
    {
        Move();
    }

    void ProcessInput()
    {
        float moveX = Input.GetAxisRaw("Horizontal");
        float moveY = Input.GetAxisRaw("Vertical");
        moveDirection = new Vector2(moveX, moveY).normalized;
        mousePosition = sceneCamera.ScreenToWorldPoint(Input.mousePosition);
    }

    void Move()
    {
        rb.linearVelocity = new Vector2(moveDirection.x * playerSpeed, moveDirection.y * playerSpeed);
        Vector2 aimDirection = mousePosition - rb.position;
        float aimAngle = Mathf.Atan2(aimDirection.y, aimDirection.x) * Mathf.Rad2Deg - 90f;
        rb.rotation = aimAngle;
    }
}
rich adder
shy orbit
#

"'Vector2' does not contain a definition for 'z' and no accessible extension method 'z' accepting a first argument of type 'Vector2' could be found (are you missing a using directive or an assembly reference?)"

polar acorn
#

It's got two dimensions, hence the 2

rich adder
#

oh wait it was already vector2

polar acorn
#

ScreenToWorldPoint returns a Vector3, you should store it in a Vector3

rich adder
#

mybad

polar acorn
#

Actually if you're just setting z to 0 that's fine

#

no need to take the middle step

rich adder
#

yeah z was already omitted

#

misread that..shit i need some caffeine lol

shy orbit
#

yeah idk player just rotates to the spot where mouse was at the start but wont follow mouser

#

wont follow mouse*

#

i feel like theres nothing wrong with the code but idk

rich adder
shy orbit
#

so i can move the player normally with wasd, but it wont rotate and aim towards mouse

#

just rotates automatically to where mouse was at the beginning

#

where it clicked "play"

polar acorn
#

Is your camera perspective or orthographic?

rich adder
#

just curious, can. you try this rq
rb.transform.right = aimDirection

#

or use .up if your forward is the green arrow

shy orbit
shy orbit
rich adder
#

are you sure this script is running after?

polar acorn
shy orbit
#

yeah its this script thats running

rich adder
#

and it moves fine throughout ?

shy orbit
#

yeah movement is fine, its just the rotation thats wacky

rich adder
shy orbit
#

sure give me a sec

#

nvm i found the problem

#

i had the script in twice somehow and one of them didnt have the camera on it

rich adder
#

you have an error

#

right

#

keep the console window docked

#

never hide the console

#

its easy to miss errors at the bottom

shy orbit
#

okay thank you for your help

#

i managed to spot it while rewatching the video 💀

rich adder
#

haha almost a case of rubber ducking

smoky river
#

how do i stop this from happening?

#

when i jump and hold right it just flings

rich adder
#

what is this ?

smoky river
rich adder
#

what

#

i can barely tell what is happening

smoky river
#

how do i make it not spin

rich adder
#

please explain the full problem and what it is you tried doing to fix issue and whats not working

#

lock the rigidbody rotation

smoky river
smoky river
rich adder
#

also wtf is up with that mass..

smoky river
smoky river
shy orbit
#

yeah you gotta lock the z rotation

naive pawn
#

the square paracetamol?!

shy orbit
#

to stop it spinning

smoky river
#

it works now thanks

#

but when i hold right

#

it makes me stick

#

to the thingy

rich adder
#

welcome to physics

shy orbit
#

thats probably cause of the mass being so high

smoky river
rich adder
#

nah its because ur constantly applying velocity into a collider

shy orbit
#

ah

rich adder
#

in real life that doesnt happen

smoky river
rich adder
#

you either not apply force if you have obstacles inront of you

#

or use the physics material trick

smoky river
#

yeah im finishing this project and never touching programming again 😭

rich adder
#

more of a physics thing than programming

shy orbit
#

oh yeah you could make the material slippy

smoky river
rich adder
#

yup

smoky river
#

or should i do it with the box collider thingy

#

which one is better

shy orbit
#

if you make the material slippy it wont be getting stuck and itll just slide along

smoky river
rich adder
#

ray is the cleanest

#

if this is a quick project stick to no friction physics material I suppose

smoky river
shy orbit
#

physics material with no friction is slippy material

rich adder
#

if you find coding hard then physics material is the easiest
otherwise you use the rb.SweepTest or Casts

smoky river
shy orbit
#

id just google how to make materials slippy in unity

smoky river
#

alr

shy orbit
#

theyll explain it a lot better than i can

smoky river
#

well not HARD

#

but like

#

coding is alittle complicated and i don't wanna do anything related to the 3 main sciences

shy orbit
#

thats a lot of game development unfortunately

smoky river
#

this is my LAST time touching coding

#

actually maybe not

#

cuz im taking cs as one of my classes next year so i am able to skip chem bio and physics

shy orbit
#

could always do visual scripting if writing code isnt to your liking

rich adder
#

I find it kinda funny how most cs graduates know barely any code or how to actually create a game / application

#

here I am with a culinary degree making games and apps lol

#

though you gotta give to CS there is a lot of good theory, but a lot of students have just that.. All theory and no practical real world usecase

#

(this isn't a slam at you btw, just general observation it reminded me of)

rocky canyon
rich adder
#

or fancy shmanzy lawyer ?

rocky canyon
#

that was my intention.. but here i am 🙂

smoky river
#

i never took cs

#

i meant next year i will have to as a resort to ditch the basic 3 sciences cuz they said minimum 1 science

rocky canyon
#

for just this year?

rich adder
smoky river
rocky canyon
#

this semester i mean..

smoky river
rocky canyon
#

i remember needing to take atleast 1 science class per semester

#

i was just curious how it was for u

smoky river
#

oh no im still in school

#

not college yet

rocky canyon
#

ohh okay.. thast where i was confused 👍

#

carry on 🙂

smoky river
#

for grades 11 and 12 we have an IB system and i can pick SOME subjects

#

AND I CAN FINALLY DITCH CHEMISTRY

#

AND NEVER DO IT AGAIN

rocky canyon
#

lol.. chemistry involved soo much writting i remmeber 😭

rich adder
#

damm what school. lets you do CS

smoky river
#

they said min 1 science and i can pick from chem bio phys and cs

rich adder
#

my school sucked and never offered anything even close to STEM

rocky canyon
#

phys is a great option imo

smoky river
#

like currently at my grade

rich adder
#

lucky then

rocky canyon
#

if u plan on going into game-dev i would say do both physics and cs >8)

smoky river
#

its so ass bruh the teacher barely teaches us anything 😭

rocky canyon
#

welcome to the real world

rich adder
#

thats usually the case for an underpaid teacher

smoky river
smoky river
rich adder
#

most teachers are

smoky river
#

yeah but not at my school

rich adder
#

only college professors usually care about teaching cause they usually get paid big bucks
(not community college ofc)

rocky canyon
#

i found it to be different..
once i hit college it seemed like the teachers could care less..

#

its your money.. go to class or not.. they'd not be affected a bit

smoky river
#

what country should i go to for a college for finance or economics

rich adder
#

depends how much tuition was too

#

if teachers get paid big and you're not learning there are complaints usually . Take schools like havard or NYU

rocky canyon
#

UK, Switzerland

smoky river
# rocky canyon USA

yeah but like each year the country gets worse bro i WANTED but im starting to rethink

#

😭

rich adder
#

Swiss manage rich people money

smoky river
#

is switzerland fire

rich adder
#

it is but prob almost impossible to go there as outsider

rocky canyon
#

yea, USA and UK have Wall Street/ London Access

#

global economics i'd go UK or Switzerland

smoky river
frosty hound
rich adder
#

ops yeah we got. bit carried away here

smoky river
#

guys how do i add the physics material onto my object 😭

#

none of the yt tutorials are telling me

frosty hound
#

Drag it onto your collider* component

rocky canyon
#

u add it to the collider

#

or rigidbody ^

rich adder
frosty hound
#

I forget now

rich adder
#

put it on the collider

smoky river
#

there isn't like a clear tutorial they just explain what it does

rich adder
#

make sure its physics2d mat not physics material

rocky canyon
#

it controls friction

#

basically

#

and bounciness

rich adder
#

you're telling me the entire internet and you cant find, how do you think we learned..

smoky river
rich adder
#

you all want things handed to you without doing some critical thinking work to put effort into

#

2 youtube videos isn't the entire internet. You have a search engine that gives results into other pages and articles, the info is there. you just don't search thats laziness

#

these are important skills even outside of coding..

#

now with all this GPT / "AI" crap everyone wants fed answers and not think for themselves.

rocky canyon
#

just learn by doing.. for example lets take the rigidbody material..
theres only 2 variables on it.. so u can assign it to the rigidbody.. using context clues
then can tweek those variables around to see what happens..

#

there.. you've already figured out what the physics material is.. where it goes.. and how it works..

#

never had to leave the engine 🙂

short hazel
rich adder
rich adder
#

so basically if LLMs went down the newer generation have no more knowledge cause who remembers fed answers when you just wanted the solution

zenith cypress
#

I mainly use it today to find obscure api functions that I keep missing (looking at you Roslyn generators), or to make a like 300 field enum from a provided list from a website because it would take me way longer to do it by hand lol (then I validate the values afterward) LMAOO

short hazel
#

my god the roslyn API

#

I have PTSD

rich adder
#

i treat GPT like a very uhhh obedient secretary lol
"I need a list of 300 names in Json format pronto! "

zenith cypress
rich adder
#

oh god this makes me realize how much stuff really is inside of unity manual that I havent even touched yet

rocky canyon
zenith cypress
#

Still mad it took me years to actually realize the gizmo icon pngs in the dropdown were the real toggle

#

They still do not look clickable

rich adder
#

yeah some UX choices in unity are rough

primal cliff
#

I'm getting this error even though I set what it is earlier in the script

#

this is the line causing the error

naive pawn
#

well does that gameobject have an animator?

rich adder
primal cliff
#

yes it has the animator

rich adder
#

show

primal cliff
#

and the animator also has a controller assigned

rich adder
#

either that or you placed another of this script somewhere else

primal cliff
rocky canyon
#

Debug.Log(anim);

primal cliff
#

I'll check for that

#

the script isn't anywhere else in the scene

rich adder
rocky canyon
#

ahh yes context 🙂 we all love context

primal cliff
#

where should I put that? at the error code?

rich adder
primal cliff
#

somehow it doesn't even log

polar acorn
primal cliff
#

I have

polar acorn
#

If you've put it in Start, before the line that throws the error, and nothing prints then nothing in the scene has that script on it

primal cliff
#

that's not possible though, the object is there and it has the script

naive pawn
#

have you saved and recompiled

primal cliff
#

I pause it and it's still there

#

yeah

polar acorn
#

Show code, show console

rich adder
#

doesnt Start disable the script if there is a nullref somewhere in the start method

rocky canyon
#

place ur bets 🎰

primal cliff
#

console is just this each update, the debug.log doesn't show even if I put it in start (which I have done here)

polar acorn
rich adder
#

true

#

ah update

primal cliff
#

entire script

rocky canyon
#

call it before u try using anim

#

anim.speed

rich adder
rocky canyon
#

before that ^

polar acorn
#

Chances are, it is logging. Did you actually scroll to the top

primal cliff
#

this does rely on another script called dialogue but no changes have been made to it

primal cliff
#

it's the same all the way around

#

and as I have said before, an object called Dialogue has this script and it is not destroyed on starting the scene

rich adder
#

comment out anim.Play then

rocky canyon
#

if anim is null.. u break the script @ anim.speed =

rich adder
#

that log should go in Update

polar acorn
primal cliff
#

okay progress

#

still no log but the error disappears, now I have a completely seperate one

polar acorn
#

Because anim.speed will throw an error if anim is null

#

and we said to put the log before the error, including the one that's scrolled off the screen

primal cliff
#

I think this is just because gamestate is from a previous scene and is dontdestroyonload

rich adder
#

so its not found that component

polar acorn
#

There's nothing in the scene named GameState

primal cliff
#

I'll try doing it from the other scene

rich adder
#

you cannot GetComponent on a null object

rocky canyon
#

progress bb

primal cliff
#

okay so no error and the debug log appears if I load it from the title screen (which goes into cutscene1)

#

only problem is now the dialogue box just disappears

#

AND NOW IT DOESN'T??

#

WHAT

#

fantastic, now it doesn't animate to show the different character faces and names

rocky canyon
#

takes money to make money

primal cliff
#

oh its because I commented it out I'm dumb

safe root
#

So I have problem with one of my enemey's just going through soild walls and not sure why this is happening

primal cliff
#

but it needs to be commented out if I don't want exception

rocky canyon
#

how are you moving the character?

#

transform.position =?

#

if its navmesh u need to exclude the walls from the surface so it bakes around it

primal cliff
rocky canyon
rich adder
#

we dont have crystal ball

safe root
#

As the code shouldn't affect the collision

rocky canyon
#

how are you moving it

rocky canyon
#

if ur using translation.. as i mentioned transform.position =

#

it does not respect collision.. and will shove ur colliders into each other

rich adder
safe root
rich adder
#

this alone tells us its just a rigidbody

rocky canyon
#

check this out

safe root
rich adder
#

well no shit

rocky canyon
rich adder
#

its phasing through walls because ur teleporting and not using the rigidbody

rich adder
rocky canyon
#

lmao

#

use a Rigidbody method to move ur character

rich adder
#

You can still use MoveTowards but yu cant use transform.position =

rocky canyon
#

one of these

safe root
#

But the question is why is it only the one and not the others?

rocky canyon
#

maybe the speed..

rich adder
#

luck

rocky canyon
#

if its moving slowly theres a chance that the collider would realize ur intersecting it. and shove it back out

#

if its moving too fast.. u pass the point of no return and it'd shove u out the other side

rich adder
#

you're basically teleporting without the rigidbody

#

the rigidbody will catchup on the next physics frame

#

by that time you might have already went thru the wall

safe root
#

I see, well thank you

lofty sequoia
#

is there a way to limit the scope of a FindObjectOfType to a specific scene?

rich adder
#

maybe the other Find methods are ig

lofty sequoia
#

you can do a FindObjectOfType with 2 scenes open (as long as they're both open) and it will find a cross scene reference

#

It's how you get around inspector cross scene references

rich adder
#

oh interesting... the other Finds dont do that iirc, i wonder why

#

FindObjectByTag for example iirc doesnt do cross scene

rich adder
#

thats dirty as hell tho

rocky canyon
#

FindObjectOfType has been deprecated

rich adder
#

if(myscenename)
FindObjectOfType

rocky canyon
#

we need to use By type now

rocky canyon
#

then u can sort or unsort

#

w/e u need

rich adder
#

WAIT

#

Unity says thats slow...

#

wTf

#

Note: This function is very resource intensive. It's best practice to not use this function every frame and instead, in most cases, use the singleton pattern. Alternatively if you only need any instance of a matching object rather than the first one you can use the faster Object.FindAnyObjectByType

lofty sequoia
#

I figured I could parent everything in a scene to one GO, but I don't really want to modify everything in the scene

rocky canyon
#

yea, i think its fine for initialization methods tho

rich adder
#

THEN WHY DID YOU EVEN PUT THIS UNITY OR SUGGEST IT IN THE DEPERCATED API

lofty sequoia
#

because you can limit a search by gameobject children

rocky canyon
#

^ yea lots of things u can do with it

rich adder
#

why wouldnt they just put FindAnyObjectByType as primary and then offer the other as more "deep" results

#

silly

#

suggesting the more resource intensive version first is backwards imo

naive pawn
#

maybe FindObjectOfType used to get the first one so it's offering the equivalent first?

#

idk just guessing

rocky canyon
rich adder
rocky canyon
#

i remmeber changing all mine over to the FIndFirst

#

i honestly havent noticed any longer load times

rich adder
#

FindFirstObjectByType i guess has to check the instance ids or whatever to check who was first component added?

rocky canyon
rich adder
#

probably no big deal doing it once in Awake/method regardless

rocky canyon
#

facts

#

Initialization be that way

#

onsceneloads and stuff

rich adder
#

ya or even OnActiveSceneChanged

#

are you me?

rocky canyon
#

my loading screen masks any of that anyway

rocky canyon
rich adder
rocky canyon
#

did u catch it?.. nah still super fast

rich adder
#

"Warming up gemlins"

#

etc.

rocky canyon
#

here ya go.. this is hte one i used.. he goes into great detail

#

and shows how to do random stuff while u wait

rich adder
#

this dude has good vids

rocky canyon
#

very very good

lofty sequoia
rocky canyon
#

easy as this @rich adder

rich adder
rocky canyon
#

soo ur gonna cache all objects?

#

and then find the correct one?

rich adder
#

I was thinking to like just fake the loading to a specific time

rocky canyon
#

as i dont really have enuff stuff to load to cause actual progress

rich adder
#

same

rocky canyon
rich adder
#

my level generated 10 rooms in the beginning the rest are spawned in after

rocky canyon
#

mine just loads gameobject by gameobject

#

this is my level boiler plate..

#

as long as i keep this structure (w/ the gameobjects) the loading screen works on ever scene

#

hes a phony! a big fat phony! 👉

rich adder
#

"wow thats amazing...wait...something isn't right"

#

you're just pretending

rocky canyon
#
  IEnumerator UpdateAdditiveSceneProgress()
  {
      totalSceneLoadProgress = 0f;

      for(int i = 0; i < scenesLoading.Count; i++)
      {
          while(!scenesLoading[i].isDone)
          {
              foreach(AsyncOperation operation in scenesLoading)
              {
                  totalSceneLoadProgress += operation.progress;
              }

              totalSceneLoadProgress = (totalSceneLoadProgress / scenesLoading.Count) * 100f;
              LoadingBar.fillAmount = totalSceneLoadProgress * 0.01f;
              LoadingStatus.text = "LOADING FILES"; //loading scenes

              yield return null;
          }
      }
  }

  IEnumerator UpdateSceneInitializationProgress()
  {
      while(currentSceneInitialization == null || !currentSceneInitialization.isDone)
      {
          if(currentSceneInitialization != null)
          {
              totalSceneInitializationProgress = currentSceneInitialization.totalProgress;
          }

          int sectorIndex = (int)currentSceneInitialization.currentSector;

          // Scene initialization *is done*
          float totalProgress = Mathf.Round(totalSceneInitializationProgress);
          LoadingBar.fillAmount = totalProgress * 0.01f;
          LoadingStatus.text = sectorLoadingStrings[sectorIndex];
          yield return null;
      }

      StartCoroutine(FinishSceneLoading());
  }
``` heres the meat and potatos of it
#

tbh its been so long since i made it.. i forget how it works

#

this is important.. my past self probably thought..

rich adder
rocky canyon
#

ya u do

#

for something like that u can probably find a decent magic number to randomize around

#

3 seconds or so +/- 2 more

#

if u wanna make that loading system it doesn't take too long

rich adder
#

ya I think maybe 5-6 seconds should do. I just feel bad punishing someone who has a fast pc compared to one with slow pc

rocky canyon
#

it does require u to use additive scene and async loading

#

so it may not be something for you

rocky canyon
#

i noticed earlier that SOT lets u escape out of its intro cinematic..

strong wren
#

Could time the loading itself and then enforce the minimum time, if you must do this

rich adder
rocky canyon
#

found out about 200 hrs too late

rich adder
rocky canyon
#

Danny always got legit ideas when he pops in 😃

rocky canyon
#

mine takes 4 seconds for empty scene

#

oh i also used Actions too ^ each of those "Category" gameobjects could or could not have actions

rocky canyon
#

they do various things.. like turn on lights.. make sounds.. etc

#

makes it nice and re-useable

rich adder
#

I need to prewarm my pooling

rocky canyon
rich adder
rocky canyon
#

i enable the world.. b/c i was trying to find things to slow down my loading bar

#

lmao

#

doesn't really do anything

#

the only thing ive found that actually slows it any

rich adder
#

its already in memory

rocky canyon
#

is For Loops

rich adder
#

If you did a Streamable assets I think you can Async load that to put a loading

rocky canyon
#

each container just enables a sub-container

#

i think i was trying to make myself feel like i had accomplished something that day

rocky canyon
rich adder
#

yeah its very good if you're trying to load big files , i guess in 2d no big deal but in 3D if you want to load an entire environment later or those type of big files late its a good usecase to speed up initial load time

#

awesome ! feeling inspired again to continue this project now, got decent ideas from here

rocky canyon
rich adder
smoky river
#

guys i gave my wall zero friction so now my object can't stick to it. i tried giving it a little bit of friction so it can slide slowly but it doesn't work

#

is it because the friction is combined or?

rich adder
#

it was supposed to be on the collider of the moving rigidbody..

rocky canyon
#

^ put it on the rigidbody ^

smoky river
rocky canyon
#

ya, but then ur constantly having to add that material to everything u add

#

vs just the 1 player

smoky river
#

and adding it to the player doesn't fix my problem

smoky river
#

i can't figure out how to make it just slide slowly

rich adder
#

what you did

rich adder
smoky river
rich adder
smoky river
#

likee

#

strafe

#

is that the word

#

like slide down the wall slowly

#

when holding right

#

on the wall

rich adder
#

then you need some type of raycasting

rocky canyon
#

u may need to manipulate the physics material w/ code

rich adder
#

or that ^

rocky canyon
#

when on ground -> this material
when against wall -> that material

smoky river
#

which one is easier

rocky canyon
#

i find it pretty simple to swap out physics materials

#

but its w/e

rich adder
#

you probably still need a cast to figure out when you're on wall slding down

smoky river
#

and switch it back when im on the ground?

rich adder
#

well one that uses a lower friction value

#

then put it back

smoky river
#

when i put the friction > 0 is just sticks and when its 0 it just slides normally and not slowly like i need it to

#

how do i fix ts

rich adder
rocky canyon
#

i forgot my old math classes

#

whats Mean

smoky river
smoky river
rich adder
#

yea

rocky canyon
#

thats what im thinking.. its similar but not the same..

smoky river
rich adder
rocky canyon
#

1, 2, 3, 3, 4 average = 2.6
the mean i think is 3

rich adder
#

or maybe something to do with the middle number

#

forgot tbh lol

smoky river
rocky canyon
smoky river
rocky canyon
rich adder
#

yeah okay so average has different averaging "modes" ?

rocky canyon
#

lmao.. i have a new mission for today

rich adder
smoky river
rocky canyon
#

dont add it to both the collider and the rigidbody

#

the rigidbody automatically covers all colliders

#

and the value of friction goes from 0 - 1 just so u know

#

.1 probably is barely noticeable

sharp abyss
#

does anybody know how can I prevent this while flipping my character?Should I just flip its head?

rich adder
smoky river
rich adder
#

ok so it is working tho
you said it dosnt affect it at all

sharp abyss
rocky canyon
#

try to make it 1 and make sure its actually working

#

once u know its working move to code

smoky river
#

i meant that it doesn't change based on what i do with it

sharp abyss
rich adder
smoky river
rocky canyon
rich adder
#

if its still sticking 0.1 try a lower value or youd have to manually code the falling by overriding the velocity

smoky river
#

0.1 is the same as 0.9 etc etc

rocky canyon
#

maybe u can use a more accurate method to detect collisions to stop it

#

else u might want to use a bigger overall collider

rich adder
rocky canyon
#

so they cant get close enuff to each other to have their limbs twist together

#

you may just want to change ur gravity and be done with it 😛

sharp abyss
rocky canyon
#
    if (isWallHit && !isGrounded) // Stick to the wall
    {
        velocity.y = reallyLowGravity;
    }
smoky river
#

i just need to look for the perfect value which will take some time

#

and im putting it on the wall only this time

rocky canyon
#
    else
    {
        velocity.y = normalGravity;
    }```
rocky canyon
#

glad u got it figured out

rich adder
#

experiment

sharp abyss
#

I thought about adding a big box collider over the character and only making it active the second Im flipping but havent tried yet

rich adder
#

the heart of dev

smoky river
rich adder
earnest wind
#

uhm how can i make a IEnumerator run smoothly based on time.timescale?

smoky river
#

so now its 0.01 but still doesn't work

rich adder
rocky canyon
#

i had a problem like this yesterday... Ienumerator wasn't fast enuff so i had to use Update loop timer..

rich adder
#

wdym "smoothly based on timescale?"

earnest wind
rocky canyon
#

but thats not the same issue as here..

#

why not use WaitForRealSeconds

#

or w/e that is

rich adder
rocky canyon
#

scaled time

earnest wind
rich adder
earnest wind
#

i mean, not run

earnest wind
#

okay thanks

rich adder
naive pawn
#

@rich adder @rocky canyon both average and mean have several meanings, but the most common meanings of both are the same, arithmatic mean µ = 𝛴𝑥/𝑁

rocky canyon
#

yield return new WaitForSeconds(1f);
yield return new WaitForSecondsRealtime(1f);

#

ya, i did some researching

#

it seems in most cases its almost the same

rich adder
#

ya seems so what i read too

rocky canyon
#

its confusing how the material has both options tho

#

still trying to figure out what exactly is the differing factor

naive pawn
#

"mean" is the mathematical term and there's also geometric and harmonic mean

naive pawn
acoustic belfry
#

hey, this should make proyectiles enter into their parry state, but they dont, what im doing wrong?

   private void MeleeAttack()
   {
       Vector2 MacheteRange = new Vector2(attackRange, attackRange);
       Collider2D hitEnemy = Physics2D.OverlapBox(machetepos.transform.position, MacheteRange, 0f, demons);
       Collider2D hitProyectile = Physics2D.OverlapBox(machetepos.transform.position, MacheteRange, 0f, proyectile);

       if (hitEnemy != null)
       {
           if (hitEnemy.TryGetComponent(out EnemyBase enemy))
           {
               enemy.TakeDamage(meleeDamage);
           }
       }
       if (hitProyectile != null)
       {
           if (hitProyectile.TryGetComponent(out MortemRifleProyectile enemy))
           {
               enemy.Parry();
           }
       }
   }```
proyectile:
```cs
using UnityEngine;

public class MortemRifleProyectile : MonoBehaviour
{
    public int damage = 5;
    public Rigidbody2D rb;
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.transform.TryGetComponent(out ValeriaController enemy))
        {
            enemy.TakeDamage(damage);
            Destroy(gameObject);
        }
    }
    public void Parry()
    {
        Debug.Log("PARRY");
    }
}```
rocky canyon
naive pawn
rich adder
#

wall of code

rocky canyon
naive pawn
#

oh 2d

#

mean there is geometric mean

#

sorry, geomtric mean

swift crag
rocky canyon
#

ahh soo thats what it is

swift crag
#

ah, you just posted it

rocky canyon
swift crag
#

Aha

rocky canyon
#

i think Chris has the solution tho..

swift crag
#

Geometric mean strikes again

rocky canyon
#

Geometric mean

acoustic belfry
rich adder
#

Debug.Log what else

#

the first step to solving any problem

naive pawn
acoustic belfry
rich adder
#

you havent logged anything useful before it gets there

rocky canyon
#

Mean algorithm used is: SquareRoot(valueA * valueB)
Average algorithm used is: (valueA + valueB) * 0.5

@swift crag @naive pawn @rich adder

acoustic belfry
#

ah, you mean to also Log the parring of the weapon?

rich adder
#

step by step and see where its going wrong

naive pawn
rocky canyon
#

Log the line!

rich adder
#

dont just put random useless strings

rocky canyon
#

log until u get something u dont expect

rich adder
#

put the actual objects to log

rocky canyon
#

then u found the crack

rocky canyon
acoustic belfry
rich adder
acoustic belfry
#

holup, i think it fixed...idk why tho

#

but it works :3

rich adder
#
void OnDrawGizmos(){
Gizmos.color = Color.yellow
Gizmos.DrawCube(machetepos.transform.position, range);
}```
acoustic belfry
#

but i already have Gizmos

#
    void OnDrawGizmos()
    {
        Gizmos.color = Color.red;
        Vector2 MacheteRange = new Vector2(attackRange, attackRange);
        Gizmos.DrawWireCube(machetepos.transform.position, MacheteRange);
    }
}```
rich adder
#

if its correct pos/size in game, your layers are either wrong or something else

#

could also be hitProyectile.TryGetComponent(out MortemRifleProyectile enemy) is false

#

or the nullcheck

acoustic belfry
#

but i mean, now it works

rich adder
#

🤷‍♂️

rocky canyon
#

dont look at it for too long

acoustic belfry
#

have you managed to do something and then feel that it was actually bad?

#

i mean cuz the proyectiles reflect by their own, it works...idk why but feels off

#

nah, nvm, i like it