#💻┃code-beginner

1 messages · Page 165 of 1

unkempt tree
#

lfmao

ionic zephyr
#

how can I make my character NOT to move Diagonally (I use GetAxisRaw)

unkempt tree
#

check which one is higher set the other to zero

ionic zephyr
#

yeah, I did that but the problem is that when setting an IDLE Animation (if movement vector == 0) everytime I switch from moving upwards to downwards or to the right and then left the IDLE Animation triggers

#

if (_xvalue == 1 || _xvalue == -1)
{
_yvalue = 0;
}
else if (_yvalue == 1 || _yvalue == -1)
{
_xvalue = 0;
}

#

this is my code

#

(between _xvalue and _xvalue there is an "or"

#

and the same with yvalue

north kiln
#

!code

eternal falconBOT
ionic zephyr
#

between the switch of _xvalue = 1 to _xvalue = -1 it passes through zero

olive lintel
#

hey guys, just wondering is Network ID in a network behaviour always the ID of the owner of said object?

wintry quarry
lost kelp
#

hi, im not really sure which channel to ask this in but im struggling with my code inheriting from an interface after inheriting from monobehaviour

wintry quarry
#

show your code and the problem you're having

lost kelp
#

im just trying to make a save/load system and theres no errors on visual studio but on unity it says i can't have multiple base classes

wintry quarry
lost kelp
wintry quarry
#

Show the error in Unity

lost kelp
wintry quarry
#

Also you should have errirs in VS since you didn't actually implement the interface

#

my guess would be you have another script

#

and you're defining class iData in it

slender nymph
#

the interface methods have default implementations so they don't actually need to be implemented

wintry quarry
#

ohh yes

#

yeah they shouldn't have that

#

it should just be void LoadData(GameData data); for example

lost kelp
#

ohh okay thank you

wind raptor
#

Looking for some project guidance.

I have a Unity Windows build that is connected to several microcontrollers over serial ports. I would like other devices (PCs, tablets, phones) on the same local network to be able to access a simple UI to see some variables states and send commands to the main application.

My thought was to have my main application, on startup, deploy a locally hosted Webgl build of an application containing said UI.

Given how simple this should be (I hope), what path would you recommend for handling the networking? Am I on the right path regarding the locally hosted Webgl build? If I ever wanted to access the UI from a different network, how could that be accomplished?

Thanks in advance for any pointers.

night adder
#

Having an issue with the C# Dev Kit, the error is below but it seems I just dont have the right SDK version, my issue is that I can't find documentation anywhere on what version I need, where could I find this at?

The current workspace is using a new version of .NET SDK '8.0.101', which is not supported by current .NET runtime used by the extension. Some functions may not work correctly. This may happen when global.json is changed, or new SDK installation after the workspace is opened. Reloading the workspace may fix the problem.
teal viper
night adder
#

It pops up in the bottom right as a little box whenever I launch VSC

teal viper
eternal falconBOT
night adder
wind raptor
teal viper
#

So, if you want to distribute it via a link(i.e. just open a link in a browser to launch a client), then yeah, you'd need to host the WebGL build somewhere in a addition to your actual app server.

wind raptor
teal viper
wind raptor
small mantle
#

How can I reference a sub class in a script?

teal viper
small mantle
teal viper
#

The latter one is a bad practice that I recommend to avoid.

small mantle
#

I did that. It doesn't show up in inspector? @teal viper

teal viper
wintry quarry
grizzled pagoda
#
        Debug.Log(other.gameObject.layer);
        if(other.gameObject.layer == 7){
            HealthPoints = HealthPoints - 1;
            Debug.Log("Zombie HealthPoints: " + HealthPoints);
        }
        else if(other.gameObject.layer == 6){
            speed = 0f;
        }
        else{
            speed = 10f;
            Debug.Log("skibbidi");
        }
    }```
#

hi, why is my speed not turning to 10 even when the if statements are not true?

grizzled pagoda
#

nope

polar acorn
#

Then that code never runs

grizzled pagoda
#

yeah but why?

#

is it indentation or smth

#

theres nothing else that changes speed either

polar acorn
grizzled pagoda
#

oh

#

yeah haha

#

damn it was so obvious

#

i added speed =10f to update

small mantle
minor spindle
#

Would it be best to have a script for Player and a script for Sword, or to handle both in one script?

calm coral
#
if(Physics.Raycast(
    new Vector3(mouse.position.value.x, mouse.position.value.y, -5),
    Vector3.forward,
    out RaycastHit hitInfo,
    10))
{
  // do stuff
}
```Hey, is this raycast going to detect my collider even if it's a 2D collider?
rich adder
#

they're completely different physics engines

calm coral
rich adder
#

depends what you're doing, or use 2D raycast?

#

3d colliders on sprite is normal, unity is 3D anyway

calm coral
#

And I don't see an option to raycast from the camera perspective through the plane to get where the player is clicking (raycasting)

wintry quarry
calm coral
wintry quarry
wintry quarry
#

Use it with the mouse position if you want it where the mouse is

calm coral
#

Okay, quick testing and I almost got it, I did a mistake by taking mouse x and y coords instead of that camera screen point, thanks a lot!

teal viper
#

That is if you're interested in writing good code.

minor spindle
teal viper
minor spindle
#

one day though

teal viper
#

you could at least try

#

Otherwise there's no point in your original question.

minor spindle
#

Good point

calm coral
# wintry quarry You want Physics2D.GetRayIntersection and Camera.ScreenPointToRay
Ray a = Camera.main.ScreenPointToRay(new(mouse.position.value.x, mouse.position.value.y));
RaycastHit2D hitInfo = Physics2D.GetRayIntersection(a, 10);
if(hitInfo.collider.gameObject.CompareTag("Card"))
{
    // ...
}
```Great, this piece of code works for me, thanks again! ![PepeHappy](https://cdn.discordapp.com/emojis/822677090217230397.webp?size=128 "PepeHappy")
#

With box collider 3D it also worked earlier but this works for a 2D box collider

minor spindle
grizzled pagoda
#
    private int waittime = 5000;
    private int eatwaittime = 10000;
    private float eatdelay;
    private float delay;
    public float SunflowerHealth = 5;
    public GameObject SunPrefab;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        delay++;
        eatdelay++;
        if(delay>=waittime){
            Instantiate(SunPrefab, transform.position,SunPrefab.transform.rotation);
            delay = 0;
        }
        if(SunflowerHealth<= 0){
            Destroy(gameObject);
        }
    }
    void OnCollisionStay(Collision other){
        Debug.Log("Collision happened");
        if(other.gameObject.layer == 3){
            if(eatdelay>=eatwaittime){
                SunflowerHealth--;
                Debug.Log("monkey");
                eatdelay = 0f;
            }
        }
    }
}``` is there any reason why my eatdelay doesnt work???????
#

in oncollisionstay

cosmic dagger
grizzled pagoda
#

cuz its per tick and updated in update

teal viper
#

