#💻┃code-beginner

1 messages · Page 512 of 1

languid spire
#

PC/Mac/Linux. NOT Mobile, WebGL

slender nymph
#

did you follow the instructions i just gave you? if no, then fucking do that.

rancid tinsel
slender nymph
#

if yes, then screenshot the entire visual studio window with the solution explorer visible

languid spire
stone pilot
slender nymph
#

show what you've done

stone pilot
#
    {
        leftLegRB.AddForce(Vector2.right * (speed));
        yield return new WaitForSeconds(seconds);
        rightLegRB.AddForce(Vector2.right * (speed));
    }

    IEnumerator MoveLeft(float seconds)
    {
        rightLegRB.AddForce(Vector2.left * (speed));
        yield return new WaitForSeconds(seconds);
        leftLegRB.AddForce(Vector2.left * (speed));
    }```
#

removed the 1000 and the deltaTime

slender nymph
#

was the the only instruction you bothered following?

rancid tinsel
echo sand
#
    void ChangeWayPoint()
    {
        Bounds Bounds = WanderingArea.GetComponent<MeshRenderer>().localBounds;

        float DY = WanderingArea.transform.position.y;

        float DX = Random.Range(-Bounds.extents.x, Bounds.extents.x);
        float DZ = Random.Range(-Bounds.extents.z, Bounds.extents.z);

        Vector3 Destination = new Vector3(DX,DY,DZ);

        Agent.SetDestination(Destination);
   }
``` im trying to get a random position in a plane but its not working for some reason?
stone pilot
#

leftLegRB.AddForce(Vector2.right * speed, ForceMode2D.Impulse);

#

should it be like this?

velvet mulch
languid spire
rocky canyon
slender nymph
fast tendon
#

i have just created a completely new project, i have the latest version installed yet it still shows this

rancid tinsel
#

thank you

echo sand
#

but im using local bounds tho

severe acorn
# velvet mulch relax dude Im new to unity

That’s not unity related, is visual studio related, if you never used visual studio in the first place I recommend ya yo learn the basics first instead of going directly to unity learning

rocky canyon
# echo sand ye im trying to use local space so it works with rotated planes aswell
void ChangeWayPoint()
{
    Bounds bounds = WanderingArea.GetComponent<MeshRenderer>().bounds;

    // get the world position
    Vector3 center = WanderingArea.transform.position;

    // random local offsets
    float DX = Random.Range(-bounds.extents.x, bounds.extents.x);
    float DZ = Random.Range(-bounds.extents.z, bounds.extents.z);
    
    // Create the new random destination, applying the offsets to the center
    Vector3 destination = new Vector3(center.x + DX, center.y, center.z + DZ);
    Agent.SetDestination(destination);
}```
slender nymph
fast tendon
#

but until then how can i do almost anythign iwthout a code editor?

slender nymph
echo sand
#

ah i see, mb ty

fast tendon
languid spire
rocky canyon
velvet mulch
slender nymph
fast tendon
#

where can i submit a bug report?

slender nymph
rocky canyon
#

i've also wondered if there was computer skill issues... best i can say
is : if u continue to have troubles my solution would be to Install the Unity version you want w/ Visual Studio selected in the modules.. (it should (this way) configure it as it installs)

slender nymph
#

let me guess, you had regenerated the project files before but you only just now restarted visual studio?

rocky canyon
#

🧐 sus

velvet mulch
#

shut up yall not even helping

slender nymph
#

that's 100% a "yes"

rocky canyon
#

now ur dilusional

#

ive seen many people trying to help u..

#

dont be ridiculous and say u haven't

echo sand
severe acorn
rocky canyon
#

ohh nvm extents. is half

echo sand
rocky canyon
#

u could debug it a bit more

#

see if u can tell how far out of bounds it travels

velvet mulch
rocky canyon
#

or just give it the min and max values as a test

#

and see what its doing

rocky canyon
# echo sand its kind of working, its also going out of bounds tho
    // Calculate the min and max world positions based on the bounds
    float minX = center.x - bounds.extents.x;
    float maxX = center.x + bounds.extents.x;
    float minZ = center.z - bounds.extents.z;
    float maxZ = center.z + bounds.extents.z;

    // Log the bounds and world limits for debugging
    Debug.Log($"Bounds: MinX={minX}, MaxX={maxX}, MinZ={minZ}, MaxZ={maxZ}");
#

that shuld be ur limits

echo sand
#

ur right it was halved for some reason. i put (* 2) not it works UnityChanThumbsUp

stone pilot
#
    {
        leftLegRB.AddForce(Vector2.right * speed, ForceMode2D.Impulse);
        yield return new WaitForSeconds(seconds);

        rightLegRB.AddForce(Vector2.right * speed, ForceMode2D.Impulse);

        ClampVelocity(leftLegRB);
        ClampVelocity(rightLegRB);
    }

    IEnumerator MoveLeft(float seconds)
    {
        rightLegRB.AddForce(Vector2.left * speed, ForceMode2D.Impulse);
        yield return new WaitForSeconds(seconds);

        leftLegRB.AddForce(Vector2.left * speed, ForceMode2D.Impulse);

        ClampVelocity(leftLegRB);
        ClampVelocity(rightLegRB);
    }

    void ClampVelocity(Rigidbody2D rb)
    {
        float maxVelocity = 5f;
        rb.velocity = Vector2.ClampMagnitude(rb.velocity, maxVelocity);
    }``` 
Hmm this works but makes the gravity a bit shitty..
rocky canyon
#

thats b/c when u modify velocity directly.. its overwritting it

#

soo w/e gravity you've included. whatever way.. like AddForce for example.. that'd get clamped as well

#

u could instead check if ur over ur threshold and still use AddForce for it if ur under

#

that'd be pretty close to a limiter

#
  Vector2 clampedVelocity = new Vector2(
        Mathf.Clamp(rb.velocity.x, -maxHorizontalVelocity, maxHorizontalVelocity), 
        rb.velocity.y
    );
``` you could also try clamping horizontal forces and ignoring vertical ones..
stone pilot
#

Alright thanks for the help but my lap went off.. when it goes back on I'll be trying that (I'm on my phone)

timber comet
#

This is for a multiplayer game (with client ownership)

burnt vapor
rocky canyon
rocky canyon
#

might be something to look for

#
        if (networkIdentity.isMine) // Only control if this object belongs to the local player
        {
            HandleMovement();
        }```
#

what are you using to build your multiplayer?

timber comet
timber comet
#

netcode is a lot more difficult

rocky canyon
#

im going on 4 years and i still havent done a mutliplayer project (past joining a lobby and starting)

#

got a jumpstart on me lol

rocky canyon
#

soo many people i see.. like "oh i made this big singleplayer game, how hard would it be to convert to multiplayer Now"

timber comet
rocky canyon
#

you'd use it anytime u want to only run code on a local version of something

#

just an example, not a real component or anything btw

#

the isMine thing was just the main point i was making

#

without it.. everyones inputs would be trying to move everyones players 😅

timber comet
rocky canyon
#

basically... imo it'd be harder

#

gotta start that stuff as soon as possible.. so ur rewriting as little as possible

timber comet
#

Thx a lot btw

polar acorn
burnt vapor
#

This is painfully true

timber comet
clever raven
polar acorn
long jacinth
#

