#💻┃code-beginner

1 messages · Page 186 of 1

rare basin
#

just want to take a look

north kiln
#

Just stop addressing them

barren aurora
rare basin
north kiln
rare basin
#

also please stop dming me

barren aurora
tight saffron
#
public class PlayerMovement : MonoBehaviour
{
    private Rigidbody2D rb;
    private SpriteRenderer sprite;
    private Animator anim;

    private float dirX = 0f;
    private float dirY = 0f;
    [SerializeField] private float jumpForce = 12f;
    [SerializeField] private float moveSpeed = 7f;

    private enum MovementState { idle, running, jumping, falling, }

    public bool ClimbingAllowed { get; set; }

   
    private void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        sprite = GetComponent<SpriteRenderer>();
        anim = GetComponent<Animator>();
    }

   
    private void Update()
    {
        dirX = Input.GetAxisRaw("Horizontal");
        rb.velocity = new Vector2(dirX * moveSpeed, rb.velocity.y);
       
        if (ClimbingAllowed)
        {
            dirY = Input.GetAxisRaw("Vertical") * moveSpeed;
        }

            if (Input.GetButtonDown("Jump"))
            {
                rb.velocity = new Vector2(rb.velocity.x, jumpForce);
            }

        UpdateAnimationUpdate();
    }

    private void UpdateAnimationUpdate()
    {
        MovementState state;

        if (dirX > 0f)
        {
            state = MovementState.running;
            sprite.flipX = false;
        }
        else if (dirX < 0f)
        {
            state = MovementState.running;
            sprite.flipX = true;
        }
        else
        {
            state = MovementState.idle;
        }

        if (rb.velocity.y > .1f)
        {

            state = MovementState.jumping;

        }

        else if (rb.velocity.y < -.1f)

        {
            state = MovementState.falling;
        }

        anim.SetInteger("state", (int)state);
    }

    private void FixedUpdate()
    {
        if (ClimbingAllowed)
        {
            rb.isKinematic = true;
            rb.velocity = new Vector2(dirX, dirY);
        }
        else
        {
            rb.isKinematic = false;
            rb.velocity = new Vector2(dirX, dirY);
        }
    }
}
eternal falconBOT
rare basin
#

psate it to external site

barren aurora
north kiln
#

Great, well if you're posting here in future without a configured IDE you will be banned. Have fun

barren aurora
tepid summit
#

omg

#

what is bro on about

teal viper
fickle plume
#

@barren aurora Don't send unsolicited DMs as well. Consider that as addon to the previous warning.

west sonnet
#

I want to make a trigger happen when a collision happens with an object of a specific tag. Is it a good idea to check for the tag name on collision?

#

Or is it slow?

fickle plume
#

That is one of the purposes of tags.

ivory bobcat
fickle plume
#

If you can filter it previously using collision matrix that would be more optimal though

barren aurora
# fickle plume <@176068058241171456> Don't send unsolicited DMs as well. Consider that as addon...

Is it all right now?

Is there no more peace ?
Guys : I've been here for the first time,
Asked one single question to which you get no answer,

and helped someone with a problem.
stop it, it has to be good for once! Or is this going on for 3 days now, that someone has to mention me all the time ?

I lived well without you until then,
You don't get any help with the Package Manager, which doesn't download anything,

and for the integration of a Java code, I'm wrong here, all good so far.

But: Apart from that, this thing is slowly coming to an end.
That's enough! You want to play a bit important, then do it.
But leave me out of it! I've lived well without you so far, and I'll continue to do so! I've never asked for code here otherwise.

So keep your head down!

rare basin
#

jezus you again

#

thought you don't have time

fickle plume
#

!mute 176068058241171456 3d Stop spamming. Listen to moderation and advise.

eternal falconBOT
#

dynoSuccess smokingheadstudio was muted.

west sonnet
#

If I create a [SerializeField] and input a value, but then I change it in the inspector. Does the inspector or the script take priority? And will it automatically change respectively?

languid spire
#

Inspector

west sonnet
#

So, there's no problem with me changing values in the inspector, other than that it might just be confusing seeing two different values?

languid spire
#

correct. the confusing bit may be that if you add the script again it will take the value of the script at that time

west sonnet
#

ahh, I see. Is there a way to update the script with the values in the inspector, other than going into the script and manually chaning values?

languid spire
#

yes, you can do a Reset of the component in the inspector

west sonnet
#

Okay, thank you

west sonnet
languid spire
#

Sorry, no that is the other way round, it updates the Inspector with the values from the script

west sonnet
#

Oh yeah

languid spire
#

The inspector cannot update the script

west sonnet
#

Need some help. I'm making a power up that will temporarily increase the players speed. On the DeactiveBuff() Method, i want to make the players speed back to the original value, but I'm not sure how/where I can store it in my script

languid spire
#

you already are doing, you just need to NOT make RegularSpeed a local variable

west sonnet
#

Hmmmmm, how would I do that?

languid spire
#

by removing the float and declaring the variable in class scope

west sonnet
#

i'm still not sure what you mean 😦

#

I've removed the float, but where would I place the line?

#

Oh wait

languid spire
#

where do you have your other variable declarations?

west sonnet
#

Yes, figured it out

#

Thank you

modest dust
# west sonnet i'm still not sure what you mean 😦

{ } is your scope.
If you declare something within a scope, it is only accessable within that scope and child scopes.
If you declare a variable within the Start method scope, it only exists until the Start method end. So you need to declare it within the class scope as Steve said

west sonnet
languid spire
#

no, that's good

languid spire
west sonnet
languid spire
#

I meant the Invoke keyword. Just call the method

west sonnet
#

I used BuffTime to determine how long the effects should last

languid spire
#

Coroutine would be better

modest dust
kindred halo
#

how do I reference the gameobject with the required script it has

languid spire
#

what is the declaration of m4?

kindred halo
#

It's M4

languid spire
#

what type

kindred halo
languid spire
languid spire
#

do you have a reference to the GameObject it is on?

#

or is it on the same game object as this script?

kindred halo
#

same gameObject

languid spire
#

then ... m4 = gameObject.GetComponent<M4>();

kindred halo
#

oh wait you meant that
That would probably go on the projectile script then
the code I showed
I was trying to reference the m4 gameobject with the M4 script

languid spire
#

you need to put this on the script that Instantiates Projectile

#

not on projectile itself

kindred halo
#

like this?
projectile.m4 = gameObject.GetComponent<M4>();

languid spire
#

yes

#

presuming this game object has a M4 script

kindred halo
languid spire
kindred halo
languid spire
#

is this script the M4 script?

kindred halo
#

yeah

languid spire
#

then you just need

projectile.m4 = this;
#

forget the rest

kindred halo
#

It works
Thanks man

pseudo ermine
#

I am trying to set the mine active status to false, however it does not seem to work.

Any ideas?

languid spire
pseudo ermine
languid spire
#