frames

#

very bad idea though

cosmic dagger
#

Also, you're adding to delay and eatdelay without using deltaTime . . .

teal viper
#

Unless you have fixed frame rate in the game

cosmic dagger
#

You should work using time, not frames . . .

grizzled pagoda
#

yeah idk how to use time, ive used frames so far

#

i thought the only way to use time was enumerating

cosmic dagger
#

If someone lags, it's game over. All their values are f!@#ed . . .

teal viper
#

10000 frames on 60 fps is around 166 sec, so around 3 minutes.

teal viper
grizzled pagoda
cosmic dagger
grizzled pagoda
#

and deltatime is real time right

teal viper
#

the timer also needs to be a float then

teal viper
#

I think you should go do some basics learning.
!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

cosmic dagger
grizzled pagoda
#

and my delay counters should be multiplied by deltatime?

#

and how would i know how much deltat time is

cosmic dagger
#

Technically, an average between the previous frames, and yada, yada, yada. . .

teal viper
#

It's not an average. it's actually the time passed from the last frame.

cosmic dagger
cosmic dagger
grizzled pagoda
#
 eatdelay = eatdelay + deltatime;```
cosmic dagger
grizzled pagoda
#

okay

cosmic dagger
#

It's crucial when changing values in Update . . .

dark sluice
#

so im making a mc clone and have a script set up for basic chunk spawning the world generation with a simple grass, dirt, and stone blocks, for some reason im getting a layer of nothing under my grass blocks and above the dirt blocks, if i share my generation script could someone help out? this is just for a fun lil side project with a friend

teal viper
dark sluice
teal viper
#

!code

eternal falconBOT
dark sluice
#

mbmb

#

like so?

teal viper
#

If I assume that there are more problems(like missing reference), then there are more possible causes.

#

Use the debugger to debug that code.

shell herald
#

OnDIsable is the last thing that gets called if either the script or the gameobject its on is deactivated right?

charred spoke
#

Yep

teal viper
shell herald
#

and im guessing OnEnable is the polar opposite to that?

teal viper
#

activated state only affects some unity callbacks.

teal viper
charred spoke
#

But if awake and start have already been called then yes. OnEnable will be first

sonic dome
#

https://pastebin.com/D7XJnxbu
https://pastebin.com/Y3cdv7xu
these r my camera and moment scripts can anyone tell me why my camera is also rotating when i press a and d

#

these r my configs

#

ping me on reply

paper rover
#

Is anyone able to help me figure out why I am getting GC Alloc from my camera? I only have one camera and am getting GC Alloc every frame

teal viper
sonic dome
ivory bobcat
ivory bobcat
#

Assuming orientation is the camera object

sonic dome
ivory bobcat
#

Is it the camera object?

sonic dome
#

no

teal viper
ivory bobcat
#

What is the move script attached to?

paper rover
teal viper
sonic dome
#

capsule

ivory bobcat
#

Line 23 rotates the object with the script (camera script). Was that what you wanted?

sonic dome
#

like in rpgs

ivory bobcat
#

It rotates the object with the script attached

sonic dome
ivory bobcat
#

transform.rotation = Quaternion.Euler(xRotation,yRotation,0);

sonic dome
#

doesn't it rotate the object its attached to?

ivory bobcat
#

That's what I said

sonic dome
#

ya so thats what i want

ivory bobcat
#

If it's attached to the camera it'll rotate the camera

#

So a and d will rotate the camera

sonic dome
#

i want to move in any direction irrespective of the camera

ivory bobcat
#

It doesn't move, it rotates

sonic dome
#

ya my bad

#

i meant rotate

ivory bobcat
#

So you found the problem

teal viper
sonic dome
#

see i removed the 24th line which rotated the orientation

ivory bobcat
#

Your camera rotates because of that line (23)

sonic dome
ivory bobcat
#

why does my camera also rotate

sonic dome
#

yea

#

cz

#

i want my cam to be rotated with my mouse

#

and my player with a and d

sonic dome
ivory bobcat
#

Ah, right. Mouse X and not Horizontal

#

I'm not sure then

sonic dome
teal viper
#

Might want to look at cinemachine tutorials

sonic dome
teal viper
#

You probably want to use free view camera(or whatever it was called) instead of a plain vcam.

sonic dome
teal viper
#

Also, expanding the "body" drop-down might give more clues.

sonic dome
sonic dome
ivory bobcat
#

Unless it's a child of the object with the movement script, have referenced the wrong object or have attached the movement script to the camera object as well.. I'm not sure.

sonic dome
#

why does it work here 😭

teal viper
#

Did you inspect the body properties of the vcam..?

teal viper
#

and..?

sonic dome
#

i couldnt find anything like i get it that cuz the should transfom is rotating the camera rotates with it where as in the other project it doesnt

ivory bobcat
#

Does "following" refer to orientation as well?

sonic dome
#

so i m kinda confused

ivory bobcat
#

Or does it just move towards the object?

north kiln
ivory bobcat
#

If it stays directly behind the object that's being followed, it'll rotate with the object?

north kiln
#

Depends entirely on the Aim

sonic dome
#

wait

#

i found a difference

#

the aim was set to

#

do nothing

#

in the other project

#

let me try now

#

still doesnt work it rotates with the rigidbody 😭

ivory bobcat
#

Show us the inspector for your capsule.

sonic dome
teal viper
#

The issue is definitely with your vcam setup

sonic dome
#

yea

teal viper
#

Maybe you should share the details of the vcam with it's properties expanded, as you never did that...

sonic dome
teal viper
sonic dome
#

i checked in both the projects the should object is rotating in both

ivory bobcat
#

So you've got any other script in any other object that we should be aware of?

sonic dome
#

https://pastebin.com/7Pu0QW69
https://pastebin.com/PiNa6NZM
these r the scripts used in other project

ivory bobcat
#

I'm referring to this project with the capsule

ivory bobcat
#

So no other objects have any other scripts attached to them?

sonic dome
#

nope

#

i just have 2 scripts as of now

teal viper
# sonic dome

Okay. Can you record a video of what happens at runtime with the vcam selected and visible in the inspector?

ivory bobcat
ivory bobcat
#

You don't have the camera script attached to some other object referencing the vcam, do you?

shell herald
#

not quite understanding this. i want a sound to play, every time a button is selected. right now i have this and its not working

sonic dome
teal viper
#

@sonic domewhat's that line 24 for?

#

Can you comment it out and try again?

sonic dome
#

well i took this script from https://www.youtube.com/watch?v=f473C43s8nE&t=288s and as of now i felt like i dont need that line so i removed it from my current project cuz i dont want the shoulder to rotate

FIRST PERSON MOVEMENT in 10 MINUTES - Unity Tutorial

In this video I'm going to show you how to code full first person rigidbody movement. You can use this character controller as final movement for your game or build things like dashing, wallrunning or sliding on top of it.

If this tutorial has helped you in any way, I would really appreciate...

▶ Play video
sonic dome
sonic dome
#

and it bugged everthing

#

wait let me show u

ivory bobcat
#

Define bugged?

sonic dome
ivory bobcat
#

If it can't be described with words then a video may be fine but most of these could probably just be better described.. we'll likely not even know what we're looking at.

sonic dome
#

when i do that my mouse stop rotating the cam as well

teal viper
#

I think the answer to your issue has to do with the Shoulder object and the references to it. Can you confirm if these 2 reference the same object?

#

And also take a screenshot of it's position/orientation in both of the projects?

sonic dome
#

okk

teal viper
ivory bobcat
#

So, simply by deducing we have confirmed that the line allows you to rotate by both mouse y and key (a and d). Did you perhaps change anything inside the input manager?

teal viper
# sonic dome

Why is it offsetted like that in the left project?

#

on the right it only has offset on the y axis

sonic dome
#

no spfic reason in one case i just changed that from the x y z damping in the virtual cam 3rd person follow

teal viper
#

Make it the same as in the other project and test

sonic dome
#

well

#

tbh

#

i think i should just make my own camera script

#

that will fix everthing

junior finch
#

Hey is there something wrong here that I am not seeing

teal viper
#

I'd say that naming conventions are wrong, but I don't think that's what you're looking for..?

junior finch
#

well I am trying to make the button change color on click

summer stump
# junior finch

Why have isPressed at all?
You already have GetMouseButtonDown

junior finch
junior finch
gaunt ice
#

no idea why you query your input in update loop but not doing in on mouse down

teal viper
#

Or is it a quiz?

junior finch
# teal viper Or is it a quiz?

nah, just a learning kind of thing. I want to see if i can change the color of another game object from this one when i click it. I can do i on that object itself but i want to see if i can do it from here cause something i want to implement might depend on it

teal viper
#

So, what is not working..?

junior finch
#

well the color does not change

teal viper
#

Great. You should've started the very first message from that sentence, instead of expecting other people to guess.

#

And you've already been answered by several people about possible causes.

junior finch
#

well i originally went through most of those but "why you query your input in update loop but not doing in on mouse down" is something i might not have tried

#

Its still not working

#

could it be an attaching issue?

teal viper
#

Start from sharing more details. A screenshot of the object that has the script, the latest code, debugging attempts so far.

junior finch
#

this is how I have attached

gaunt ice
#

have you tried debug.log if the on mouse down is executed

teal viper
junior finch
#

the area is pretty dark, i've tested it with something else i can see it

junior finch
#

so the button is just not getting clicked

vale bronze
#

is it possible to detect collisions between a collider that has isTrigger enabled and one that doesnt?

teal viper
junior finch
teal viper
teal viper
vale bronze
teal viper
vale bronze
#

ok last question: would I use oncollision or ontrigger?

vale bronze
#

thanks

teal viper
#

Depends on what object you want to receive the message on.

timber tide
#

I think it makes more sense to have the rigidbody on the character and the trigger on the object to trigger

#

can just use IsTrigger on anything anywhere if you don't care for collisional events

fringe plover
#

!code

eternal falconBOT
fringe plover
#

(lines 29 and 30 are not used)

hard hornet
#

it works with the new input system, not sure with the old one but try it

fringe plover
#

lemme try

#

yeah it works

#

thank you😅

hard hornet
#

of course, sometimes simple solutions are the best

long scarab
#

Greetings, I have small issue, my IDE debugger evaluates a condition true, but in the code debugging, the if is skipped as if it went false.

#

else if (eventData.button == PointerEventData.InputButton.Left && toggleDrawUI.isOn)

#

this is the code, I pasted same code to my watched variables to IDE

#

its true

#

yet it never gets into the nested part of code inside the if

#

and no, it is not caught by previous else ifs

gaunt ice
#

is this whole thing eventData.button == PointerEventData.InputButton.Left && toggleDrawUI.isOn true

long scarab
#

yes

#

well IDE says it is and from what I can see I clicked left button and the toggle is on

gaunt ice
#

show the screenshot?

long scarab
#

sure one sec, have to get to the program state

#

well

#

now it suddenly works

#

but until I added a new line inside the if condition, it didnt

#

maybe some compilation bug idk

#

yup now it works after I added one new line to the nested brackets of if

#

Could it be that unity somehow catched old code or something?

obsidian parcel
#

hi, im facing a problem using raycast as when i do the raycast on a object with the rigidbody it works and but when i make the rigid body is kinametic or freeze loc and rot it dont and also trigger dont work is there any workaround through which i can use raycast and also make the object stay in air and not acting to player?

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

namespace InteractorSystem
{
    public class InteractionSystem : MonoBehaviour
    {
        [SerializeField] Transform orientation;
        public bool canInteract = true;

        private void Update()
        {
            if(Input.GetKeyDown(KeyCode.E) && canInteract)
            {
                
                RaycastHit hit;
                
                if(Physics.Raycast(transform.position + (orientation.forward), orientation.forward, out hit,100))
                {
                    Debug.Log("Debug");
                    Interactor interactObject = hit.collider.gameObject.GetComponent<Interactor>();
                    if (interactObject != null)
                    {
                        interactObject.OnInteract();
                        canInteract = false;
                    }
                }
            }
        }
    }
}
hard hornet
#

why transform.position + (orientation.forward) as ray origin?

obsidian parcel
#

i thought its colliding with the player so i started the location one vector

hard hornet
#

you could use layers for that

eternal needle
#

Use debug.drawray to visualize your raycasts

long scarab
#

you see the condition is true but on next step it just goes after the if

#

I am now optimising the ifs anyway cause its a mess I did just to test if it works at all

obsidian parcel
#

it works now

eternal needle
long scarab
#

well yes

#

but then the object would instantiate

#

if I skipped the code in debug but it happened

#

I usually use step over btw

#

Sorry for bothering you guys

#

this just seem like some non deterministic s*it to me 😄

eternal needle
odd valley
#

If I wanted to make a text sprite in 2D, how would I make one without using canvas?

long scarab
#

worst thing is that when I changed a line in the code, it worked, and now it doesnt again, havent touched the IFs tho

#

seems like the file is somewhat corrupted or something

eternal needle
long scarab
#

yeah probably

#

thanks for efforts tho!

eternal needle
#

Also you dont need to use Instantiate for a new gameobject. Using the constructor will spawn the object in your world

#

You might be spawning 2 objects because of it

long scarab
#

nah it spawns one

#

I havent made constructors for this class yet

wintry quarry
#

Instantiate(new GameObject()) definitely spawns two objects

eternal needle
#

Im talking about the ctor for game object

#

One will spawn with no parent, then you instantiate another under the parent

long scarab
#

let me check then

#

nope

#

it spawned one GameObj

wintry quarry
#

One of them won't have a parent

long scarab
#

ooh

#

I see another one at top of hierarchy now

#

how to make empty GameObj then?

wintry quarry
#

new GameObject()

eternal needle
#

You just use the constructor, remove the instantiate function. Or use instantiate and make a prerab

long scarab
#

(I always used prefabs to spawn objects until now)

wintry quarry
#

I think you should use a prefab here idk why you're not

#

Also I don't understand how you're doing GetComponent<Meshrenderer>() on it since it clearly won't have one

long scarab
#

it does have one

wintry quarry
#

Doesn't that cause an NRE?

long scarab
#

nope, it works fine

#

I havent used prefab cause I didnt wanted another attribute 😄

wintry quarry
#

How could it have one? Didn't you just create an empty object?

long scarab
#

when its so simple GameObj

wintry quarry
#

Without a renderer?

long scarab
#

wanted to just generate it

#

nope, it creates an object with meshfilter and meshrenderer

wintry quarry
#

How?

long scarab
#

its made via [RequireComponent(typeof(MeshFilter))]
[RequireComponent(typeof(MeshRenderer))]

wintry quarry
#

I thought RequireComponent only works when creating the object in the editor

long scarab
#

could be

#

making a prefab

#

😄

wintry quarry
#

Oh actually I just checked the documentation

#

It does work with AddComponent

#

That's a new one for me, TIL. I'd still just use a prefab

arctic ibex
#

Does anyone know what I can do to fix this? I've restarted the game, and checked the prefab, but i can't figure out how to fix it

long scarab
#

yup, its simply that I wanted to learn if I can make such simple GameObj from scratch

wintry quarry
arctic ibex
north kiln
#

you created a second version

#

and you didn't assign the script

wintry quarry
arctic ibex
#

Theres no second version here

north kiln
#

In the scene

wintry quarry
arctic ibex
#

there is only one object in this scene that has that script

wintry quarry
#
  • that you remember
arctic ibex
#

if there were more I would have checked all of them

north kiln
#

Can you search your scene for the script

arctic ibex
#

how?

north kiln
#

Search in the hierarchy window's search box

wintry quarry
#

It's also possible you're referencing the prefab somewhere and trying to call a function on the prefab itself

#

t:chicken in the hierarchy search

north kiln
#

don't even need to the t: unless you have objects with the same name too 😄

arctic ibex
#

Only one

#

as i said

north kiln
#

Well, you had never searched, apparently

#

Send your !code

eternal falconBOT
arctic ibex
north kiln
#

Fills me with confidence

arctic ibex
wintry quarry
arctic ibex
wintry quarry
# arctic ibex

Doesn't this GameObject fellowpoultry = GameObject.FindGameObjectWithTag("chicken"); imply there are multiple chickens in the scene?

#

My guess you are spawning chickens in at runtime

arctic ibex
wintry quarry
#

And the prefab doesn't have the animator assigned

arctic ibex
north kiln
#

(particle system, but yes too)

wintry quarry
#

Also that code makes little sense since it will likely just find itself

arctic ibex
wintry quarry
#

Show your chicken prefab

arctic ibex
wintry quarry
#

I bet it's not assigned on the prefab especially since it was an override in the scene

arctic ibex
#

This is the script component on the prefab

#

also imnot spawning any other chickens in this scene

north kiln
#

you don't use chicken 2?

arctic ibex
#

they spawn in a different scene

arctic ibex
north kiln
#

Seems like you have a number of chicken prefabs

#

I would check them all, and check your assumptions about what's spawning when

arctic ibex
north kiln
#

and presumably bebe1 and 2 are also chickens

arctic ibex
#

the second chicken prefab also has everything assigned

#

bebe1&2 both have it assigned

north kiln
#

At this point, break out the debugger

arctic ibex
languid spire
#

one thing we haven't seen. The chicken script from the scene

north kiln
#

apparently it's fine, and they seem adamant about things

languid spire
#

hmmm, heard that before

arctic ibex
#

in the first message

languid spire
#

where?

arctic ibex
north kiln
#

Damn, discord hides the other two from me

arctic ibex
languid spire
#

I only see one

arctic ibex
languid spire
#

Damn I hate that 'feature'

#

Ok, the only think I can think of is that there are multiple chicken scripts on the prefab or scene object

sonic dome
sonic dome
#

makes sense

#

wait

#

done

wintry quarry
sonic dome
#

maybe cuz this script is on the virtual cam which follows the player?

wintry quarry
#

Show the hierarchy and which components are on which objects

sonic dome
#

nvm

#

fixed it

rapid valve
#

I have script to make the character move but the character will net move

#

how do I fix this

#

and it has a animation

north kiln
eternal falconBOT
sonic dome
north kiln
#

Certainly is a problem that the axes are named differently; presumably there's warnings in the console. However, it needs to be addressed after the IDE is configured

rapid valve
#

Is this a good script to use

#

after I configured my ide

north kiln
#

Look at the console window and address any errors/warnings in it, because this certainly isn't correct

rapid valve
#

it gave this error

sonic dome
rapid valve
sonic dome
#

Rigid body is easier to use as u can use the unity Phys system and ig in character controller u have to do a lot by yourself like even for gravity u need to add a force pushing yourself down

wintry quarry
#

Fix your basic errors first before overhauling your whole system

rapid valve
#

ok

#

but I am not sure how I identify the error

wintry quarry
sonic dome
rapid valve
sonic dome
#

Well that would help

#

And also just cross check the spelling vertx pointed from the video

rapid valve
#

this is the video that I copying from

sonic dome
#

Ya so do u see the difference?

wintry quarry
rapid valve
#

I am trying to do that

sonic dome
sonic dome
rapid valve
#

yes

sonic dome
#

🔥🔥🔥

rapid valve
#

I did it correctly but the player will still won't move the animation kinda makes him move

sonic dome
#

Send your code

tiny bloom
#

anyway I can change these rules? I want it to be _ and not camelCase

rapid valve
#

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

public class PlayerMovement : MonoBehaviour
{
public float speed;
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
    float horizontalInput = Input.GetAxis("Horizontal");
    float verticalInput = Input.GetAxis("Vertical");

    Vector3 movementDirection = new Vector3(horizontalInput, 0, verticalInput);

    transform.Translate(movementDirection * speed * Time.deltaTime);
}

}

sonic dome
rapid valve
#

how do I fix that

sonic dome
#

Did u download the animation from mixamo?

rapid valve
#

yes

sonic dome
#

There is an option "in place" u have to check it before downloading

rapid valve
#

I used this video

#

there is no in place

sonic dome
#

Select the animation 1st

warm stag
#

Hey guys, I'm following a tutorial online and made two scripts. There are no errors within the Visual Code and I'm like 99,99% sure I don't have any typo there or anything, I checked the code so many times that my head hurts now lol. Unity is giving me:

Assets\Scripts\Hit Components\HitBox.cs(9,23): error CS0246: The type or namespace name 'HitData' could not be found (are you missing a using directive or an assembly reference?)

But in the code itself HitData is properly defined and even Visual Studio knows where it is defined and where it is used etc. (I tried typing HitData with a typo just to test this and instantly I get the error in Visual Code, but there are no errors otherwise) So it seems like Unity can't communicate properly with the script files for some reason?

Here is the HurtBox.cs that defines public struct HitData: https://hastebin.com/share/owuquzenoq.csharp
And here is the HitBox.cs that gives the error: https://hastebin.com/share/exatirorih.csharp

I also attach the screenshot of my project folder to see the hierarchy.

north kiln
rapid valve
north kiln
sonic dome
warm stag
rapid valve
sonic dome
rapid valve
keen dew
rapid valve
sonic dome
#

just select the animation

#

skin doesnt matter

rapid valve
#

and download it ?

sonic dome
#

no

#

check in place 1st

#

is there any way i can compare this hit with a layer?

#

ignore the 1st vector3.back parameter

static bay
sonic dome
#

yea

#

thanks

#

what am i doing wrong?

languid spire
#

you cannot compare a RayCastHit to a LayerMask, that makes no sense

sonic dome
#

hmm makes sense

arctic ibex
#

Ah yes, the artof the bodge. I'm almost certain this is the worst possible way to do this but hey. It works.

sonic dome
#

wait

#

i got it

#

layerMask = DefaultRaycastLayers

#

something like this

languid spire
languid spire
sonic dome
#

shouldnt something likt this work?

warm stag
# keen dew You could try moving HitData to its own file. Sometimes Unity only sees the Mono...

Ok so I'm trying this

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

public class HitData : MonoBehaviour
{
    public int DamageValue;
    public Vector3 HitDirection;

    public HitData(int damageValue, Vector3 hitDirection)
    {
        DamageValue = damageValue;
        HitDirection = hitDirection;
    } 

}```