Hello im making a game where each cities u can build buildings and stuff so my idea is that every city has a list called buildings and the list will have different types ** but i want those types of buildings to have their variables that contain levels and costs and stuff and i want it to also be accessable from the city script that the list is in**, how can i approach this idea

rich adder
long jacinth
#

scriptable object it is i guess but the problem is

#

i want each city to have its own factories that have their own levels and costs

rich adder
#

scriptable object thats what they're for

#

or just use a regular POCO thats serialized, you just have to create all your buildings in an array / inspector which may not be ideal compared to actual assets

long jacinth
#

whats a poco

rich adder
#
public class Building {
public int Cost;
public int Level;
}```
long jacinth
rich adder
#

but with scriptable object is better because its saved on disk and easier to access modify later on or create more of them with 1 button click

long jacinth
#

ok ig i can do that

rich adder
#
[CreateAssetMenu(fileName ="BuildingData")]
public class BuildingData : ScriptableObject {
public int Cost;
public int Level;
public Sprite Icon;
public Tranform prefab;
}```
long jacinth
rich adder
#

you can also use the menu name to assign custom categories and paths

rancid tinsel
#

is there a way of eliminating non-english alphabet characters when reading a text file into a list?

#

or even just spaces

rich adder
#

string.replace probably or regex

rancid tinsel
#

can you replace " " with ""?

languid spire
#

but anyway regex is the way to go. good luck figuring out how to use it correctly though

white obsidian
#

how do i reduce a certain objects box collider if it's already deleted, for example : i deleted a wall but forgot to reduce its collider, now i can't shoot through that place

wintry quarry
#

Find that object and modify it

rich adder
long jacinth
white obsidian
wintry quarry
rich adder
clever raven
rich adder
clever raven
#

For example I am making a tile based game right now, each tile has an associated object that holds all the info on the tile such as it's sprite, type, name, etc

white obsidian
#

I'm sorry for the nonsense i might speak :D, I'm pretty new, so i made a wall for a level let's say then i duplicated my level and deleted the levels left wall, i can move through the space, but i can't shoot fireballs through it, is it colliders issue or for what should i look?

rich adder
polar acorn
wintry quarry
#

You can also have your fireball code print the name of the object it collides with

#

(and ping it in the hierarchy)

white obsidian
#

I did this, and deleted the left wall from the Red square i pointed out

rancid tinsel
languid spire
rancid tinsel
#

i guess ill test the performance on this and look into regex if needed then

languid spire
rancid tinsel
#

i feel like doing it char by char would be awful performance-wise

#

idk if string.replace works any different though

languid spire
#

at the end of the day, whatever method you use, will have to do that

rich adder
naive pawn
long jacinth
naive pawn
slate marten
#

hi little sigmes

eternal needle
slate marten
#

im new

#

im a low level beginer

long jacinth
rich adder
eternal needle
slate marten
#

sorry im a skibinngerrsigaretforcebrute

#

im a friendly guy

languid spire
#

and still spamming after being told to stop

slate marten
#

here we can learn more about scripting or we only ask questions or help? im new to this server

slate marten
#

smith

naive pawn
rich adder
slate marten
#

what

long jacinth
steep rose
eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

slate marten
#

thanks senior skibidi

rich adder
steep rose
slate marten
#

i think its better unity thing because is more specific etc

rich adder
#

Unity is nothing more than an API / and Bunch of components. You still need core C# under your belt

slate marten
#

not to much

#

for what i know its the most things different

steep rose
long jacinth
rich adder
slate marten
steep rose
rich adder
steep rose
slate marten
#

yes but i need C# only for unity not for other things

rich adder
slate marten
rich adder
#

what changes is how you use that code

slate marten
#

it has different things

rich adder
#

thats nothing to do with C#

slate marten
#

the most of the codes are for component on unity

rich adder
#

thats the Unity API

slate marten
#

how i know i can have addforce on rigidbody2d

rich adder
#

you need C# understanding to know how to use it

slate marten
#

if i dont learn

steep rose
#

as I said, it teaches you the basic functions of unity, not in depth C#

long jacinth
rich adder
#

yes but if you dont know what a function is or where to place youd have no idea

steep rose
#

you would want to learn C# to use unity correctly

short hazel
#

Unity uses intermediate to advanced concepts of C# that are better off learned outside of Unity first. Like everything related to object-oriented programming

rich adder
slate marten
rich adder
#

this is why you don't learn in unity first

short hazel
#

void is the return type

slate marten
#

in unity u dont use functions

#

as what i know

slender nymph
mossy bay
rich adder
slate marten
rich adder
#

void are literally return types for functions..
hence they're called functions not voids

steep rose
slender nymph
runic lance
slate marten
#

in unity when u use functiosn?

#

never seen it

slender nymph
#

yes you have

steep rose
slate marten
rich adder
white obsidian
#

what do i do to fix my autocompletion in visual studio in unity, i did go to edit >> preferences >> and it is on visual studio, however, when i restart my unity hub it goes to visual studio code for some reason and i need to manually do it again all the time, but even tho it is on visual studio there's still no autocompletion

rich adder
#

AddForce is a function

slate marten
slate marten
#

wait

slender nymph
slate marten
#

its comes from vodis

rich adder
#

might need to assign it a couple of times and restart unity to fully affect

slate marten
#

why void is blocked for a word?

rich adder
#

can you not spam nonsense

slender nymph
# slate marten well its voids

we have already explained to you why that is wrong. void is the return type. the block of code you write that has a return type of void is still called a method or function

#

calling them "voids" is incorrect

short hazel
#

This is a "function":

void Start() { }

as well as this:

int Sample() { return 42; }

In C# they're called methods, not "voids". What would you call my int Sample() example? An "int"??

slate marten
#

its hard to learn too because im not totaly ennglish

#

what the hell is that
int Sample() { return 42; }

short hazel
#

A method

slate marten
#

yea i learned eng but im not totaly

slate marten
rich adder
short hazel
#

Well now you've seen one lol

slate marten
steep rose
slate marten
#

what you mean

short hazel
#

They're not that different from the ones returning void

languid spire
rich adder
slate marten
steep rose
#

I have zero clue if you are trolling

slate marten
#

how much did take you to learn it

rich adder
slate marten
slate marten
rich adder
slate marten
#

im born in europe

slate marten
steep rose
rich adder
# slate marten wydm

coding isn't the only part of developing, thats just a tool to a much bigger picture

slate marten
white obsidian
# rich adder fix it in the preferences

yeah, ty, it helped with the problem with opening in vsc, but autocompletion is still not working for some reason, i saw a tutorial where it said to regenerate project files, i did that, still autocompletion doesnt work, maybe you have an idea how to fix that?

slate marten
#

wich one

short hazel
#

I thought "wdym" and the like answers were blocked by the antispam bot

slate marten
#

which one

steep rose
#

I never said his native language isnt english.

slate marten
#

why

#

idk where to start

steep rose
#

we gave him some, he does not want to use them

slate marten
rich adder
slate marten
#

what the hell is vsc

#

im using vs

steep rose
rich adder
short hazel
#

lol

steep rose
slate marten
steep rose
#

okay then, you must learn if you would like to use unity

slate marten
#

u mean when i finish the other or now

#

btw thans for searchnig it up for me

steep rose
#

you would either look for more tutorials for C# and Unity or start making a project using the things you learned