that would suggest that your reference to mine is incorrect so make sure to debug it's GetInstanceID

pseudo ermine
#

I get this error when on the 2nd mine.

languid spire
#

and that line is?

pseudo ermine
languid spire
#

so camera is null

pseudo ermine
#

so, how would I fix that? I have tried every way I can think.

languid spire
#

post your full !code

eternal falconBOT
languid spire
#

why new ?
public new CinemachineVirtualCamera camera;

#

that looks like a variable that should be set in the inspector but I guess it's not for mine2

languid spire
#

the error message would disagree with that

pseudo ermine
#

Yeah, its an issue with camera.follow = mainPlayer, the mainPlayer gameObject is a transform.

languid spire
#

the problem is the camera variable it is null

rich adder
# pseudo ermine

line 115 in code you sent is mineDefusedCounter.SetActive(true);

languid spire
#

so mineDefusedCounter is null
@rich adder good catch

#

cant be line 34 would give NRE

pseudo ermine
#

here, let me provide both scripts I am currently working with.

rich adder
#

true, something must be different maybe from what they sent

pseudo ermine
rich adder
#

ok cause screenshot says ,error comes from minigameMovementline 115

#

but that means you should also have another error on line 34

pseudo ermine
languid spire
#

thats better so it is camera

#

possible multiple instances
Debug.log this GetInstanceID

#

in Start

pseudo ermine
timid saffron
#

can you write me a very basic example of code block that simulates: gravity 0 for 5 seconds gravity 1 for second?

languid spire
#

ok, so mine manager gets a camera but movement does not

rich adder
pseudo ermine
#

I fixed it.

timid saffron
#

is it something like that

pseudo ermine
#

I added this line to minigame movement: camera = GameObject.FindGameObjectWithTag("Vcam").GetComponent<CinemachineVirtualCamera>();

and it seemed to have fixed it.

rich adder
#

I used to use game maker

timid saffron
#

okay

rich adder
#

Coroutine is very similiar

timid saffron
#

then I set a variable in start event for corotine

#

then in update event i write the code

#

i guess

rich adder
#

no?

timid saffron
#

is there something like corotine event?

rich adder
#

perhaps lookup how a coroutine works first

timid saffron
#

that sounds reasonable

pseudo ermine
rich adder
#

the score?

timid saffron
#

I think I saw somewhere while messing around unity before there was a component that adjusted how much the player gets affected by gravity like -1000 and 1000 something like that.

#

I cant seem to find it now

pseudo ermine
orchid shoal
#

Greetings all! How can I make this one more optimized, it rotates objects around the center. I have 20 different objects rotate around the center, for some reason it loads RAM, maybe there is a variant to do more optimally! Multiply by Time.deltaTime or just Time? The goal is to rotate objects around the axis of the object

timid saffron
#

it was around here but i may have seen it in 2d

rich adder
#

but also wtf is up with that mass

eternal falconBOT
timid saffron
rich adder
pseudo ermine
rich adder
#

the only log you shown

pseudo ermine
#

The score is displayed on the users screen however, on the second mine, it does not increase by the specified amount.

rich adder
#

about the log printing

orchid shoal
rich adder
#

!screenshots

eternal falconBOT
#

mad No

Be mindful, if someone requests your code as text, don't send a screenshot!

rich adder
#

20+ objects rotating shouldn't be an issue, if you're lagging its something else you must profile it

orchid shoal
rich adder
orchid shoal
#

Yea, thnx thinksmart

pseudo ermine
#

I seem to be having an issue with the score and the way it increases, I have tried most things I can think off.

Any ideas?

https://hatebin.com/vfkfdhqhrq

rare basin
#

perhaps describe the issue?

#

"the way it increases" doesn't tell us anything

pseudo ermine
#

Sure thing, so when a mine is defused the score displayed on the users screen is supposed to increase by 1, however on the 2nd mine it doesn't.

subtle hedge
#
    public Canvas parentCanvas;

    private void Start()
    {
        //Cursor.visible = false;
    }

    private void Update()
    {
        Vector2 movePos;
        RectTransformUtility.ScreenPointToLocalPointInRectangle(parentCanvas.transform as RectTransform, Input.mousePosition, parentCanvas.worldCamera, out movePos);
        Vector3 mousePos = parentCanvas.transform.TransformPoint(movePos);

        cursor.position = mousePos;
    }
```i'm trying to make a compiuter in 3D using a canvas as the desktop. I'm trying to limit the cursor's position that it will always stay in the canvas and never get out of it. How can i do that ?
languid spire
pseudo ermine
scarlet skiff
gaunt ice
#

the error have said you are trying to access a destroyed gameobject

#

so you know why

scarlet skiff
#

yea but its not really destroyed

#

unless a destroyed object still takes up space in a list?

pseudo ermine
scarlet skiff
languid spire
#

you probably need to Clear targets at the end of Delayed

gaunt ice
#

your list wont resize automatically

scarlet skiff
#

ah i see

pseudo ermine
languid spire
#

targets.Clear();

#

there are docs for a reason

languid spire
pseudo ermine
#

oh, xd

scarlet skiff
#

yup it works, thanks guys

pseudo ermine
#

when going from the main menu to main scene and playing it, the landmines do not want to go from active true to active false but when playing the scene without going from the menu, it works. Any ideas on why this is happening?

twin bison
#

Hi guys. Just question if I do this correctly:

I have an enemy that has a rigidbody and a Move script. That Move function will just take the norma vector multiplies it by speed and set the velocity of the rigidbody. Now I also want to turn rotate the enemy into the direction it's facing and I'm not sure if I'm doing it wrong / more complicated then it should be. Also should it be in Update for Fixed Update?
Here is the code:

void FixedUpdate()
    {
        Vector2 targetDir = Target.position - transform.position;
        transform.up = Target.position - transform.position;
        _movement.Move(targetDir.normalized, MoveSpeed);
    }

Just to make sure, this code works. The enemy is moving towards player and also turns correctly. I just want to know if this is 100 % correct since it smells a bit. My first intuition was to do like this : transform.LookAt(Target) but then my enemy completey disappears and I dont see him any more in scene or gameview 😄

#

Ok now I did some changes and it smells a bit less:

void FixedUpdate()
    {
        transform.up = Target.position - transform.position;
        _movement.Move(transform.up, MoveSpeed);
    }
verbal dome
#

I dont see anything about rotation here

#

Ah you are setting transform.up

#

The physics might not like that you are rotating it with transform. Could lead into oddities/missed collisions

#

You could get a look rotation with Quaternion.LookRotation + maybe FromToRotation, and then use that to rotate the rb with rb.MoveRotation

#

Usually it is cleaner to have the Z axis as your forward direction, though. Seems like yours is the Y/up direction

cosmic dagger
#

maybe it's 2D?

pseudo ermine
#

Hi, for some reason (which I am unable to figure out) the 1st landmine sets the 2nd landmine to false when it shouldn't.

The first landmine should set itself to false and the 2nd landmine should set itself to false.

I have attached both scripts that handle the landmines.

Any assistance/help would be appreciated.

minigame movement: https://hatebin.com/rvzasonowa
mine manager: https://hatebin.com/wzsjppzqof

polar acorn
languid spire
deep goblet
#

how do i make an instantiated prefab a child of another gameobject? im making a grid and i want to instantiate each tile it generates to be a child of a canvas i have.

languid spire
#

use the override of Instantiate that allows you to specify a perent

deep goblet
#

does that change the instantiated tile's position at all?

#

nope nevermind, got it, thanks!

#

also Im trying to make a dragging system for an object and for some reason the OnPointerDown event just isnt registering?
I have an OnPointerDown function and a debug.log in it but it doesnt work

{
  Debug.Log("OnPointerDown");
}```
I have imported the EventSystems and the class has the IPointerDownHandler
languid spire
#