The problem is, now it is a class and not a struct.. if I try to have a struct with same name as class it doesn't work, but if I rename the class to something else it's basically the same as before, no? When it's a class like this I get "Assets\Scripts\Hit Components\HurtBox.cs(31,32): error CS1729: 'HitData' does not contain a constructor that takes 2 arguments" which I suppose is connected to it now being a class and not a struct.
languid spire
sonic dome
#

which types?

languid spire
#

float and int

sonic dome
#

for the max dist of the ray and all

languid spire
#

you do not specify the type in the call only in the method signature

keen dew
sonic dome
#

wait

#

let me try another way

warm stag
sonic dome
#

how should i compare the hit info with the layer

languid spire
sonic dome
#

ya i get it but how do i compare hte layer?

keen dew
#

I meant that if you have something in addition to the MonoBehaviour class in the same file then it doesn't register the other stuff. Not that everything has to be a MonoBehaviour

sonic dome
#

how do i get the the layer info after hitting it

gaunt ice
sonic dome
#

hmm i get it ig

#

wait

#

something like this?

languid spire
#

no

#

does GameObject have a LayerMask property? I dont think so. Go look up the docs instead of just trying random shit

rapid valve
#

@sonic dome my character does not have a in place option

#

so I am not sure what to do I thinK I somehow need to put it in place in blender