#

then come back here and ask questions

slate marten
#

i think i would not

#

too poor

rich adder
slate marten
#

better

short hazel
#

Wouldn't recommend buying stuff when free things can be better

steep rose
#

but don't cling onto tutorials or else you will solely rely on them which you do not want when building game

white obsidian
slate marten
#

btw what is vsc

steep rose
slate marten
steep rose
slate marten
#

what changes from vs

#

i already use vs

#

i know some things in unity

steep rose
slate marten
#

ide?

slate marten
#

im not english

short hazel
#

You sound like a little kid

#

Asking questions at an extreme rate

slate marten
#

i dint say i was english

steep rose
#

its the basic tool for programmers

slate marten
#

why people when u are not english think ur stupid like what

#

its nosense

#

if know how to speak english doesnt mean im fully eng

steep rose
#

ofc

slate marten
#

im not christian im not religionic

steep rose
#

he was speaking to me, also I would recommend bringing your life to Christ

hardy jewel
slate marten
#

bro like what

short hazel
#

This is a code channel people, let's keep stuff on topic

#

Make a thread or take it to DMs if you want to continue this conversation

slate marten
steep rose
slate marten
#

why this dude is saying poor me like what

#

ok

steep rose
#

once you are done with the courses and understand them, make a project and start making a simple game

#

if you have questions along the way, please !ask

eternal falconBOT
slate marten
#

🫡

oak kelp
#

how can i get Generate constructor when i press Ctrl + it doesnt give me a option to do that

polar acorn
#

Are you trying to generate a constructor for a MonoBehaviour

oak kelp
#

yes trying too

slender nymph
#

is there a specific reason you need a ctor on a MonoBehaviour? because you shouldn't be instantiating those manually anyway

oak kelp
#

well its not with MonoBehaviour its with PlayerState

slender nymph
#

does player state inherit from MonoBehaviour

oak kelp
#

yes

slender nymph
#

then it is a monobehaviour and my previous statement stands

oak kelp
#

i have it like this

public class PlayerIdleState : PlayerState

slender nymph
#

and if it inherits from monobehaviour then you should not be calling its constructor

stiff abyss
#

Hello

slender nymph
#

is there a reason it inherits from MonoBehaviour?

oak kelp
#

i still learning

astral falcon
#

So PlayerState is just a class

slender nymph
oak kelp
#

thx

#

i am wondering why my letters are not green in is Script

slender nymph
#

Configure your !IDE

eternal falconBOT
oak spear
#

Hey guys im new in c# and i dont know why the variables isnt shown in the game. Any ideas?

polar acorn
#

Show inspector of this component

ivory bobcat
#

The values from the declaration of the field are only the defaults

polar acorn
# oak spear

That seems to be exactly what your screenshot shows, what's the problem?

ivory bobcat
#

Once the object has been created, whatever value you've set them will become the new value - set through the inspector.

oak spear
#

So the values I set in the code wouldn't work, only in the inspector right?

ivory bobcat
#

Reset the component and you'll see that they are the default initialized values but you can change them - which you have.

ivory bobcat
oak spear
ivory bobcat
#

The values assigned during the declaration of the variables are only the default initialized values.

oak spear
#

tysm it worked when I reseted it ❤️

long kayak
#

I have no coding experience but wanted to ask about the possibility of something. Can I write a script for this?
My problem:
I work with 100s of materials per .blend file and want unity to automatically assign the textures to the proper materials, my diffuse and normal map import just fine but the roughness never goes to the gloss map, I have to import them manually and it takes forever. I've already inverted the rough to make a gloss through photoshop. Honestly I've been having ChatGPT write the script and it never works. Yes I know that's probably bad... Please help <3

Blender : shader (example)
ximage_658d180e02a375a3.tga - color
ximage_2c89f70020bd2728_Gloss.png - roughness
ximage_2c89f70020bd2728_normal.png - normal

unity shader : Bumped Specular SMap (what I want)(example)
ximage_658d180e02a375a3.tga - diffuse/specular
ximage_2c89f70020bd2728_Gloss.png - glossmap
ximage_2c89f70020bd2728_normal.png - normalmap

astral falcon
long kayak
#

wdym how did I assign the textures? you mean in Blender?

astral falcon
#

Oh you mean the standard import of your file is setting the wrong textures, my bad

ember tangle
#

Why do I have to multiply by -1 in Physics2d raycasting for the mouse position to work?
Vector3 relativeMousePosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, camera.transform.position.z * -1);

astral falcon
#

Because 0 is your camera pos. so you are shooting nowhere in 3d space

long kayak
ember tangle
astral falcon
ember tangle
#

It has to

#

Dev post: Raycast/Linecast for 2D take Vector2 not Vector3 because they operate along the X/Y plane only as it’s 2D physics not 3D.

#

yet, if I don't multiply by -1 it doesn't work.

astral falcon
#

And if you just set it to vector2?

astral falcon
ember tangle
#

I understand all of that, but this in the context of the Physics2d function and the requirements to get it working. camera.ScreenToWorldPoint(relativeMousePosition)```` is being taken as a Vector2 argument anyway RaycastHit2D hit = Physics2D.CircleCast(camera.ScreenToWorldPoint(relativeMousePosition), 0.25f, Vector3.zero, 0);```

#

yet it literally wont work without that third dimension

north kiln
#

Why are you doing a cast with zero distance

ember tangle
#

cast at mouse point

north kiln
#

Nope. Use overlap circle

ember tangle
#

it all works perfectly and performs well, I just want to know why the -1 is needed

#

overalp circle is probably more elegant. Still not sure on that -1

north kiln
#

I can only presume that somehow depth matters in this situation, and presumably being at the camera position doesn't work, only in front of it does

#

but OverlapCircle might just fix the issue

astral falcon
#

I guess, thats why the docs use the nearclipplane in 2D, just to have the correct position for the interaction in 2D space with the flattened clip plane distance.

normal turret
#

How does slope-handling in Unity work...?

#

Looks like everything is working but I came to a problem...

#

The movement and animations work fine but when I jump and land on a slope, it doesn't immediately change to idle, it still falls when I land on the slope

#

Is the slope detected in the ground check...?

astral falcon
normal turret
#

I might watch some YouTube tutorials on slopes for Unity 2D...

#

Everything works fine (except for the jumping animation, I have to also figure out why that's not playing fully)

#

I just have to watch some slope tutorials to add to my ground check maybe

astral falcon
# normal turret I might watch some YouTube tutorials on slopes for Unity 2D...

If the tutorial addresses this issue, you might have to rewatch it and read the code provided. But apart from that, I am guessing, that you have some kind of animator with a transition from falling to next state which is taking too long. But thats something you can easily debug log, log when it hits the slope and log, when the animation turns from falling into slope

normal turret
#

So for slopes I don't have to do anything special apart from just setting the velocity of the player to 0 (to prevent it sliding)...?

#

I saw they were doing that in one of the tutorials, I might add that soon

astral falcon
#

yeh, but not the issue right now, stick to the problem you introduced and show the code addressing the behaviour

clever raven
#

Anyone have any tips on how to generate a random number of rooms between my minRooms and maxRooms? The code I am trying right now is only do the min rooms and I know I can do better. I am not sure how random works in Unity. Anyone know how I can improve this loop:

int maxAttempts = maxRooms * 5;

while (rooms.Count < minRooms && attempts < maxAttempts)
wintry quarry
clever raven
#

Now I guess I just need to google what type of distribution Random.Range uses haha, Thank you

wintry quarry
#

a uniform distribution

viscid cliff
#

so i've just started working on an fps project and am very inexperienced; for some reason, my jump function sometimes sends my player incredibly high and i don't know why.

#
if(Input.GetKeyDown(KeyCode.Space) && isGrounded)
        {
            Player.AddForce(jump * jumpSpeed, ForceMode.Impulse);
            isGrounded = false;
        } ```