is this a UI object?

deep goblet
#

no i have it on a square sprite

languid spire
#

add a PhysicsRaycaster to your camera

deep goblet
#

should i do the 2D raycaster

languid spire
#

tbh, I have no idea, I dont do 2D, but I would guess so

verbal dome
deep goblet
#

how do i change the color of a UI image in script? I added the UIElements package and i can make a variable for the image but theres no options for image.color

cosmic quail
#

what even is the UIElements package?

#

are you using the ui toolkit or default ui

deep goblet
#

idk i thought i saw it was the right one

#

default ui i think

cosmic quail
#

yea then you gotta import UnityEngine.UI and not the other one

deep goblet
#

that makes sense

languid spire
#

UIElements is UIToolkit

proud kite
#

where/how can I create 3d collision detection box?

#

I cant really find anywhere

#

so for example I will be able to detect with script if player is inside this box

verbal dome
rare basin
#

or Collider?

proud kite
#

but in scene?

rare basin
#

Collider component

cosmic quail
# proud kite but in scene?

make a gameobject and add a BoxCollider component to it and tick the Trigger box. and then add a script on it with "void OnTriggerEnter(Collider other)"

proud kite
#

I thought its separated object type

#

like triggers > box trigger

cosmic quail
rare basin
#

colliders are components

rare basin
deep goblet
#

whats the property for UI elements to show/hide them? For gameobjects its just setActive but i switched some things to UI and dont know how to recreate that

rare basin
proud kite
#

nothing more

rare basin
#

to mark is as trigger and to add the callback in code etc

proud kite
#

mark as trigger wasnt told

#

and that was neccesary

#

i think

rare basin
proud kite
#

sorry i thought its unity-talk my bad

deep goblet
proud kite
#

i know how to code didnt need that extra step

rare basin
#

you can access the gameObject normally

#

and call SetActive() on that

rare basin
deep goblet
#

i know but SetActive isnt working, does OnMouseEnter and OnMouseExit work on UI elements too? im not used to working with UI

proud kite
rare basin
#

and IPoniterExitHandler

cosmic quail
rare basin
cosmic quail
#

well i didnt tell him everything. the part where he detects the player inside the OnTriggerEnter method

rare basin
#

he just asked about how to add collider

frigid sequoia
#

I mean, if the question is a simple one and the answer is also simple, I think is way better way of learning to just straigh tell and not go with annoying riddles

#

Like a visit ask where are the snacks? And you hanlde them the house blueprint

cosmic quail
rare basin
cosmic quail
rare basin
timid saffron
#

my vehicle wont go forward but only upwards when pressed w key

#

Im trying to make it both go forward and upwards when pressed W

rare basin
#

that's not how it works

#

calculate the direction you want the vehicle to go after pressing W key

#

and translate into that direction

timid saffron
#

when not used with each other

#

i can do like i did when i first started this pathway position change and assign it to w

rare basin
#

as i said

timid saffron
#

but what are the chances it will work together with vector3.up since vector3.up and vector3. forward dont together

rare basin
#

calculate the direction you want to move

#

and move towards that direction

#

right now you override

#

your script is moving forward

#

and then it's moving up

#

overriding the forward movement

#

simple vector maths

#

calculate desired move direction, and translate into that direction

#

you can use Vector3.Cross function for example

timid saffron
#

maybe something like this?

#

so it wont override

#

letme check vectorcross

rare basin
#

well

#

you clearly have a error

#

underlined in red

timid saffron
#

yeah i know

#

i was just trying to show you the basic thing i was trying to do to fix the override

#

maybe you could help me how to write it correctly

rare basin
#

by doing this way you wont be able to move forward

pseudo ermine
rare basin
#

while already holding A/D

#

if any horizontal input will be detected, you wont be able to move forward

timid saffron
#

how does man fix it?

#

put if and else everyhwere?

rare basin
#

i still don't even know what are you trying to achieve

#

there is plenty of movement tutorials for unity online

timid saffron
#

I can move the vehicle to right and left

#

and forward and backwards

#

i got that part

#

now im just trying to modify it

rare basin
#

to achieve what

#

and what is the problem then

timid saffron
#

to be able to both move forward and up

#

when pressed w

rare basin
#

so as i said

#

calculate the direction

#

you want to go

#

and translate into that direction

verbal dome
rare basin
#

you cannot translate fowrard and in the next line translate up

#

it wont combine it

timid saffron
#

ill try and calculate the direction and if it wont fix it ill come back

rare basin
#

doesn't work like you think it does

timid saffron
#

@rare basin

#

🤔

polar acorn
timid saffron
#

it moves up i just need to attach it to input

wintry quarry
rare basin
#

what i told you to do

#

make it in only one transform.Translate

#

not in two

#

one for forward, second for up

verbal dome
rare basin
#

calculate the direction you want to move, and translate there

polar acorn
# verbal dome ;)

You know now that I think about it a whole bunch of programming lines end on a winking frowny face

verbal dome
#

Can't unsee

timid saffron
#

we are good 👍

#

the one not problem but thing is it moves up so fast so you cant actually comprehend it movingforward. it moves forward and up (I checked in inspector window)

#

even tho my UPSPEED is 0.1 and normal speed (for forward) is 4

polar acorn
timid saffron
#

it moves both up and forward

#

Im just a little surprised that even though upspeed is 1/1000 of normal speed their numbers are still relatively close

#

when increasing

ripe kayak
#

Hello, Guys i wonder if i can make the text mesh pro animations from canvas happens after specific period of seconds (3 seconds before the animation starts)

#

How

timid saffron
#

is there like clamp ?

polar acorn
timid saffron
#

that I can set upspeed to a max value

rare basin
#

google exists

#

you can check if there is "like clamp"

timid saffron
#

bro you dont have to answer like that if you dont wanna answer just dont

soft wren
rare basin
polar acorn
ripe kayak
polar acorn
#

Literally just open a new tab and type "unity clamp"

rare basin
#