warm stag
# keen dew I meant that if you have something in addition to the MonoBehaviour class in the...

It worked!! Dude, thank you. Still had one issue that I think I solved in a not so great way lol. Basically when I put the struct to it's own script file, this line (in HurtBox.cs) started giving me error that HitData doesn't have a constructor that takes 2 arguments:

hitbox.Hit(new HitData(_damageAmount, -hit.normal));

so I simply changed it to:

hitbox.Hit(new HitData());

And now it works... But I suppose those two were there for a reason lol and they weren't giving this error when the struct was defined in the same file... Any idea how I could fix this?

keen dew
#

Can you show the HitData file you made

gaunt ice
#

where is the constructor? how you define it

warm stag
#

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

public struct HitData
{
public int DamageValue;
public Vector3 HitDirection;

public HitData(int damageValue, Vector3 hitDirection)
{
    DamageValue = damageValue;
    HitDirection = hitDirection;
}

}

gaunt ice
#

did you save the script

warm stag
#

yes this is saved as HitData.cs

keen dew
#

On this line: hitbox.Hit(new HitData()); ctrl-click on HitData and see where it goes

languid spire
#

this
hitbox.Hit(new HitData());
should not work. you have no default constructor

sonic dome
#

why is this code working and not mine

warm stag
#

it goes to public struct HitData line in HitData.cs, so it seems to know where it is