teal viper
#

Btw, the correct way to share C# code is ```cs

viscid cliff
#
public Vector3 jump;
    public float jumpSpeed = 2.0f;```
teal viper
#

Why do you need both jump and jumpSpeed? What does the jump variable represent?

viscid cliff
#

honestly i'm not quite sure

teal viper
#

Did you not write that code?

viscid cliff
#

i'm still trying to figure literally everything out

teal viper
#

In this case, I'd suggest going over the beginner pathways on unity !learn

viscid cliff
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

ember tangle
normal turret
#

That and some other main problems: the jumping, falling and double jumping animation logic works but the whole animatino doesn't play

north kiln
normal turret
#

And also some parts of the tiles have like invisible collisions which stop me for some reason

north kiln
normal turret
#

This is my ground check code so far:

        RaycastHit2D collisionDetection = Physics2D.BoxCast(boxCastCollision.bounds.center, boxCastCollision.bounds.size, 0.0f, Vector2.down, rayCastDistance, tileSetLayer);
        return collisionDetection.collider != null;
    }```
restive linden
#

I've got people that tested my game and have saved files already. Now that the game is releasing I want a way to delete old save data. What would be the best way to go about that? I was using a playerprefs for currentgamevers and if it's older than a certain number I delete. Does that work find? Or should I do something else?

restive linden
#

so I check if the playerprefs is updated to the new version. If it isnt I update it and delete all data

rich adder
#

another reason not to use PlayerPrefs

restive linden
#

checking date could work

ember tangle
topaz fractal
#

the code is the EXACT same for me and the tutorial, yet for some reason when i play, this happens

#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Floater : MonoBehaviour
{
    public Rigidbody rigidBody;
    public float depthBeforeSubmerged = 1f;
    public float displacementAmount = 3f;    

    private void FixedUpdate()
    {
        if(transform.position.y < 0f){
            float displacementMultiplier = Mathf.Clamp01(-transform.position.y / depthBeforeSubmerged) * displacementAmount;
            rigidBody.AddForce(new Vector3(0f, Mathf.Abs(Physics.gravity.y) * displacementMultiplier, 0f), ForceMode.Acceleration);
        }
    }
}

#

Here is the code

#

The block is supposed to act as if its floating on the plane

#

like its in water

#

the video is from 4 years ago, so possibly one of the methods i referenced isnt around anymore?

wintry quarry
#

First step first: open your console window in the unity editor and keep it open always

#

That way you can see any errors that are happening

topaz fractal
#

got it

wintry quarry
#

Second step would be to add debug.log statements into your code at strategic points so you can see if and when specific code you expect to run is actually running

topaz fractal
#

an example would be where, in the code is sent

wintry quarry
#

Where the force is added

topaz fractal
#

so from that i figured out why it wasnt being called

#

he set ocean level to 0 on unity map, changed it to 1000

#

its being called now, but its not floating, any tips?

#

just moved it all to 0 and fixed

cosmic gorge
#

!code

eternal falconBOT
cosmic gorge
#
{
    // References //

    private CharacterController Controller;

    // Movement Settings //

    [SerializeField] private float moveSpeed = 5f;

    // Input //

    public float moveInput;
    public float turnInput;

    private void Start()
    {
        Controller = GetComponent<CharacterController>();

    }

    private void Update()
    {
        InputManagement();
        Movement();
    }

    private void Movement()
    {
        GroundMovement();
    }

    private void GroundMovement()
    {
        Vector3 move = new Vector3(turnInput, 0, moveInput);
        move.y = 0;

        move *= moveSpeed;

        Controller.Move(move * Time.deltaTime);
    }

    private void InputManagement()
    {
        moveInput = Input.GetAxis("Vertical");
        turnInput = Input.GetAxis("Horizontal");
    }
}
cosmic gorge
cosmic gorge
teal viper
# cosmic gorge

You should be looking at the unity console for errors, not wherever that screenshot is from.

#

You should be looking at it at runtime too. There might be runtime(not compile) errors.

cosmic gorge
#

thank you

teal viper
#

Lastly, when confirmed that there are no errors, start debugging your code. Use debug logs to debug relevant values. Start from the bottom-up - from the closest code to actual movement.

cosmic gorge
#

so sorry lmao

#

oops

#

wrong reply

teal viper
cosmic gorge
#

i was wondering how to look at runtime errors, but i figured it out

#

sorry to bother

#

mbmb

#

got my script working, thanks for your help :D

fickle wagon
#