you could google "how to clamp values in unity" within the same time you was writing the question here

#

and get answer probably much quicker

summer stump
rare basin
#

"Use provided resources and advice before requiring others teach you how things work."

ripe kayak
polar acorn
ripe kayak
#

Oh ok

soft wren
#
void function()
{
  // Do textmeshpro stuff

  // ^^^^

  Invoke("animations", 3.0f);
}

void animations()
{
  // Do animation stuff

  // ^^^^^
}```
#

@ripe kayak ^

ripe kayak
#

Imma give it a try

#

Btw

#

"Animations"

#

Should i change it?

#

Like the name

soft wren
#

you can name the functions whatever you want

#

i just did that as an example

ripe kayak
late bobcat
#

Hey there guys, i'm having troubles with animating enemies when they take damage. I'm getting "Animator is not playing an animator controller".
I'm spawning enemies prefab from a pool of object and while in play mode if i click on one of the spawned enemy i can see they've a controller attached to them.
I'm getting the warning when i start the game and when the weapon collides with them.
https://hatebin.com/fqchhzvvzo this is one of the weapon codes i'm using that should trigger the enemyPrefab.animator.
https://gyazo.com/84626b0478dd61da2ea3751637f8837f Screenshot of one of the enemyprefab spawned from the pool.
https://gyazo.com/72fa6cfffa8e01634f791801f9df2a1a Screenshot of the game animator

polar acorn
late bobcat
#

do i just need to animate the base enemy object?

polar acorn
#

A prefab doesn't exist, what are you expecting to happen animating something that isn't actually there

late bobcat
#

like to set the animator to the base enemy object

polar acorn
#

It's just a blueprint for copying into the scene

polar acorn
#

why?

late bobcat
#

i just want the prefab to animate when it takes damage lol

#

but what am i asking is, should i just animate the enemy base object instead?

rare basin
#

you are missing concepts

#

of prefab and a instance

languid spire
#

did you not understand? Prefabs do not exist in the Scene

rare basin
#

do you know what a prefab is?

late bobcat
#

a copy of a gameobject?

rare basin
#

prefab is a recipe kinda

#

to create instances

#

prefabs doesn't exists in the scene

#

you can create instanecs of that prefab

late bobcat
#

prefabs gets created when the game starts no?

languid spire
#

no

rare basin
#

what

#

prefabs don't get created at all

#

you create them

#

manually

late bobcat
#

so instances of the prefab gets created?

#

when the game starts?

polar acorn
wintry quarry
rare basin
#

if you create them, then yes

polar acorn
#

A prefab is a file

late bobcat
#

ye

polar acorn
#

it doesn't exist

late bobcat
#

i see

polar acorn
#

There is no visible "prefab" in the scene

rare basin
#

prefab is like a apple pie recipe

#

and with that recipe you can create an actual apple pie

late bobcat
#

apple pie is an instance of the prefab?

#

i guess

rare basin
#

yes

late bobcat
#

good

timid saffron
# rare basin i won't spoon feed you, sorry

its great no problem. i like that you dont give directly codes but make ppl think its for our own good but sometimes googling stuff can be hard for total beginners to c#like me so its sometimes more comfrotable for me to ask here to how I could implement it to the code Im writing at that moment

#

i mean look at this full of stuff i dont know

rare basin
#

you have comments

#

for each line

late bobcat
#

okay then if prefab is just the recipe

rare basin
#

and a big text above the code

late bobcat
#

should i give an animator controller to it?

#

so that every instance has the animator

rare basin
#

yes you should

#

but modify the actuall instance's animator

late bobcat
#

mm i see

rare basin
#

like you have 100 objects with animator on the scene

late bobcat
#

ye

polar acorn
rare basin
#

and you want to animate specific object

#

then you animate only on THAT specific object

#

not all the 100 objects

late bobcat
#

ofc

timid saffron
#

seems daunting at first sight

late bobcat
#

okay i understood thanks everyone

timid saffron
#

so sometimes i feel more comfortable asking here

soft wren
rare basin
timid saffron
late bobcat
#

@soft wren yeye i'm doing that already, just having problem with animations

rare basin
#

that's not related to how to use the Clamp

timid saffron
#

but no problem sorry. Ill at least try to spend some minutes on these documentations before asking again

timid saffron
polar acorn
rare basin
#

that GUI is GUI related

#

and Clamp() is a different function

#

and you have use cases in the code

polar acorn
#

gui.whatever is for making UIs in code. If you took that whole script it'd come with sliders and whatnot

#

You'll notice, for example, that all of those function names are hyperlinks

#

you can click them

buoyant knot
polar acorn
timid saffron
# polar acorn you can click them

okay yeah i realized that I just don't want our relationship to be strained because I like these help channels on unity 🙂 thats why i made these comments

buoyant knot
polar acorn
buoyant knot
#

Math is a static class in C# System which contains static methods for math, especially with ints

brave compass
wintry quarry
brave compass
#

I like that the color in my IDE matches other struct types with similar methods, though.

#

The class color makes me thing of garbage

polar acorn
#

This is why we can't have nice things

brave compass
#

Just give me static struct 😤

buoyant knot
#

then everyone doing dumb shit can just do better

green copper
#

You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all
UnityEngine.MonoBehaviour:.ctor ()

I'm trying to save an array of inventory objects to a file for an app, and I get this error when I try to load the array I created. It's an array of inventoryItem, which are scribtable objects with an image (sprite) component and a script attached. I'm using the Save Game Free asset

polar acorn
green copper
#

I'm not using new, the save game tool is, I think? Is there another way to save objects other than saving an array containing them?

#

this is my test code for saving and loading the data

languid spire
green copper
#

what is a POCO

languid spire
#

Plain old C# object

polar acorn
#

An object that doesn't inherit or extend anything

green copper
#

the highlighted line in this function from Save Game Free

polar acorn
# green copper

Yeah it looks like this asset is not designed to work with the kind of data you are passing it. See if that asset has a support channel or forum

green copper
#

Can you make any reccomendations for saving an array of scriptable objects? Save data tools are expensive

honest haven
#

https://gdl.space/enenulekef.cs having a bit of a issue here. Im trying to get the npc to attack if the distance is less then 2. but the issue is he only attacks once. then goes into running state. i dont understand becuase im never over 2 distance.

languid spire
green copper
honest haven
#

that is just a trigger collider for a dialogue system. not the attack from the npc

pastel patrol
#

My rigidbody (circle) can't move close to walls. They collide to early. Help?

late bobcat
pastel patrol
#

it's exactly the same as the character

late bobcat
#

what about wall collider?

pastel patrol
timid saffron
#

what is a good way to combine rotations

#

like i did in translate

#

with +

#

what replaces + for rotations?

late bobcat
#

are you setting the collision offset in the inspector? @pastel patrol

#

and why do you have a collision offset

pastel patrol
#

I followed a guide for movement

pastel patrol
regal isle
#

Yo can anyone help me find some bug? Unity (version 2023.2.8f1) says I have some bug here.
I am new at this so yeah, I don't know much about it. Also it doesn't show up in functions when I want to give it to some buttons.
(Please ignore the background)

timid saffron
#

medic 🥵

eternal falconBOT
polar acorn
timid saffron
#

yeah he calls for medic

#

🙂

regal isle
languid spire
regal isle
#

And it was here.

languid spire
#

video is wrong or you copied it wrong

polar acorn
languid spire
#

try reading the docs instead

regal isle
#

Thx, that could be way useful tbh.

languid spire
#

should be the FIRST thing you do

polar acorn
polar acorn
regal isle
#

Well it works now anyway, I just deleted whole string and did it like this.

languid spire
wintry quarry
gloomy vector
#

me when I refuse to use basic tools afforded to me by modern technology for no reason

polar acorn
languid spire
polar acorn
languid spire
#

indeed, to their own detriment

deep quarry
#
RocketController controller = rocket.GetComponent<RocketController>();

Is this the correct way of making a reference to a script in another script?

#

or shall I just use public RocketController controller and drag the Script from the inspector?

languid spire
#

what is rocket?

ivory bobcat
deep quarry
languid spire
#

is it in the same heirarchy as this script?

deep quarry
#

Yea

ivory bobcat
#

Unless it's being referred to as a different component type that's necessary and you're not wanting to cache the specific component reference for some reason (not used enough, etc)

languid spire
#

then direct reference via Inspector

deep quarry
#

I only need to get the value of a variable though. Is it really necessary to direct reference via inspector then?

languid spire
#

less overhead, minimal but less

timid saffron
deep quarry
#

alright. Thanks @languid spire and @ivory bobcat! :)

ivory bobcat
swift crag
#

I've gotten footgunned by GetComponentInChildren before.

#

I added more components to the object and, surprise surprise, I suddenly started getting the wrong thing

languid spire
#

Apart from runtime generated components there really is no need to use GetComponent

#

and even then it's suspect

swift crag
#

I use it sparingly nowadays.

languid spire
#

It's all about design, lots of GetComponent or, God forbid, Find, screams bad or no design

buoyant knot
#

GetComponent is great. It just gets your references, which makes setting things up easier.

polar acorn
buoyant knot
#

GetComponent isn’t slow, as some people claim. It’s only slightly slower than accessing a Dictionary to get a component at runtime.

deep quarry
#

But if I use public RocketController controller to make a reference for another script. What do I put in the field? I can't drag the script there?...

languid spire
#

why not, you alread said it's in the same heirarchy

#

drag the rocket gameobject into it

deep quarry
#

I thought you could drag only the script

languid spire
#

no, you drag the instance of the script which, in this case, is on the rocket game object

deep quarry
#

Ah, I see

ivory bobcat
#

This is the coding channel. Try asking in #💻┃unity-talk
|| An LTS version would be the accepted stable version. ||

covert glade
#

oki

green copper
#

how can I convert the GameObject[] returned by findObjectsWithTag to an inventoryItem[]? I know for a fact only inventory items will be added to this array and/or tagged

wintry quarry
#

well ok - maybe i'm being pedantic. There's always cs InventoryItem[] inventoryItems = myGameObjectArray.Select(g => g.GetComponent<InventoryItem>()).ToArray();

green copper
deep quarry
#

How does new Vector3(transform.forward * vertical + transform.right * horizontal) not take 3 arguments? transform.forward and transform.right are both Vector3s, in which when added together should form a new Vector3?

swift crag
#

there is no constructor for Vector3 that takes a single Vector3

#

just use the result of the addition directly! there's no need to try and construct a new Vector3

#
Vector3 vec1 = Vector3.one;
Vector3 vec2 = new Vector3(vec1);

you're trying to do this

green copper
#

forEach loops don't have a page on the documentation that I can find, how do I access the iterator for it?

deep quarry
deep quarry
#

alright. Thanks!

swift crag
#

passing a Vector3 doesn't count as "three arguments" -- it's a single argument!

#

I guess you could do something like this if you wanted to

Vector3 vec1 = Vector3.one;
Vector3 vec2 = new Vector3(vec1.x, vec1.y, vec1.z);
#

but it'd be pointless

#
Vector3 vec1 = Vector3.one;
Vector3 vec2 = vec1;

It'd be the same outcome as doing this.

#

Vector3 is a struct, so you don't have a reference to an object -- you directly have the value

swift crag
deep quarry
#

I declare the dir variable in the MyInput() function. Is it possible to use it in Movement()?

#

cuz I get red line when I write dir

carmine elm
#

How can i make when a button is selected something happens .

green island
#

how do Actions work i tried this but it didnt work:

GameManager.Instance.GameStart += PlayerSetupServerRpc;```
```cs
public static event Action GameStart;```
the instance is just this script where the action is
short hazel
green island
short hazel
#