languid spire
warm stag
gaunt ice
#

struct has a default parameterless constructor

sonic dome
north kiln
sonic dome
#

😭 makes sense

languid spire
warm stag
#

I just don't understand why the line

hitbox.Hit(new HitData(_damageAmount, -hit.normal));

worked when the struct was defined in the same file, but it didn't when I moved it elsewhere EVEN THOUGH when I click on HitData it goes straight to the new file... And I mean VisualCode wasn't giving me the error it was Unity.. I feel my Unity has some sort of problem knowing where things are

sonic dome
#

hope this works

#

no it doesnt

warm stag
# keen dew Show the full error message

"Assets\Scripts\Hit Components\HurtBox.cs(31,32): error CS1729: 'HitData' does not contain a constructor that takes 2 arguments"

But I tried to rewrite the line from scratch and it seems to not give any errors now... Maybe it's finally fixed. Thank y'all.

somber sun
#

Hi, i need help trying to flip a group of sprite, sorry to repost this here i didnt get help at the 2d tools

languid spire
#

A) This is a code channel
B) Do not post photos

sonic dome
shell herald
stone elk
#

how can i change a button's text through script?

ionic zephyr
#

does anyone know a way to make my character face the direction I last moved to whenever I stop moving it?

languid spire
sonic dome
#

JASDUASHDUAHSDASDH

#

then just tell me

#

how to do it

languid spire
#

no

sonic dome
#

nice

languid spire
#

you are here to learn not to get handouts and be spoonfed

sonic dome
#

well okk let me see yt tutorials

languid spire
#

you would be better off with !learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

deep quarry
#

Yo, can't seem to get my Particle System working.
This is my script for how I turn on/off the particles:

        if(Input.GetKey(KeyCode.LeftShift))
        {
            accelerating = true;
            thrust.Play()
            Debug.Log("Started Thrust");
        }
        else {
            accelerating = false;
            thrust.Stop();
            Debug.Log("Stopped Thrust");
        }

The method is called, since I recieve my Debug.Log() messages in the console, but the Particle System doesn't start.

#

also, the particles works in scene view

faint sluice
modest dust
#

You're only stoping the particle system in the else part

#

You're never starting it

deep quarry
languid spire
#

this in update?

deep quarry
languid spire
#

so you are calling Play every frame when the key is held down

deep quarry
#

Oh

#

Yea

languid spire
#

not what you want I think

deep quarry
#

So I should only start it once, and then when I release the key I should stop it, right?

languid spire
#

yes

deep quarry
#

Ah, I see. Thank you!

deep quarry
languid spire
deep quarry
odd valley
#