Hi, friends, I am having trouble finding the build report from the console -> Editor.Log I am using a Mac, and attached is the build report I got, When I was using Windows I got a full report for each texture and their sizes on mac there are no sizes appear. (BTW I'm building for web).

fickle wagon
#

Yes, I did exactly but I see details only if i build for android not for web. @astral falcon

languid spire
fickle wagon
#

Oh, certainly I'll clean build my project @languid spire

#

Data appear when clean build Thanks @languid spire

sturdy wharf
#

hey,
I have a simple 2D game in unity, where there is a little stickman with differnt parts of his body (left leg, right leg, left arm, right arm, head, torso) all with rigid bodies and stuff and i have a script where i can click and drag around the stickman and he moves and interacts with phyics and stuff. For ages i was trying to make a code where the stickman gets up and then walks using animations and stuff, but becuase the game is very physics based i thought it would be cool to make the walking phyics based too, kinda like games like TABS and Stick It To The Stickman. the only issue is, im very bad at coding haha. so i kinda just putting this here as almost a thought thing, where u guys can give me a general idea of how to make like phyics based walking (or if u know a tutorial) or if u wnated to actually help write the code. thanks !

rare basin
#
private void UnloadLoadingSceneAndFadeOut()
{
  var activeScene = SceneManager.GetActiveScene();
  Debug.Log("Current active scene: " + activeScene.name);
  Debug.Log("Unloading loading scene");
  
  AsyncOperation unloadOperation = SceneManager.UnloadSceneAsync(activeScene.name);
  unloadOperation.completed += (AsyncOperation operation) =>
  {
      Debug.Log("Loading scene unloaded successfully");
      isSceneLoaded = true;
      OnSceneLoad?.Invoke(currentScene);
      fadeScreenCGT.TurnCanvasGroupOn(false);
  };
}

why am i getting null reference exception in this line unloadOperation.completed += (AsyncOperation operation) =>, the prints are correct

#

the unload scene async doesnt even work, the scene is not getting unloaded

burnt vapor
#

If you don't have this, then unloadOperation will be null

#

At least, that's what Google tells me in this case

rare basin
#

there are 2 active scenes

burnt vapor
#

Even the docs do not specify that the return type can be null

keen dew
#

Do you have warnings enabled? It should show a warning if it returns null

rare basin
#

because i use unload on LoadingScreen scene, when the level scene is loaded

burnt vapor
#

Very odd

stuck palm
#

how does this work? like having multiple options in a single enum.

#

is it bitwise operations or something

rare basin
#

i only get this warning

burnt vapor
keen dew
#

so it's the only active scene

burnt vapor
rare basin
#

hmm not sure why, im calling the unload in .completed operation in another scene load

#

but thanks atleast i know where to look

#

maybe it needs 1frame delay or something

#

well it indeed fixed it

#

just wait for end of frame

burnt vapor
reef oracle
#

this is my code...but

#

the bullet wont move...

languid spire
#

start != Start

wintry quarry
#

Debugging tip: If you have code that you think should do something, but isn't doing anything, use Debug.Log to make sure it's actually running first.

#

because this is not

slate marten
#

do it un update not start

wintry quarry
#

no, that's not the issue

#

Start is the correct place

slate marten
#

what

reef oracle
wintry quarry
#

Start is correct

#

start is not

#

start will not do anything

slender nymph
eternal falconBOT
reef oracle
wintry quarry
slate marten
reef oracle
#

Debug.Log.

wintry quarry
#

Yes, put a Debug.Log statement in the code to see if it's running

reef oracle
#

i mean what would i need to write down

languid spire
wintry quarry
#

then check your console window

wintry quarry
wintry quarry
#

which explains your problem

#

(and the reason it's not running, we have spelled out to you several times now)

slate marten
#

black

languid spire
slate marten
languid spire
#

no, at least not for me. For you, only you can say

slate marten
#

its hard or not like beginned or advanced****

languid spire
#

advanced

slender nymph
slate marten
#

ok

slender nymph
#

and then, if you learn the basics you might realize that telling someone to use "else or if" when they are instructed to log info is idiotic and makes no sense

slate marten
#

ok idiotic

reef oracle
wintry quarry
reef oracle
#

it changes my velocity to linearVelocity

wintry quarry
#

or configuired your IDE

wintry quarry
slate marten
#

is better is better addorce or linear

reef oracle
fickle plume
#

!ban save 1178166654774022156 spam

eternal falconBOT
#

dynoSuccess lossantosred was banned.

languid spire
#

which wont make a blind bit of difference as the code does not run in the first place

wintry quarry
#

show the actual error you saw

reef oracle
#

ok..

reef oracle
wintry quarry
#

that's a problem with some other code

reef oracle
wintry quarry
#

click on it and read the full error which will show you which file and line number the error happens in

reef oracle
wintry quarry
#

keep scrolling down..

#

or make the window larger

reef oracle
#

yeah

#

gimme a sec

wintry quarry
# reef oracle

looks like it's the THirdPersonShooterController.

Basically on line 58 it's trying to do something with a Transform, but you destroyed that Transform

#

so it becomes sad

wintry quarry
reef oracle
#

so am i cooked

wintry quarry
#

I don't know what you mean by that

reef oracle
wintry quarry
#

You seem to immediately throw your hands up in despair when you run into issues

#

you will need to change that if you want to be successful in game dev

reef oracle
wintry quarry
reef oracle
#

and have the bullet move

wintry quarry
#

this seems like a pretty basic projectile system. It's not compicated in general, so probably not a lot to change, no.

wintry quarry
#

if your player Transform is being destroyed I would guess you put the script on at least one object it doesn't belong on.

#

or it could be some other code entirely

#

impossible to say without seeing the project/scene.

reef oracle
#

💬 How to make a Third Person Shooter Controller in Unity!
✅ Get the Project Files https://unitycodemonkey.com/video.php?v=FbM4CkqtOuA
🌍 Get my Complete Courses! ✅ https://unitycodemonkey.com/courses
👍 Learn to make awesome games step-by-step from start to finish.
🎮 Get my Steam Games https://unitycodemonkey.com/gamebundle

00:00 Third Person Sho...

▶ Play video
#

I’m watching this dude

#

But I’ll watch again to see if I made any of the errors you said

burnt vapor
eternal falconBOT
burnt vapor
#

It was already mentioned but this screenshot makes it clear you haven't

#

There's no point in helping until you did this

queen adder
#

Is byte immutable or mutable ?

reef oracle
#

i have Visual Studio

burnt vapor
#

You mutate the field that it exists on

#

Same with all value types

wintry quarry
#

but yeah Fused has a good answer

burnt vapor
#

I guess immutability depends a lot on other factors, but without those these are the basics

queen adder
wintry quarry
#

you're not mutating the original 4 value

#

you're overwriting the value stored in b with a totally new value

queen adder
#

Okay thanks

burnt vapor
queen adder
#

Ah i see, okay thanks

wintry quarry
#

It's almost a moot point because there's not really a way to "refer" to a struct - you can have variable references with ref but that's the variable

burnt vapor
#

Even a string, which is not a value type

#

But a string is hardcoded to be immutable

#

But strings are weird in general

ruby python
#

Hi all, If you would indulge me, I've had an idea of how to spawn enemies in my asteroid belt game. But I'm not entirely sure how to actually do it. 😕

Here is the 'world' layout.
Grey - Asteroid Belt
Green - Planet
Blue - Space Stations.

The idea is that the further the player is away from a space stations 'sphere of influence' the more likely it is for a group of enemies to spawn and attack the player. So at a point exactly equal distance between two space stations, the chance of enemies is the highest. I know how to do it if only one space station is involved, but with two I'm not sure. Especially as the initial start point for the player is at a random Space station.

Would anyone have any pointers please?

#

((I have the spawned stations GameObjects stored in a list btw)

winter aspen
#

Question: I've got an abstract class like this

public abstract class Foo<T>
{
    T data;

    public Event(T data)
    {
        this.data = data;
    }
}

and an implementation:

public class Bar: Foo<MyClass>
{
    public Bar(MyClass data) : base(data)
    {
    }
    //This constructor is triggering an error
    public Bar(Vector3 from, Vector3 to)
    {

    }
}

is it impossible for children to have extra constructors even when the base one is satisfied?

ruby python
#

Not sure if I'm correct, but you're naming the two 'Bar' s the same, so would that not be the issue?

rich adder
#

you can have multiple methods same name if they have different signatures

ruby python
#

Ah okay. Took a shot. lol.

winter aspen
#

they're constructors, it's natural they have the same name

rich adder
winter aspen
#

can I still call the base constructor from within?

#

the idea being: I use the vectors to initialize the data class, then pass that to the base constructor

#

kinda similar to this

public Bar(Vector3 from, Vector3 to): base(null)
{
  MyClass instanceData = //some calculation using the vectors and other properties
  base(instanceData);
}
rich adder
winter aspen
#

okay thanks

lost anvil
rich adder
#

I would not use mouseWorldPosition

#

use ray.origin or a holdPointTransform.position

#

also would recommend using .velocity instead of addforce

lost anvil
#

right ill try that

burnt vapor
#

If there was an issue then maybe share that

winter aspen
rich adder
# lost anvil right ill try that
private void FixedUpdate()
{
    HandleMouseInput();
    if(rb != null)
    {
        rb.velocity =  objectHoldPos.position - rb.position;
    }
}
private Rigidbody rb;
private void HandleMouseInput()
{
    RaycastHit hit;

    if (Physics.Raycast(mainCamera.transform.position, mainCamera.transform.forward, out hit, maxInteractDist, layerMask))
    {
        if (Input.GetMouseButton(0))
        {
            hit.collider.TryGetComponent(out rb);
        }
        
    }
}```
lost anvil
#

id rather do it myself but thank you 👍

burnt vapor
rich adder
burnt vapor
#

This is most syntactic sugar. In the end base() is still called but it's optional now

lost anvil
#

thanks 🙂

lost anvil
rich adder
#

AddForce adds onto the current force which can cause weird issues if you dont Clamp at some point

lost anvil
#

ah right was that why my door was spazzing out

#

because it was just adding force

rich adder
#

ohh thats for a door, though it was a pickup script

#

you can use addoforce, but put the door on a hinge and only push in your forward direction

lost anvil
#

right okay i would like to be able to pull it too but im assuming thats a different story

rich adder
#

to pull just -(inverse) the AddForce direction

long jacinth
#

how doesnt this work lol literally the guy in the tutorial did the same thign 1:1

wintry quarry
#

you did it wrong

#

, is not the same as ;

long jacinth
#

oh

#

i need glasses

#

thank you

polar acorn
#
"I did it exactly like the tutorial so why does theirs work and mine doesn't" counter:
Number of times it wasn't exactly like the tutorial: 180
Number of times it was exactly like the tutorial: 5
Number of times the code literally did not exist: 1
2022-07-19 to 2024-10-22
formal hill
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Logopopupthing : MonoBehaviour
{
    public Animator animator;
    public Collider2D zaCollider;
    public Collider2D mouseCollider;

    public void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.CompareTag("Mouse"))
        {
            animator.enabled = true;
            animator.Play("FileExplorer");
        }
    }

    private void Start()
    {
        animator = GetComponent<Animator>();
        animator.enabled = false;
    }
}

Anybody know why my animation isn't playing?

rich adder
languid spire
#

I can think of at least 4 reasons

formal hill
rich adder
formal hill
#

Oh thank you! I've been taking a small break off of unity so I totally forgot.

languid spire
rich adder
#

using physics for this is probably overkill if its just an interface interaction type deal

solar orchid
#

Can anybody help me? I’m trying to make a survival game Kinda like ark survival but I don’t know where to start. I watched a few videos like around 10 videos about coding and how to make players. I just don’t know what I should do first I wanna make a player first I just don’t really know how to and it’s really complex can anybody give me some tips or tricks???

rich adder
eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

solar orchid
cosmic dagger
rich adder
cosmic dagger
solar orchid
solar orchid
#

Can you change the name of your game later on or is it just stuck with one name?

cosmic dagger
solar orchid
#

Ok

cosmic dagger
#

you'll have the name of your before you release it. you won't finish any time soon. so, again, it's nothing to worry about . . .

solar orchid
#

Ok

#

Right now, I wanna work on the inventory the day and night cycle and the player movement and player stuff that the player would do

cosmic dagger
#

do you know what a collection is? array, list, queue, stack, etc.?

solar orchid
#

No : I

fleet granite
#

it's no big deal, won't take too long

#

i admire the aspiration but you have to start from the ground

#

throwing yourself at unity until something barely works is more likely to demoralise you

solar orchid
#

Ok

fleet granite
#

good luck!

cosmic dagger
# solar orchid No : I

exactly. crawl, then walk before you can run. you're thinking too far ahead. learn the basics of C#, learn beginner and intermediate programming with unity, then start working on your features . . .

wild widget
#

I tried to make a simple dash in 2D

    void OnDash(InputValue value)
    {
        if (value.isPressed)
        {
            PlayerRigidBody.AddForce(Transform.right * 10, ForceMode2D.Impulse); // i tried Vector2.right too
            Debug.Log(Vector2.right * 10);
        }
    }

Unfortunately only Debug.Log was triggered, anyone can help?

solar orchid
#

I made a playlist of all the things I need to do for my game like there’s this video that tells you how to code a day and night cycle and that’s what I kinda wanna do but I also wanna get better at coding while I’m making my do you think that’s good

cosmic dagger
wild widget
#

physics

cosmic dagger
#

which method of physics?

fleet granite
#

how much programming experience do you have?

wild widget
cosmic dagger
wild widget
#

ahh

solar orchid
# fleet granite how much programming experience do you have?

Over the years, I’ve watched like tons of videos of people making video games in like 1 week I don’t wanna do that. I wanna make a game in like seven weeks but keep on working on it and never stop. But I’ve watched lots of videos. About coding. I’ve just never really listened. I just liked watching how interesting it. Is to make a game and I wanna make one.

#

But I’ve started watching videos about how to code and I’m listening as much as I can

cosmic dagger
#

watching and actually doing it are two different things. just start learning C#. check the pinned messages or view this: <#💻┃code-beginner message>

solar orchid
#

Ok

ruby python
cosmic dagger
ruby python
solar orchid
#

OK, I kinda wanna make my game today. I’m gonna start out a little. I’m gonna make sure I don’t do too much. That way I can learn while I’m making my game. But it won’t be the final product of my game. Since I’m still learning.

ruby python
#

ie. The pirates avoid getting too close to a station because of the defenses (there will be 'events' where the pirates directly attack the station(s), but that bit is easy.

ruby python
solar orchid
#

Ok

#

I found one that I think is pretty good

#

And most of the people liked it and commented that it was good so I think it’s a good one

ruby python
#

Okay, try it out and see how it goes. I'm the same, I learn best by doing. Currently got about 30 different 'protoypes' of game ideas (different genres etc) and each one I've done I've learned a bunch of invaluable stuff.

solar orchid
#

Ok

cosmic dagger
cosmic charm
#

Quick question, when I try to handle movement when working on Machine State, should I write the script of moving in the Player script? or should I write it in the PlayerState script?

public void HandleMovement()
    {
        xInput = GetInput().x;
        MoveCharacter();
        ApplyLinearDrag();
    }

    // Input handling logic is within the Player class now
    protected Vector2 GetInput()
    {
        return new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
    }

    // Movement logic, directly controlling the Rigidbody2D
    protected void MoveCharacter()
    {
        rb.AddForce(new Vector2(xInput, 0f) * movementAcceleration);

        if (Mathf.Abs(rb.velocity.x) > maxMoveSpeed)
        {
            rb.velocity = new Vector2(Mathf.Sign(rb.velocity.x) * maxMoveSpeed, rb.velocity.y);
        }
    }

    // Handles linear drag and deceleration
    protected void ApplyLinearDrag()
    {
        if (Mathf.Abs(xInput) < 0.4f || changingDirection)
        {
            rb.drag = linearDrag;
        }
        else
        {
            rb.drag = 0;
        }
    }
#

like where should I write these functions?

cosmic dagger
torpid hamlet
#

Why wouldn't this work? Just trying to walk over something and teleport the player GameObject back to 0, 0, 0

deft grail
#

or your updating the position elsewhere also

cosmic dagger
rich adder
torpid hamlet
#

I have a character controller script

cosmic dagger
cosmic dagger
torpid hamlet
#

But before enabling and disabling the player let me just put a debug log to see if it actually triggers

torpid hamlet
ruby python
rich adder
rich adder
torpid hamlet
#

Just forgot it

rich adder
#

dont post videos of code, use the proper methods of sharing code

torpid hamlet
formal hill
formal hill
rich adder
# formal hill It does involve coding though

then properly post the code using codepaste webslite links and describing clear what the issue is, looking through a video just to possibly know the issue is extra work for the potential helper

uneven mantle
#

hi y'all, I'm getting back to unity dev after a LONG hiatus, is there a guide on how to attach a debugger (ideally vscode) to a built unity game on pc? Note: not the editor, not "build and run", but a build someone else already did, because I need to debug that one.

wintry quarry
#

See "Debug in the Unity Player"

rich adder
#

oof they still have mac VS instructions

wintry quarry
#

Also - the build you are trying to debug needs to have been built in development mode with script debugging turned on

uneven mantle
formal hill
wintry quarry
torpid hamlet
wintry quarry
#

Again - I'll point out that the build has to have been built with these options though:

Enable the Development Build
and Script Debugging options before you build the Player

rich adder
uneven mantle
#

btw, @wintry quarry and @rich adder thank you for the help, regardless of how it goes ❤️

mystic dawn
#

Hey there people! i'm having some trouble with handling the rotation of sprites in my project and looking for any help with this issue!

basically my player character has a weaponParent child which acts as the rotation point and parent of all the weapons, the weapon parent rotates to face the mouse position and the weapon sprites that are it's children rotate alongside it correctly.

I implemented a nuclear throne style melee weapon and im now facing an issue where rotating the weapon parent between -180 to 0 makes the sprites stutter and flip to the opposite direction, i cannot find the reason why it does this so any pointers would be very helpful :((((

here is the script for the weaponParent, it handles everything related to rotating and flipping sprites but i can't seem to find where the problem is: https://www.codebin.cc/code/cm2kodisk0001k102id59oqe9:7Z53AbNGqA6AxvvnrLBSFpjo3vTTuXEYwGTEDbmm2nu9

formal hill
# rich adder idk what to tell you , do it or don't lol

Well heres the code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Logopopupthing : MonoBehaviour
{
    public Animator animator;
    public Collider2D zaCollider;
    public Collider2D mouseCollider;

    public void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.CompareTag("Mouse"))
        {
            animator.enabled = true;
            animator.SetBool("Entered", true);
            animator.SetBool("Left", false);
        }
    }

    public void OnTriggerExit2D(Collider2D collision)
    {
        if (collision.CompareTag("Mouse"))
        {
            animator.SetBool("Left", true);
            animator.SetBool("Entered", false);
        }
    }

    private void Start()
    {
        animator = GetComponent<Animator>();
        animator.enabled = false;
    }
}
``` I don't know if something is wrong with it, but if it has could someone help me? Thanks
wintry quarry
rich adder
wintry quarry
#

isn't that redundant?
Doesn't transform.right = direction; handle the rotation already?

uneven mantle
#

but it doesn't find it

wintry quarry
#

you want to attach to the running game process

mystic dawn
uneven mantle
#

If instead I try this config here it finds the .exe but doesn't load the symbols

mystic dawn
wintry quarry
eternal falconBOT
mystic dawn
uneven mantle
rich adder
mystic dawn
formal hill
# rich adder

I'm pretty sure sprites are classified as world objects? But i'm using it as UI. I want an animation to play when the mouse goes over the sprite and it does... Sometimes, but then it also just stops working sometimes.

uneven mantle
mystic dawn
#

my problem is that it basically flips the sprite to the opposite direction whenever the rotation of the weapon parent z axis reaches -180 to 0

uneven mantle
#

not to the process of the build?

uneven mantle
rich adder
wintry quarry
#
        if (direction.x < 0)
        {
            handParent.transform.localScale = new Vector3(1f, -1f, 1f);
            axeSpr.flipX = true;
            
        }
        else if (direction.x > 0)
        {

            handParent.transform.localScale = Vector3.one;
            axeSpr.flipX = false;

        }```
rich adder
formal hill
rich adder
#

probably way easier than using rigidbodies and triggers

uneven mantle
formal hill
uneven mantle
#

also, thanks for trying ❤️

mystic dawn
# wintry quarry ```cs if (direction.x < 0) { handParent.transform.lo...

this is for flipping each weapon accordingly, what im trying to do is have the axe have a rotation similar to nuclear throne's melee weapons so im not messing with it's localscale for flipping it and only flipping the sprite, the hand weapon i flip it in the Y only and they work fine, the problem is they bug out when the rotation of the weapon parent ( the object holding both the handParent and axeParent) reaches -180 to 0, i don't know why it is doing it, my guess is that using direction.x to evaluate where the player is facing is what is messing it up

rich adder
wintry quarry
mystic dawn
#

but im not really sure as it works completly fine in any direction i point my mouse towards except for when it is at a -180 to 0 range in which the axe starts flipping in the Y axis, and the Hand flips on the X axis

rich adder
mystic dawn
eternal falconBOT
wintry quarry
#

you're worried a bit too much about the euler angles

wintry quarry
mystic dawn
mystic dawn
wintry quarry
#

there's nothing in this code that could make it "go crazy" afaict

#

you 100% sure there's no other code involved?

#

what about the code that aims the arm/weapon at the mouse?

mystic dawn
#

yeah that's why im having so much trouble with it :(((

nope apart from this no code messes with any of these objects, everything is handled in the weaponparent that relates to rotating the weapon parent there's aline of code that handles rotating it here:

direction = ((Vector2)GetMousePosition() - (Vector2)transform.position).normalized;
transform.right = direction;

spare mountain
#

try printing these every frame and see which part is flipping

mystic dawn
#

also when i examined each of the transforms on play mode, no variable seem to be changed when the flip occurs at -180 to 0, basically when i check if maybe something changed in the transform of each the hand and axe parents nothing seem to be changed and yet they are still flipped

coarse knoll
#

im trying to learn C# but cant find any videos, any of yall know any helpful videos?

eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

coarse knoll
#

thanks

cosmic dagger
eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

formal hill
rich adder
#

I don't have eyes on your pc

formal hill
# rich adder I don't have eyes on your pc

Yeah sorry. My explanation was not clear. So inside of the even trigger component on the Pointer Enter (BaseEventData) when I add the gameObject to it the function I need will not show inside of the script.

using UnityEngine;
using UnityEngine.EventSystems; 

public class Logopopupthing : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
    public Animator animator;

    public void OnPointerEnter(PointerEventData eventData)
    {
        animator.enabled = true;
        animator.SetTrigger("FileExplorerUp"); 
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        animator.SetTrigger("FileExplorerDown");  
    }

    private void Start()
    {
        animator = GetComponent<Animator>(); 
        animator.enabled = false;
    }
}

rich adder
formal hill
rich adder
#

you're mixing two of the same component together

#

pick one or the other

#

PointerEnter on event Trigger does the same exact thing that OnPointerEnter method from IPointerEnter interface does

#

pick one or the other, then you need colliders and a Physics2D physics raycaster on the camera

formal hill
rich adder
#

the one with the collider

#

remove the component EventTrigger component if you're gonna use the script

formal hill
rich adder
#

the EventTrigger was just meant as a standalone component to communicate to another script (call function in another script elsewhere too)

formal hill
#

Okay it now works, but for some very weird reason it only works if the mouse goes to the object from a certain place. It needs to go from the down left corner for it to work.

rich adder
#

keep in mind this function works off the Event System so if you have UI elements it wil block the raycast

formal hill
#
using UnityEngine;
using UnityEngine.EventSystems; 

public class Logopopupthing : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
    public Animator animator;

    public void OnPointerEnter(PointerEventData eventData)
    {
        animator.enabled = true;
        animator.SetTrigger("FileExplorer"); 
        animator.SetBool("Entered", true);
        animator.SetBool("Left", false);
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        animator.SetTrigger("FileExplorerDown");
        animator.SetBool("Left", true);
        animator.SetBool("Entered", false);
    }

    private void Start()
    {
        animator = GetComponent<Animator>(); 
        animator.enabled = false;
    }
}
rich adder
# formal hill Here

show the colliders, no need or video just select them and screenshot the colliders

rich adder
formal hill
#

But the folder one only gets activated when the mouse enters it from the left down corner

rich adder
formal hill
#

What? Why does that happen?

rich adder
#

put logs in those methods and see how quickly they print, it could just be your animation being wacky

formal hill
#

I just checked it again and it doesn't anymore

#

It's the same size now and when I stop playing

rich adder
#

alr just do the log thing anyway and see whats going on

rich adder
#

btw I hope you're not animating each button with its own animation and animator if they all animate the same hover effect . that would be painful lol I will show you a better method

formal hill
#

The logs come in pretty much instantly. It gives 2 of them tho and it gives a warning "UpAnimPlayed
UnityEngine.Debug:Log (object)
Logopopupthing:OnPointerEnter (UnityEngine.EventSystems.PointerEventData) (at Assets/Scripts/Logo pop up thing.cs:12)
UnityEngine.EventSystems.EventSystem:Update () (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:530)"

rich adder
formal hill
rich adder
formal hill
rich adder
#

hmmm that could possibly be a problem..
the new event system has a hard time logging what your mouse is hovering..

#

you would need to write a piece of code

formal hill
#

What piece of code?

rich adder
# formal hill What piece of code?

try cs PointerEventData pointerData = new PointerEventData(EventSystem.current); void Update() { { pointerData.position = Input.mousePosition; List<RaycastResult> raycastResults = new List<RaycastResult>(); EventSystem.current.RaycastAll(pointerData, raycastResults); foreach (RaycastResult result in raycastResults) { Debug.Log("Hovering over: " + result.gameObject.name); } } }

formal hill
rich adder
formal hill
#

Ok

rich adder
#

let me double check if it works, just got it off forum post

#

okay yeah it should work if hover over a collider

formal hill
#

Even though the collider is ontop of the entire image

rich adder
formal hill
#

Okay

#

Now it works from all around!

rich adder
#

hmm thats odd

#

is your camera in orthographic yes?

formal hill
#

Yes

#

Do I change it to perspective?

rich adder
#

no

formal hill
#

Could it be the CRT camera effect that I have on?

rich adder
#

its possible is messing with where the icon is vs cursor shows

#

turn it off and try the corner again

formal hill
#

The problem was the CRT

rich adder
#

ah well that will do it lol.

#

I wonder if it would do the same thing with a regular physics raycast, probably..

formal hill
#

I wonder if I can fix it. I really like the effect

rich adder
#

try it with a regular raycast

#

maybe event system doesnt like PP effects

formal hill
#

What do you mean "regular raycast"

cosmic charm
#

Quick question, when I try to handle movement when working on Machine State, should I write the script of moving in the Player script? or should I write it in the PlayerState script?

public void HandleMovement()
    {
        xInput = GetInput().x;
        MoveCharacter();
        ApplyLinearDrag();
    }

    // Input handling logic is within the Player class now
    protected Vector2 GetInput()
    {
        return new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
    }

    // Movement logic, directly controlling the Rigidbody2D
    protected void MoveCharacter()
    {
        rb.AddForce(new Vector2(xInput, 0f) * movementAcceleration);

        if (Mathf.Abs(rb.velocity.x) > maxMoveSpeed)
        {
            rb.velocity = new Vector2(Mathf.Sign(rb.velocity.x) * maxMoveSpeed, rb.velocity.y);
        }
    }

    // Handles linear drag and deceleration
    protected void ApplyLinearDrag()
    {
        if (Mathf.Abs(xInput) < 0.4f || changingDirection)
        {
            rb.drag = linearDrag;
        }
        else
        {
            rb.drag = 0;
        }
    }
formal hill
rich adder
formal hill
rich adder
faint osprey
#

im trying to test my multiplayer game out by running a build and the editor at the same time however when i tab out and switch to the other screen to play on the other player it makes the other one lag like crazy I have application.runinbackground to true so i dont get why cause my cpu and gpu and struggling

rich adder
# formal hill I already had the Physics2D raycast

I meant try like this

 void Update()
 {
     Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
     RaycastHit2D hit = Physics2D.GetRayIntersection(ray, Mathf.Infinity);
     if (hit)
     {
         Debug.Log("Hit " + hit.collider.name);
     }
 }```
formal hill
crisp token
#

@remote kiln over here

remote kiln
#

game manager

rich adder
remote kiln
#

player movement

#

I have no previous experience with c# so excuse the trash code/indentation

rich adder
crisp token
#

youre good, one think I want to ask is do you have any errors in your log because that will cause very poor performance. Like do you see any red

remote kiln
#

basically when my game runs the player doesnt move at all and it runs on extremely low fps

#

sample scenbe keeps flickering with "unloaded"

rich adder
#

first of all you never want to multiply Time.deltaTime inside AddForce

remote kiln
#

console is clear

rich adder
#

rigidbodies methods like addforce should only be called inside FixedUpdate unless its an Impulse

#

everything else is fine

crisp token
#

I think you might be getting stuck in an infinite loop of unloading and loading scenes

remote kiln
rich adder
remote kiln
#

in the tutorial, the guy mentioned it wont be the same for different frame rates

#

that why we use time.deltatime

crisp token
#

can you add this line before you load a new scene: Debug.Log("New Scene Loaded");

remote kiln
#

oh dang

remote kiln
#

it keeps printing

#

could i try figuring it out

#

as some type

#

of practice

rich adder
remote kiln
rich adder
solar orchid
#

Does anybody know if any PC can run unity?

#

Or is it certain ones

remote kiln
#

hm i got an idea

rich adder
#

if EndGame is constantly being called then your rigidbody is always at < y -5 starting

short hazel
solar orchid
languid spire
short hazel
#

Yep, consider removing the safe on the left because that could cause interference

solar orchid
#

I don’t know, man i’m new to all this crap

languid spire
#

then learn something about computers

remote kiln
solar orchid
remote kiln
#

well the calling method

short hazel
#

What matters are your specs, ie. what CPU, GPU, and RAM you have on that computer

solar orchid
#

Ok

languid spire
#

Not to mention SSD HDD PSU etc, etc, etc

remote kiln
#

what could possibly be wrong

rich adder
remote kiln
rich adder
polar acorn
remote kiln
#

wth

solar orchid
remote kiln
#

gng.

#

i forgot to check for the colliders tag

#

man

rich adder
remote kiln
rich adder
#

you should always debug the collider also when this happens and see what is hitting

#

but yeah had a feeling OnCollision like that, is too much of a gamble . Always need some type of filtering usually

remote kiln
#

collission was the entire issue

#

dang

#

collision

#

i cant believe i forgot to check for the tag