Make sure this method is being executed at some point

#

Log something in it

green island
honest haven
#
            float angle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg;
            Quaternion rotation = Quaternion.Euler(0, angle, 0);
            _rigidbody.rotation = rotation;
            Vector3 newPosition = transform.position + direction * moveSpeed * Time.deltaTime;
            _rigidbody.MovePosition(newPosition);``` move speed is really slow. am i doing somthing wrong here. i can increase the speed but my player speed is only 5 and this is much slower
lost forge
#

hello guys, i've got small problem, i donwnloaded animation from mixamo, and problem is that when anim is played avatar's position is changed, i want to play anim in a way that avatar's position stays the same, i turned off Root Motion, but still same...

grave frigate
#

I also have a quick question, why do I knock this cube into the floor. I am using a character controller and the cube has rigidbody physics.

rapid wing
#

Hi all, I'm using a CM VirtualCam with a script that applies a custom bounding / confiner box that I've setup using a 2D polygon collider trigger. Almost everything is functioning as I'd like however in play mode, when taking the camera to the bounds of the scene, the camera stops where it should but the transform values on the CM VirtualCam object continue changing in the editor while inputs are pressed. This leads to the camera appearing to "stick" to the bounds as when trying to move the camera to a new position it requires the transform values to catch up before releasing the camera to freely move within the bounds again. Any idea(s) what might be causing this issue?

true gyro
#

is there a logic error in my script? i feel like there is something wrong with my jumpBuffer logic. even if theres no obvious bug i can see in game.

deep quarry
#

How do I get the size of a Mesh Collider?

#

(via script)

rich adder
#

the meshcollider has no "size"

#

its as big as the mesh

deep quarry
# rich adder bounds

Tried it, but it didn't quite work for me.
(GetComponent<MeshCollider>().sharedMesh.bounds.size.y) > 1f

RocketController.cs(42, 33): Parentheses can be removed
RocketController.cs(42, 87): Parentheses can be removed
Cannot implicitly convert type 'bool' to 'float'

Nvm I made it work ✅

crystal venture
#

guys, in my project when the cube falls from the platform it falls very slowly even if all rigidbody settings are ok, why?

rich adder
#

also are you using with .velocity

crystal venture
rich adder
#

anyway if you're using .velocity the gravity is overwritten

crystal venture
rich adder
lunar haven
#

Hey all, don't mean to interrupt any discussion.

I have what I think should be fairly simple, but I am missing something..
I am trying to set the sprite of a gameobject, but it is not working.

Here is the code:

public static class TileFactory
{
    public static GameObject GenerateTile(TileType type)
    {
        GameObject tile = new GameObject(type.ToString()); // Init gameobject tile

        SpriteRenderer spriteRenderer = tile.AddComponent<SpriteRenderer>(); // Add sprite renderer component

        Sprite sprite = Resources.Load<Sprite>($"Assets/Resources/Sprites/Tiles/Sprite-Tile_{type}.png"); // change sprite based off of tile type
        //Debug.Log(sprite);

        spriteRenderer.sprite = sprite;

        return tile;
    }
}

Then just for testing, in the Start function I am creating a default tile using the following code:

    void Start()
    {
        GameObject defaultTile = TileFactory.GenerateTile(TileType.Grass);
    }

When pressing play, it will create a GameObject called Grass, as I am intending it to. But, I look at the object and the SpriteRenderer does not have the Grass sprite selected, it just says "none". Debug.Log tells me the sprite is null.

I think it might be with how i am calling the directory, but not sure. The one in the Resources.Load method is copy/pasted from the actual asset itself so not sure what else I can change it to. Unfortunately google / chatGPT has not been much of a help. What am I missing?

rich adder
languid spire
rich adder
#

true

lunar haven
# rich adder not working because you did not read the Resources docs

Jesus christ, so hostile for what? I did read the manual. I am trying to load the asset from the path. I thought this was a beginner channel? I tried implementing it as stated in the manual, and even asked chat gpt for supplementary help with the method but I cant get it to work.

#

Nevermind then lol.

swift crag
#

navarone was not being hostile

rich adder
#

idk how telling you to look at docs is hostile lol

#

also avoid GPT spambot, its as useful as watching paint dry

swift crag
#

you need to read the entire page, not just glance at a single line

#

the Resources.Load documentation is very explicit about the rules

rich adder
#

hint : Your path is messed up

swift crag
#

it breaks two rules, yes

supple sedge
#

hey can someone help me please. this is my first time coding. i trying to add camera controls so i can look around when walking around. i have the script which im 99% is fine, but when i test it i cant look around

languid spire
#

post your !code

eternal falconBOT
supple sedge
#

so do i just paste the link?

languid spire
#

yes

supple sedge
rich adder
#

and is the sript on a gameobjec btw

#

did you check console window for errors

supple sedge
#

theres no errors in the script, yes its on a game object, the camera

rich adder
#

many people dont have IDE configured so they dont see error until unity compiles, not saying thats the case here just something to keep in mind

supple sedge
#

wait, sorry. i just checked and i forgot i added a new camera, i put the script on the wrong camera when i made a new one, sorry for wasting your time everyone im an idiot lol

#

could have sworn i put it on the right camera haha i even checked but i guess i still didnt notice haha, so sorry lol

#

🙈

rich adder
supple sedge
#

what do you mean?

rich adder
#

like if you made a field for Camera camera for example, no matter where you put script as long as the field is filled you are rotating the camera
camera.transform.eulerAngles = new Vector3(pitch, yaw, 0f);

#

there is no guesswork

languid spire
supple sedge
vague dirge
#

Hello, I have a code with camera.euleurAngles.y, but I want to generalize it to a given vector (and not the y axis). How can I get the rotation between a transform and a given vector ?

wintry quarry
vague dirge
#

yes

wintry quarry
#

What exactly are you trying to accomplish?

#

Euler angles is almost definitely not the right approach

vague dirge
#

Get the angle between a transform and a vector. I don't know if it makes much sense, but here the code return the camera angles from the Y axis, but I'd like to achieve this but for "any" axis, so a vector that is not (0f, 1f, 0f)

#

(But maybe I didn't understand the whole method)

wintry quarry
#

it's not a think you can compare with a single vector

#

you need to be more specific

polar acorn
#

Like "I want to look at this thing"

wintry quarry
#

If you want the angle between transform.forward and an arbitrary vector for examplke, that would make more sense

polar acorn
#

or "I want to calculate the heading of an airplane"

#

or something like that

wintry quarry
#

but you aslso don't seem to want the angle between two vectors you want the angle around a certain vector

polar acorn
#

Context would help

wintry quarry
#

But yeah Digi is right - what are you actually trying to do? Not the solution you're attempting, but the actual gameplay goal

polar acorn
#

Chances are there's an easier way to do whatever

wintry quarry
#

Maybe draw a picture

#

or show a screenshot

#

if that helps

vague dirge
#

The thing is I have a character controller that is set up to move but not rotate with the ground. Like it always rotates from y axis when turning. So I used a raycast and hit.normal to make it snap to the ground, but the thing is it broke a little my moving code. I'm tweaking things here and there because a lot was depending to the Y axis, and I'm replacing it by hit.normal

#

Currently I have that :

wintry quarry
#
Vector3 projectedDirection = Vector3.Project(myMovementDirection, surfaceNormal);```
vague dirge
# vague dirge Currently I have that :
        {
            float targetAngle = Mathf.Atan2(direction.x, direction.z)*Mathf.Rad2Deg + cam.eulerAngles.y;
            float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle,ref turnsmooth, turntime);
            transform.rotation = Quaternion.Euler(hit.normal*angle); 
            Vector3 moveDir = Quaternion.Euler(hit.normal*targetAngle)*Vector3.forward;
            player.Move(moveDir.normalized*(speed + alt + varjump)*incline*Time.deltaTime);
        }```
wintry quarry
#

yeah don't use Euler here...

vague dirge
#

Or that's what the method does

wintry quarry
#

it gives you the part of the vector that is perpendicular to the normal (on the surface of the plane)

#

you can then normalize that direction and do whatever else you want with it.

vague dirge
#

Ok, because I projected my moveDir but now my character doesnt move, I think I might project it earlier and normalizing it as your advicing me thanks

wintry quarry
#

well you'd have to show the full code

vague dirge
#

I think it's all in the snipped I sent, but I don't understand why when I project moveDir along my ````hit.normal```, my character (on straight ground) doesn't move. Like right after it's normalized, and it should be the exact same vector because the normal is vertical