how do I play an audio clip only when I want to play it ;-;

#

I've tried a few different methods its always playing as soon as the asset is loaded

languid spire
#

turn off play on awake

odd valley
#

oh

#

omg I'm stupid

#

thx

sleek relic
#

hello every one

#

Im starting to program using unity

#

And i dont understand how does the "do" command work

#

can someone explain it?

languid spire
#

you mean do { } until (condition) ?

sleek relic
#

yes i think

languid spire
#

it is a looping construct which is always guaranteed to execute at least once

verbal dome
#

How often do you use that Steve?

languid spire
#

not often

verbal dome
#

I've used do like a handful of times

#

Useful when you need a loop that executes at least once

#

Only used do-while though

languid spire
#

it does have it's uses but they are very rare

meager steeple
#

how would i add a function to a button, like change the colour of the text, and add audio when you hover over it?

verbal dome
languid spire
#

that wont work for Hover

verbal dome
#

Oh I totally missed the hover part

languid spire
#

I think you need to implement the IPointer interfaces

sleek relic
#

hey steve, can you give me an opinion on my code?

verbal dome
#

Yeah that

languid spire
eternal falconBOT
hollow palm
#

hello, im currently facing a problem with my rigidbody character when move while jump. It jump normal when idle, but floating when moving. Any idea what wrong in my script?

languid spire
modest dust
#

You modify the velocity directly in Movement()

verbal dome
#

One way to solve it is to use AddForce instead of velocity when you are jumping/falling/not grounded

sleek relic
#
using JetBrains.Annotations;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UIElements;

public class CharacterScript : MonoBehaviour
{
    public Rigidbody2D CharacterRigidBody;
    public float CharacterJumpStrenght = 20;
    public float CharacterMoveSpeed = 10;
    public int MovementState = 0;
    public SpriteRenderer spriteRenderer;
    public int JumpsLeft=0;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame


    void Update()
    {


        //Inputs

     
  
        if(Input.GetKeyDown(KeyCode.Space) && JumpsLeft > 0)
        {
            CharacterRigidBody.velocity = Vector2.up * CharacterJumpStrenght;
            JumpsLeft = JumpsLeft - 1;
        }

        if (Input.GetKeyDown(KeyCode.A))
        {
            MovementState = -1;
            spriteRenderer.flipX = true;
        }

        if (Input.GetKeyDown(KeyCode.D))
        {
            MovementState = 1;
            spriteRenderer.flipX = false;
        }

        //Input Stops
        if ((Input.GetKeyUp(KeyCode.A) && MovementState== -1) || (Input.GetKeyUp(KeyCode.D) && MovementState == 1))
        {
            MovementState = 0;
        }


        //Input Responses
        if (MovementState == -1 || MovementState == 1)
        {
            transform.position = transform.position + (Vector3.right * CharacterMoveSpeed * Time.deltaTime * MovementState);
        }

    }

    //Jump Recharge
    private void OnCollisionEnter2D(Collision2D collision)
    {
        JumpsLeft = 2;
    }


}


The code is for character movement

verbal dome
#

See the Large Code Blocks in the bot's message

hollow palm
languid spire
#

but velocity in Movement

verbal dome
verbal dome
#

Currently it will always override your velocity if you are holding movement keys down

hollow palm
#

should i change the velocity to addforce just like jump?

languid spire
#

no @sleek relic

verbal dome
#

This is just one way to solve it

hollow palm
#

i see, thank u

verbal dome
#

You can also have a cooldown/timer that disables walk forces for a short while as you jump

sleek relic
languid spire
eternal falconBOT
languid spire
#

Large Code Blocks

sleek relic
celest spoke
verbal dome
#

You can put the game view and animator window next to each other while playing so you get a better idea of whats going on

languid spire
# sleek relic https://paste.myst.rs/7bcno76s <@556797857584381953>

Honest opinion
Class name does not need to contain the word Script, we know its a script
Variable names misspelt
Variable name convention not consistent
Empty method
MovementState is not a state
Hard coded value for JumpsLeft
Mixing Transform and Rigidbody movement
Velocity not taking into account existing velocity
Conclusion: Not very good at all

verbal dome
#

Looks like it is playing twice every time

swift mango
#

I have 0 experience worth it to learn ?

verbal dome
#

@celest spoke You are using a Bool parameter, use a Trigger instead

#

Trigger is a bool that gets set to false when it is used

celest spoke
#

do you mean in my code?

verbal dome
#

In your code and in the animator

#

In the animator make attacking a trigger instead of bool

#

And in code use SetTrigger instead of SetBool

#

The problem currently is that attacking is true for at least two frames so the transition gets triggered twice

celest spoke
#

should i remove true and false in my code aswell? Because now i get error that says "SetTrigger does not take 2 arguments"

verbal dome
#

Yes

#

You use SetTrigger to set it to true and ResetTrigger if you ever need to cancel it

celest spoke
#

well now nothing is working

verbal dome
#

You probably don't need to ResetTrigger here

celest spoke
#

my character is flying around and cant use attacks

verbal dome
#

Did you change it to a trigger in the animator?

#

And did you reassign the transition conditions to use that trigger (in case they disappeared)

swift crag
#

You might want to get rid of the condition and create it again

#

I distinctly remember having a problem when I changed a parameter from float to bool

#

The condition turned into a boolean condition set to "true"

#

but the condition didn't work

#

something was stuck behind the scenes

#

this was on a VRChat avatar, so it was a reasonably old version of unity

celest spoke
#

so now its all working again but now i do dubble to the right and up, and triple to the left and down haha

#

insted of single and dubble

verbal dome
#

Then your SetTrigger is being called twice thrice

#

Time to show your !code

eternal falconBOT
celest spoke
verbal dome
#

        animator.SetTrigger("attacking");
        currentState = PlayerState.attack;
        yield return null;
        animator.SetTrigger("attacking");```
#

You are indeed setting the trigger twice

celest spoke
#

wait wait i think i found the problem

verbal dome
#

I guess you used to set the bool to false where you now have the second SetTrigger

#

You don't need that, triggers go false automatically

celest spoke
#

so should i remove the second trigger?

verbal dome
#

Also is there a reason you are using GetMouseButtonUp instead of GetMouseButtonDown?

#

Attacking on mouse release is a bit weird

celest spoke
#

i just followed a tutorial, did exactly what the dude told me to and now its not working like his is

frosty hound
#

That would assume you didn't do it exactly like they did

#

But if you want to stick to that claim and get added to the counter, then show your code and what tutorial you're using.

#

(If you haven't fixed it)

celest spoke
#

the only difference i did was that he used spacebar for attack and i used left click

#

i just dont see how right and up is correct but down and left is wrong

swift mango
#

@frosty hound may I please dm you ?

frosty hound
#

No

swift crag
#

What part of "ask your question" do you not understand?

frosty hound
swift crag
#

Just ask it.

celest spoke
swift crag
#

Even if you think it's just one line, it's really important to make sure we're all seeing the same thing

frosty hound
#

Also what tutorial this is from?

swift mango
swift crag
#

no, nobody is going to "steal" your game idea

swift mango
swift mango
verbal dome
swift crag
#

Ask the goddamn question or stop bothering us.

#

I'm certain it's not as "confidential" as you think it is

verbal dome
#

The top comment has a bunch of fixes for it too

swift crag
#

hey, if textbooks can have errata...

#

(:

celest spoke
verbal dome
#

What's the current problem?

celest spoke
#

and i find the tutorial fun and interesting as a new person to this but w/e

#

the problem is that when i attack to the right and up i hit 1 time with my sword, and when i attack left and down it attacks 2 times. I only want it to attack 1 time no matter the direction

verbal dome
#

It's probably fun and interesting. But all the comments are about fixing stuff in the tutorial

verbal dome
#

Sounds like they are different

#

And disable loop on the animation clips

celest spoke
#

removing the loop makes it so that i do 1 stab in every direction so that works, however its not making the full animation so it looks funny

long scarab
#

Hey guys, anyone have experience with raycasts?

            mouse.z = 10;
            Ray ray = Camera.main.ScreenPointToRay(mouse);

            if (Physics.Raycast(ray, out RaycastHit hit, 10)) {
            }

have this tiny code and am clicking on an object with mesh, yet having no hits (I removed the internals of if for simplicity)
My Physics Raycaster object is on my main camera and set to the layer the object I want to hit is in

#

any ideas what might cause it?

verbal dome
celest spoke
#

Ok i dont know how i fixed it but now everything is working as it should

#

but thanks for all the help ❤️

swift crag
#

oh, you mean you named this thing "Physics Raycaster"?

#

please show us the entire script

#

don't remove anything from your code

#

i can handle reading more lines, but I can't deal with not seeing code that could be causing your problem

long scarab
#

no no

#

I mean

stuck jay
#

Could arrays be used to make two variable types related (as in, a string for AmmoType and an integer for AmmoMaxCap)

long scarab
swift crag
#

I've never used this thing before

cosmic dagger
swift crag
#

This has nothing to do with using Physics.Raycast

long scarab
#

I am not sure I am using it either, but I recall it enabled the raycasts globally

swift crag
#

I need to see what you're actually doing. Please humor me.

long scarab
#
            Vector3 mouse = Input.mousePosition;
            mouse.z = 10;
            Ray ray = Camera.main.ScreenPointToRay(mouse);

            if (Physics.Raycast(ray, out RaycastHit hit, 10)) {
                Debug.Log("x");
            }```
#

amazingly game changing

swift crag
#

That's not the entire script. That's a few lines.

#

How do you know that your raycast is even running?

long scarab
#

I did Debug.DrawRay

swift crag
#

well, you didn't show me, so I couldn't know (:

long scarab
#

the other parts of the script has nothing to do with this

#

and cannot affect it in any way

#

in debugging I can also see the origin and direction of the ray

swift crag
#

why are you fighting with me? i'm trying to help you.

long scarab
#

I am not fighting you, but there is simply nothing else

swift crag
#

Share the entire script, including your Debug.DrawRay code. I need to see exactly what is going on.

cosmic dagger
#

So the code above is everything in your script?

long scarab
#

I removed the debug since

swift crag
#

If you knew what was and wasn't relevant, you'd be able to solve your problem

long scarab
#

I put it on my camera

#

so its permanent

swift crag
#

you put what on your camera?

long scarab
#

the ray from camera to mouse

#

you know, to see it should trigger

long scarab
#

OnPointerClick of IPointerClickHandler

verbal dome
swift crag
#

Why don't you just share the code instead of making us play a game of 20 questions?

long scarab
#

okay

#

full code

#
        if (eventData.button == PointerEventData.InputButton.Right) {
            if (drawing != null) { drawing.IsExtending = false; toggleDrawUI.isOn = false; drawing = null; }

            Vector3 mouse = Input.mousePosition;
            mouse.z = 10;
            Ray ray = Camera.main.ScreenPointToRay(mouse);

            if (Physics.Raycast(ray, out RaycastHit hit, 10)) {
                Debug.Log("x");
            }
  }
}
swift crag
#

This must be a joke. We've asked you to share the full script over and over and you keep sending us snippets.

long scarab
#

its a method

#

there is notghing like full script

verbal dome
#

Why do you need a raycast here?

#

You are already using OnPointerClick which raycasts to the UI

long scarab
#

well my eventData for some reason dont catch the item

#

I tried testing if ray will

swift crag
#

I see nothing here that proves this code is even running

#

This code will run when a UI element is clicked on, and will try to do a raycast against physics objects in the scene

verbal dome
#

We don't even know if it implements the interface

swift crag
#

we don't know much of anything!

verbal dome
#

🤷‍♂️

swift crag
#

I'm going to ask one last time: share the entire script.

#

we're not going to steal it

long scarab
#

Full script then

public class ClickController : MonoBehaviour, IPointerClickHandler, IPointerMoveHandler {
public void OnPointerClick(PointerEventData eventData) {
        if (eventData.button == PointerEventData.InputButton.Right) {
            if (drawing != null) { drawing.IsExtending = false; toggleDrawUI.isOn = false; drawing = null; }

            Vector3 mouse = Input.mousePosition;
            mouse.z = 10;
            Ray ray = Camera.main.ScreenPointToRay(mouse);

            if (Physics.Raycast(ray, out RaycastHit hit, 10)) {
                Debug.Log("x");
            }
  }  
}
public void OnPointerMove(PointerEventData eventData) {
        //Debug.Log("<color=#" + ColorUtility.ToHtmlStringRGB(GetColour(eventData.pointerCurrentRaycast, transform.parent)) + ">PIXEL</color>");
    }}


long scarab
swift crag
#

Great.

Now, prove that OnPointerClick is actually running by logging something inside of it.

long scarab
#

it is

swift crag
verbal dome
#

Does your scene have an EventSystem component?

long scarab
#

then it would throw exception of not implementing interface

#

yep

verbal dome
swift crag
#

and the method wouldn't be called

long scarab
#

Yes I have eventsystem

swift crag
long scarab
#

You must trust me then

swift crag
#

remember that:

  • we don't know what you know
  • we can't see your screen
long scarab
#

I told you what I know

#

this is really going in circles

verbal dome
#

Fen is trying to teach you how to debug

long scarab
#

I know how to debug

swift crag
#

I'm trying to get you to communicate properly.

verbal dome
#

Then where's your log to prove it is running?

swift crag
#

It's going in circles for a reason.

long scarab
#

I dont need log for such simple things

swift crag
#

What if it isn't?

long scarab
#

I used Debug.DrawRay for debuging if the ray hits the item before

swift crag
#

You didn't use it anywhere in that code.

swift crag
long scarab
#

yes

#

I know how to debug

swift crag
#

Good. That's what I was looking for.