wintry quarry
#

because the new code should be very different from the old code

#

like 80% of those lines of code should have gone away

vague dirge
#

oh

#
        {
            float targetAngle = Mathf.Atan2(direction.x, direction.z)*Mathf.Rad2Deg + cam.eulerAngles.y;
            float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle,ref turnsmooth, turntime);
            transform.rotation = Quaternion.Euler(0f, angle, 0f); 
            Vector3 moveDir = Quaternion.Euler(0f, targetAngle, 0f)*Vector3.forward;
            moveDir = Vector3.Project(moveDir, hit.normal);
            player.Move(moveDir.normalized*(speed + alt + varjump)*incline*Time.deltaTime);
        }```
#

I just added the projection

#

Shouldn't it do the trick ?

wintry quarry
#

no

#

all that euler stuff needs to go byebye

twin bison
#

Basic C# question. I have an abstract weapon class. I want a property MaxUpgradeTier that I dont want to set in the base class but in all classes that inherit from it. VS makes this suggestion after i declared the property like this:
public abstract int MaxUpgradeTier { get; set; }

This is what VS gives me:

public override int MaxUpgradeTier { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); }

How to now define a value like 10 ?

wintry quarry
#
Vector3 projectedDirection = Vector3.Project(direction, hit.normal);
Vector3 moveDir = projectedDirection.normalized *(speed + alt + varjump)*incline*Time.deltaTime;
player.Move(moveDir);``` something like this
vague dirge
#