long scarab
#

skip this gaslighting please

#
        Debug.DrawRay(ray.origin, ray.direction * 20, Color.white);```
#

I also used this for camera update

swift crag
#

That's enough. Someone else may help you.

#

Good luck.

long scarab
#

So I could see the ray is actually going through the item

#

Not sure why are you acting so weird

#

You should trust someone's words more next time imo

verbal dome
#

Don't expect us to know your experience level. We are asking reassuring questions for a reason, it's a beginner channel

long scarab
#

And I answered all of them

#

but he wanted proofs all the time

verbal dome
#

While calling it 'gaslighting'

languid spire
long scarab
#

Fortunately not

#

I apologize

#

I might have overextended

polar acorn
# long scarab You should trust someone's words more next time imo

Search this channel for posts by me containing the words "The counter" and you'll see why we don't take anything people post here at face value without evidence. Sorry that you got caught up in it but sometimes when all the signs point to one problem but someone swears up and down it's not the case, the simple solution is that person is mistaken.

ionic zephyr
#

does somebody know how to make my character face the way it was moving before it stops

long scarab
#

yeah ik

#

its just that there is literally no code related to this

verbal dome
long scarab
#

so I thought I shouldnt include it

#

cause there is no way it affects the new raycast

verbal dome
long scarab
#

yes

#

and is on 0 layer

#

I also checked the mesh in wireframe

#

and tried convex

ionic zephyr
#

Zelda style

ivory bobcat
#

Does it log x?

ionic zephyr
#

sorry?

verbal dome
long scarab
#

it wont detect the hit

#

yes, camera is, one sec

ivory bobcat
#

So if you get no logs, there's a possibility the code isn't running

long scarab
polar acorn
# long scarab I also checked the mesh in wireframe

I only just arrived but from some scrolling, it seems you're having issues detecting something with a Raycast. Remember that mesh colliders are one-sided. If this mesh's normals are backwards it wouldn't detect a ray unless it struck the inside of a polygon

verbal dome
# ionic zephyr 2D Rpg

Then you probably want to tell the animator which way you are moving. Make parameters for MoveX and MoveY directions in the animator and control your sprites/animations with that

verbal dome
long scarab
#

and I can see it so the normals should be fine

ivory bobcat
long scarab
#

otherwise they would point towards the side and I wont be able to see them

verbal dome
long scarab
#

good idea

polar acorn
long scarab
#

hit

#

okay well then there must be some mesh collider issue

ivory bobcat
long scarab
#

so I used 3D mesh collider too

long scarab
#

and it works for all my other items

verbal dome
#

Can you show your mesh generation code?

long scarab
#

technically I added the 3D Raycaster just because I did not know how to make it 2D like my other items

polar acorn
long scarab
# verbal dome Can you show your mesh generation code?
            trianglesList.Clear();
            Vector3 endPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            endPoint = transform.InverseTransformPoint(endPoint);
            endPoint.z = transform.position.z;
            float stemWidth = Mathf.Log(Camera.main.orthographicSize + 100) - 4.557f;
            float distance = Vector3.Distance(transform.position, endPoint);

            Vector3 perpendicularVector = new(-endPoint.normalized.y, endPoint.normalized.x, 0f);
            Vector3 normalVector = 0.3f * distance * new Vector3(-endPoint.normalized.x, -endPoint.normalized.y, 0f);

            verticesList.Add(perpendicularVector * stemWidth);
            verticesList.Add(-perpendicularVector * stemWidth);
            verticesList.Add(endPoint + (perpendicularVector * stemWidth) + normalVector);
            verticesList.Add(endPoint - (perpendicularVector * stemWidth) + normalVector);

            trianglesList.Add(0);
            trianglesList.Add(1);
            trianglesList.Add(3);
            trianglesList.Add(0);
            trianglesList.Add(3);
            trianglesList.Add(2);
            
            verticesList.Add(endPoint + (2 * stemWidth * perpendicularVector) + normalVector);
            verticesList.Add(endPoint - (2 * stemWidth * perpendicularVector) + normalVector);
            verticesList.Add(endPoint);
            trianglesList.Add(4);
            trianglesList.Add(6);
            trianglesList.Add(5);

            for (int j = 0; j < verticesList.Count; j++) {
                Vector3 n = new(verticesList[j].x, verticesList[j].y, transform.position.z);
                verticesList[j] = n;
            }


            mesh.vertices = verticesList.ToArray();
            mesh.triangles = trianglesList.ToArray();```
#

its simple arrow

#

but I wanted more objects in the future

verbal dome
#

And maybe some of the other RecalculateX methods, I don't remember which ones are necessary

long scarab
#

all righty

#

trying all three

#

seems like not

verbal dome
#

If you look at the mesh from behind, you can't see the faces right?

long scarab
#

I cant yes

#

should I recreate everything and make something like LineRenderer instead or

verbal dome
#

I have no idea about VR/AR stuff but what if you remove thet second parameter from your ScreenPointToRay

long scarab
#

You mean inside the arrow creation?

long scarab
#

oh no yeah

#

actually I removed it since then

now its

public void OnPointerClick(PointerEventData eventData) {
        if (eventData.button == PointerEventData.InputButton.Right) {
            if (drawing != null) { drawing.IsExtending = false; toggleDrawUI.isOn = false; drawing = null; }

            Vector3 mouse = Input.mousePosition;
            mouse.z = 10;
            Ray ray = Camera.main.ScreenPointToRay(mouse);

            if (Physics.Raycast(ray, out RaycastHit hit, 10)) {
                Debug.Log("x");
            }```
ivory bobcat
#

We can't see the scene, inspector/components, hierarchy or anything that may be important. Maybe the collider isn't where we think it is?

long scarab
#

I can screen everything if needed

#

well when I made the collider convex I could see it better

verbal dome
ivory bobcat
#

We wouldn't know if something is wrong with it, we can't see it.

long scarab
#

You just have to tell me what you want to see haha

#

I ll get you the arrow with collider I guess

#

oh, now the collider is a box when I made it convex

#

it used to copy the arrow shape

#

Maybe due to the RealculareNormals?

#

Commenting out and testing

#

this is now convex

#

I ll try to get screen how it used to be

#

okay, cant get it back 😐

#

its not because of the normal recalc

#

I mean I would totally skip raycasting and use the PointerEventData eventData if I could

#

but for some reason the OnPointerClick PointerEventData eventData is detecting just my 2D sprites/objects

radiant glen
#

Hello, I am getting this error for my code, followed a tutorial for it and dont really know what is wrong, any help is greatly appreciated thank you!

rare basin
#

configure your IDE

topaz pendant
#

you wrote SterializeField instead of SerializeField

rare basin
#

there is no such thing as SterializeField, configure your IDE

#

!ide

eternal falconBOT
ivory bobcat
#

Typo

radiant glen
#

Thank you so much, I have my IDE but my intelasense has been acting up

rare basin
#

you dont have IDE configured