But I need it to make my character turn along the direction with the Euler no ?

wintry quarry
#

Are you sure you want a setter?

swift crag
#

replace the throw with something else

#

get => 10, for example

twin bison
swift crag
#

you also probably don't want a set accessor, yes

wintry quarry
#

If you JUST want a getter then change the abstract to this:

public abstract int MaxUpgradeTier { get; }```
Then in the child:
```cs
public override int MaxUpgradeTier => 10;```
twin bison
#

ok yeah now it makes totally sense thx

#

what do you think about this desgin in my base class
public abstract void OnWeaponUpgrade();
And then I have this:

public void UpgradeWeapon()
    {
        upgradeTier++;
        OnWeaponUpgrade();
    }

Is this something to work with or how would you do that or is "normally" done

wintry quarry
twin bison
#

My thinking is with this design, each different weapon can have its own thing happen when it upgrades itself

wintry quarry
#

I think it's a good idea - just make the abstract method protected so you don't accidentally call it elsewhere

twin bison
wintry quarry
#

Because you always want to be calling UpgradeWeapon() right?

frigid sequoia
#

I actually never understood the part of programming that compels you to use private, protected and all that stuff; like, if you don't really care about security and are working solo and you know what your classes and methods do, you can practically call everything public

wintry quarry
#

to make everything clearer and cleaner

#

When you write myWeapon.Up instead of one useless function and one useful function popping up in autocorrect ONLY the useful one does

#

this reduces cognitive load

#

reduces mistakes

#

makes your code better

polar acorn
frigid sequoia
# wintry quarry makes your code better

Makes it cleaner, yeah, but also is the other side of having to be constantly reorganazing stuff cause you need access to stuff later and you don't have access over it

wintry quarry
#

In general there's not really a "constant" reorganization. You think more up front about what an object's external facing interface should be before you start

opaque mortar
#

hi i am waching the move ment vid and now when i move my cam moves with the wasd no the moues

wintry quarry
opaque mortar
#

he he sorry

rich adder
#

and send tutorial

opaque mortar
#

can i send links

rich adder
opaque mortar
#

play look script using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerLook : MonoBehaviour
{
public Camera cam;
private float xRotation = 0f;

public float xSensitivity = 30f;
public float ySensitivity = 30f;

// Start is called before the first frame update
public void ProcessLook(Vector2 input)
{
    float mouseX = input.x;
    float mouseY = input.y;
    xRotation -= (mouseY * Time.deltaTime) * ySensitivity;
    xRotation = Mathf.Clamp(xRotation, -80f, 80f);
    cam.transform.localRotation = Quaternion.Euler(xRotation, 0, 0);
    transform.Rotate(Vector3.up * (mouseX * Time.deltaTime) * xSensitivity);
}

}

#

player motor using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMotor : MonoBehaviour
{
private CharacterController controller;
private Vector3 playerVelocity;
private bool isGrounded;
public float speed = 5f;
public float gravity = -9.8f;
public float jumpHeight = 3f;
// Start is called before the first frame update
void Start()
{
controller = GetComponent<CharacterController>();

}

// Update is called once per frame
void Update()
{
    isGrounded = controller.isGrounded;
}

public void ProcessMove(Vector2 input)
{
    Vector3 moveDirection = Vector3.zero;
    moveDirection.x = input.x;
    moveDirection.z = input.y;
    controller.Move(transform.TransformDirection(moveDirection) * speed * Time.deltaTime);
    playerVelocity.y += gravity * Time.deltaTime;
    if (isGrounded && playerVelocity.y < 0)
        playerVelocity.y = -2f;
    controller.Move(playerVelocity * Time.deltaTime);
    Debug.Log(playerVelocity.y);
}

public void Jump()
{
    if (isGrounded)
    {
        playerVelocity.y = Mathf.Sqrt(jumpHeight * -3.0f * gravity);
    }
}

}

rich adder
#

also !code

eternal falconBOT
rich adder
#

use links

valid pulsar
#

was trying to add some custom inspector things to a script so its easier to use and i found this (https://discussions.unity.com/t/custom-inspector-if-bool-is-true-then-show-variable/178698) to help me. I was using the code posseted by ElijahShadbolt in it and it works properly in the inspector but whatever i set with it is reset to the default value when I run the game.

opaque mortar
valid pulsar
deep goblet
#

im using some UI elements for tiles and a test object for a grid placing system, and i know the layer order is based of the heiarchy, but the tiles for the grid are generated from a prefab, is there a way i can change that sorting order so the test object is always the most visible?

rich adder
wintry quarry
polar acorn
rich adder
deep goblet
open apex
#

I am making a 2d game (flappy bird) this is the code, 2 question.
Does it matter if it's vector3 for any specific reason when it moves to the left? Also when the object of the script is moving to the left, it only moves to a certain point, I have not givven it a stopping point. Is there any reason why it's stop at a certain distances?

#

this is the code I will use the green tubes to move

rich adder
#

look.ProcessLook(onFoot.Movement.ReadValue<Vector2>());

open apex
#

I am just making some testing, this is not the final result

opaque mortar
rich adder
opaque mortar
#

oh

rich adder
#

Look at the names

#

You're passing in Movement inside Look

#

ofc your WASD will move camera

open apex
languid spire
open apex
open apex
languid spire
rich adder
deep goblet
rich adder
#

at the same spot

#

right now its stuck at 1,0

wintry quarry
rich adder
#

maybe follow a tutorial instead of guess work @open apex

open apex
deep goblet
#

i just saw that canvas' have a sorting layer of their own, i havent used 2D elements too much so im just blind ig

opaque mortar
open apex
#

😁

rich adder
#

because you assigned it x1,y0

#

every frame

#

its not incrementing

wintry quarry
open apex
#

thanks for the answer

deep goblet
rich adder
open apex
#

that makes sense

#

😁😁

rich adder
#

yes, I still wouldn't move a gameplay object with transforms, but for learning its ok

#

btw unity also has a built in method transform.Translate

open apex
#

I would 😁 😁 😁

rich adder
open apex
#

no worries

#

all fixed

rich adder
#

lol sure

frigid sequoia
#

Does anyone knows how the component rotation constraint works? Cause I read the documentation, watched a video and I still don't get it

wintry quarry
open apex
grave forge
#

also guys how do i make the ground collide with the user
in a 2d game
i just added an collider for both but it didnt work

open apex
#

it would move it according to the amount of fps

rich adder
wintry quarry
open apex
rich adder
#

Time.deltaTime just allows everything to be consistent through diff FPS

frigid sequoia
#

But I just want to "clamp" its rotation, this cannot do that?

deep goblet
#

what do i use to share code again? cant find it anywhere

wintry quarry
eternal falconBOT
frigid sequoia
#

Cause it does in blender, that's why I am confused

rich adder
deep goblet
#

thanks

stuck mango
#

How can i roll the camera depending on the speed of rotation on y axis? I have been trying for 2 hours and still nothing works, my head gonna explode

wintry quarry
open apex
#

I will just finish it

#

it doesn't hurt nobody

#

😎

wintry quarry
rich adder
#

and waste time

grave forge
#

man nobody is helping me i guess its time to hop on chat gpt

open apex
rich adder
frigid sequoia
rare basin
#

chat gpt best tool

polar acorn
wintry quarry
grave forge
deep goblet
#

it should just be moving the objects transform by eventData.delta then dividing it by the canvas scale factor (if i decide to add one), but it goes wayyyy too fast

rich adder
rich adder
#

how is one supposed to know whats wrong without seeing context..

stuck mango
#

You get what i mean?

grave forge
ivory bobcat
wintry quarry
#

Racing?

#

FPS?

stuck mango
#

FPS, i want to have a very dynamic effect

#

I am trying on making fast paced fps retro-styled game

grave forge
deep goblet
stuck mango
#

but the tilt depends on rotating speed

rare basin
ivory bobcat
grave forge
#

i got ignored

wintry quarry
rich adder
polar acorn
stuck mango
rich adder
#

helppppp plzz omg help in such a rush
its brokee help pluzz why everyone ignoreeeme

grave forge
deep goblet
# grave forge i got ignored

theres a lot of people in discord its not really anyones fault if people are busy or accidentally scroll past the message, you can always bump your original question but i dont think guilt tripping that nobody is listening to you

rich adder
#

provides no context or screenshots

polar acorn
wintry quarry
grave forge
polar acorn
wintry quarry
#

why not

#

think about it

#

very simple math

#

literally mouse delta / time

polar acorn
deep goblet
#

he added gravity

#

and jumping

rich adder
polar acorn
#

and who am I to believe otherwise

#

I can't see their screen so all I can go off of is the information provided

deep goblet
stuck mango
polar acorn
deep goblet
#

ahh mb gotcha

#

but we need to know what colliders and stuff you have on the player and ground, if we cant see the stuff relating to the problem then we cant help.

rich adder
#

now they're not in a rush anymore

grave forge
polar acorn
#

How does something jump while remaining stationary?

deep goblet
grave forge
polar acorn
#

Physicists baffled at this conundrum

deep goblet
#

we cant help if you wont show us what youre working with

polar acorn
deep goblet
grave forge
deep goblet
#

are they normal or the 2D colliders

scarlet skiff
#

how am i getting an error if im not even running the game... 😭

grave forge
rich adder
grave forge
grave forge
rich adder
#

show the full stack trace

grave forge
scarlet skiff
#

and whats a full stack trace

deep goblet
polar acorn
rich adder
scarlet skiff
#

happened before in my project wothout a problem

rich adder
#

then you are probably destroying the referenced prefab asset, not the instance

polar acorn
scarlet skiff
#

i just did what i usually do

polar acorn
grave forge
polar acorn
#

You can't call Destroy on a prefab

scarlet skiff
#

public game object, put sprite in there, initiate it, and the gameobjkect has a script that destroys itself after an animation is played

polar acorn
rich adder
grave forge
rich adder
#

should just follow a course !learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

polar acorn
rich adder
#

seems your guessing ur way through this

deep goblet
#

theres a rigidbody 2d

grave forge
rich adder
polar acorn
#

not in this screenshot you didn't

deep goblet
#

oh crap i forgot that it doesnt count as a collider 💀 mb i might be stupid

grave forge
#

wdym where

polar acorn
#

You've sent a screenshot of the same object still with no collider

grave forge
#

ITS THERE

languid spire
#

no it's not

polar acorn
#

Let's take a look at the components on this object in order

#

Not a collider

#

Not a collider

#

Not a collider

#

Not a collider

deep goblet
#

oh no 😂

polar acorn
#

And that's it

grave forge
#

man im getting cooked

polar acorn
#

That's all of the components on this object

#

Notice how none of them are colliders

rich adder
#

what do you think?

grave forge
twin bison
#

Hi,
Is there a way to directly get the correct Component:
EnemyController enemy = Instantiate(_enemyPrefab, transform.position, Quaternion.identity).GetComponent<EnemyController>();
Like some unity trick, or is this "The Way"?

grave forge
#

i thought rigid body was an collider

polar acorn
rich adder
grave forge
twin bison
rich adder
#

rigidbody gets its shape from rigidbody ?

#

that makes 0 sense

rare basin
grave forge
#

i dunno

#

also why my sprites are 144p

rich adder
#

A Body that is Rigid

deep goblet
#

another question though, on the test object that drags, it drags but it either goes slower or faster than the mouse, and i wanna figure out why instead of just brute forcing some value

https://gdl.space/etumebusef.cpp

carmine sierra
#

I need to create a function which will follow a mouse cursor and stretch two sprites, how can I start

#

Vector3 mousePos = Input.mousePosition; is this a good start

rare basin
#

By creating a function that keeps track of your mouse position

carmine sierra
rare basin
#

What do you think

carmine sierra
#

yes

#

but it needs the name update to be called every frame right

#

so how could I rename it to a different function like trackmouse

rare basin
#

If you are asking such questions you should better watch some very basics c# tutorials

carmine sierra
#

in relation to unity?

#

or general tutorials

rare basin
#

C#

carmine sierra
#

okay i will thanks

deep goblet
rich adder
scarlet skiff
carmine sierra
#

so any functions i want to be used every frame i should insert there?

rich adder
carmine sierra
#

is onmousedrag() called every frame the mouse has a change in movement?

#

sorry i should just google some things

rich adder
#

check pins in this channel

carmine sierra
#

ngl though I don't have time for that just need to make a quick game in a month and a half for school

#

is update and start and onmousedrag called scripting API's?

languid spire
#

no

rich adder