#💻┃code-beginner

1 messages · Page 146 of 1

rich egret
#

no answer

wintry quarry
#

none of those are the log you just wrote

#

that means your raycast is not hitting at all

polar acorn
#

Is that all of the logs?

wintry quarry
#

or the code is not running at all

rich egret
polar acorn
#

Then we have definitely shown that your raycast is not hitting anything at all

#

Meaning there is no object within 1 unit of the front of shootingPoint with a collider

wintry quarry
#

raycast default distance is infinity

polar acorn
rich egret
polar acorn
#

DrawRay is the one where the distance is baked into the direction

wintry quarry
polar acorn
#

So, either CanShoot() is never true, or the raycast never hits anything because there's no colliders in front of shootingPoint

polar acorn
rich egret
polar acorn
#

so either you didn't save, something else is spawning them, or the balls are not the bullets and you've just given me a random non-sequitur

rich egret
polar acorn
#

so it doesn't matter what they collide with

rich egret
#

ok

polar acorn
#

Since the log is before the Instantiate line, if that line is running at all then the log is going to the console

#

If it's not, then you probably didn't save the script before starting the game

rich egret
#

I just need an idea to solve it

#

bro what

polar acorn
#

Does PlayerBody have the Enemy tag

rich egret
#

I could swear I saved it!

rich egret
#

ah no

polar acorn
rich egret
#

The only one who has an enemy tag is the "doll".

polar acorn
#

The ray didn't hit an enemy so it doesn't damage the enemy

rich egret
#

i know

#

so what to do?

#

And I forgot to say thank you, it goes without saying that you help me

polar acorn
#

Is the ray supposed to be hitting PlayerBody

rich egret
#

It's literally the player

summer stump
vernal minnow
#

Is it better to do damage in whole number increments or float decimal increments?

frosty hound
#

Whatever makes sense for your game

polar acorn
vernal minnow
#

Although I'm kinda thinking that having defense divide the damage doesn't make much sense

ionic topaz
vernal minnow
#

Its an arcade game so honestly it should probably be whole numbers and the defense should just directly subtract from the damage

#

Thanks 😂

#

So how do I convert integers to strings to show tye number in the text?

rich adder
ionic topaz
#

I believe you can do something like "Health: " + yourIntHere

vernal minnow
#

Is it the ${x:2}?

#

No... that doesn't look right

rich adder
#

You can use $ sure

vernal minnow
#

Something similar tho

rich adder
#

but how you wrote formatting is wrong :

summer stump
#

$""
You still need the quotation marks
You are doing "string interpolation" which you can google for more

vernal minnow
#

Alr, thanks

rich adder
#
string text = $" health : {healthVar}"```
ionic topaz
#

huh, never seen that before

rich adder
desert elm
#

what are quarterions

rich adder
#

rotations

wintry quarry
#

Just a variable that holds a rotation

summer stump
desert elm
#

oh okay-

#

wait how do they have
4 different axis?

wintry quarry
#

no

#

don't worry about it

#

it just holds a rotation with some fancy math

summer stump
vernal minnow
#

Stop, w was literally a question

wintry quarry
#

you don't ever need to look at or care about those 4 numbers

vernal minnow
#

Whys the server messing with me?

#

😂

wintry quarry
#

just think about the whole thing as an opaque box that holds a rotation

ionic topaz
desert elm
#

okay- uh
if I just want to have a 2Dgameobject turn to face a vector2
can I use quarterion.slerp?

wintry quarry
vernal minnow
wintry quarry
#

you can Slerp the direction vector

desert elm
rich adder
vernal minnow
#

So what rotation is w then?

#

Or is that 3d?

rich adder
#

all 4 numbers make a rotation

short hazel
#

It's not a rotation

#

The whole quaternion is the rotation

wintry quarry
# vernal minnow So what rotation is w then?

none of them are rotations around axes. Again, don't worry about the actual 4 numbers unless you want to spend 3 hours doing math lectures. Just think of the whole thing as a variable that represents a rotation, that's it.

short hazel
#

As long as you use the stuff in the Quaternion struct, and not interpret the XYZW as individual angles in degrees, you're fine

summer stump
#

Xyz represents a direction, w is the amount of twist around that direction

rich adder
#

^ Unity has Quaternion methods in it so you only need to work with Euler angles

vernal minnow
#

I'll pretend they don't exist till I need them ig lol

summer stump
ionic topaz
#

quaternion.euler and quaternion.identity are the simple ones you'll be using most likley

rich adder
vernal minnow
summer stump
swift crag
#

you just don't need to fiddle with their values

#

just like you don't fiddle with a Transform's 4x4 matrix

summer stump
desert elm
swift crag
#

I don't mess with the Matrix4x4. I mess with position, rotation, and scale.

wintry quarry
#

the red arrow in scene view

desert elm
#

oh okay-

#

direction is a vector 2 position?

vernal minnow
swift crag
#

A direction is a Vector3.

#

transform.right will be a Vector3 with a length of 1.

vernal minnow
#

stopped using it bc i didnt understand em

swift crag
#

Aeth was talking about trying to manipulate the underlying data that a Quaternion is made from.

#

Don't worry about that at all.

vernal minnow
#

Ah

swift crag
#

It's just a common error to mistake it for euler angles

summer stump
vernal minnow
#

What's an euler angle?

swift crag
#
transform.rotation.x; // not x rotation
transform.rotation.y; // not y rotation
transform.rotation.z; // not z rotation
transform.rotation.w; // ???
#

Euler angles are the X/Y/Z rotations you're more familiar with

#

It's what you see in the inspector

#

They produce a rotation by spinning around three different axes.

wintry quarry
vernal minnow
#

Uh... looks like I need to have a look at my inspector again...

#

Oh wait

swift crag
#

They have worse mathematical properties than quaternions, which is why Unity uses quaternions at all

polar acorn
vernal minnow
#

Those 🤦‍♂️

swift crag
#

(which is transform.localEulerAngles ! )

vernal minnow
swift crag
#

well, it gives you the local euler angles of the transform

#

the rotation you see in the inspector, as digi said

#

similar to transform.localPosition and transform.localScale

#

those are what the inspector shows you

wintry quarry
vernal minnow
#

Holy crap, so I can save that in a variable to reuse later?

swift crag
#

well, sure, if you needed that

polar acorn
wintry quarry
#

sure but you could also save the more effective thing which is the rotation or localRotation Quaternion

wintry quarry
desert elm
desert elm
#

even in 2d view?

polar acorn
#

yes

desert elm
#

okay, thanks

rich adder
swift crag
#

Yeah, it's a little annoying for 2D

#

you have to decide which direction is going to be your "2d forward"

desert elm
swift crag
#

-transform.up

desert elm
#

oh

swift crag
#

there is no transform.down, alas

polar acorn
swift crag
#

Unity 6 feature? 🥹

rich adder
#

they do it for Vector3 but got lazy with transform

north kiln
north kiln
#

!ide

eternal falconBOT
polar acorn
desert elm
#

oh no its the IDE

#

it autocompletes yes

polar acorn
rich adder
desert elm
#

well, it did previously

#

oh nevermind

north kiln
#

does it really autocomplete? If it's not underlining errors in red it needs to be configured

desert elm
#

just not autocompletting now I assume

#

its 3am anyway and I got other work to do

short hazel
#

Completion is context-aware
If you're typing stuff outside of a class, you won't get many suggestions

rich adder
short hazel
#

Normal if all of these are fields/properties

desert elm
short hazel
#

direction and directionNormalized should be local variables. They'll be light blue if that's the case

north kiln
short hazel
#

It's the default for VS

#

But a rare sight, since you use more methods and locals in methods

rich adder
short hazel
#

Then you modified it in the settings

north kiln
#

I watch a youtuber who has Rider set to the default VS color scheme and it makes me angry every time I see it lol

#

not being able to tell a value type from a reference type 😞
properties same color as local variables 😞

short hazel
#

Correctly naming things also helps in distinguishing what is what, but oh well this is Unity, can't have everything

rich adder
short hazel
lofty sequoia
#

Does Rider let you set a color for a file tab?

rich adder
north kiln
lofty sequoia
#

looks like vs2022 lets you do that finally

desert elm
#

is there a way to write "or" in if statements like
if ( bool == true "or" bool2 == false)
{

}

slender nymph
#

have you googled it

desert elm
#

nvm I have googled it

vernal minnow
#

Im having an issue with using a variable from another text, for some reason i can test integars but cant seem to use strings

#

wait...

#

its not in update... mb

#

ok im still having the issue and its now trying to create a tupple

#

void Update() { if (script.speed == 6) { Debug.Log("Speedboost active"); } healthtext = script.playerhealth; }

#

its properly checks the integer so im not sure why a string wouldnt work similarly

#

public string playerhealth = ($"{health}"); unless this is just formatted wrong?

slender nymph
#

that is 100% not formatted correctly

#

first of all, that would only create the string at the time the object is instantiated. so the value won't update. and then you also have the () around it which is likely what is causing your error

slender nymph
#

no, you can use string interpolation anywhere. but strings are immutable so this won't update with the health variable

#

but also why is that a string?

summer stump
vernal minnow
#

why is what a string?

slender nymph
#

why is playerhealth a string

vernal minnow
#

health is an integer, dont i need a string to input into a text?

slender nymph
#

well you could use string interpolation at the time you need to create the string. or you can call ToString on any object (including ints)

vernal minnow
#

tostring didnt work either

#

i tested it too

slender nymph
#

but it seriously seems like you have a tenuous (at best) grasp of c# and i would suggest going through some beginner c# courses to learn wtf you are doing

summer stump
# vernal minnow i tested it too

I mean, it WILL work if the syntax is right
You had parentheses around the string though, did you do the same with ToString() ?

vernal minnow
#

public string playerhealth = health.ToString();/*$"{health}";*/

summer stump
#

See, you're doing it in the initializer...

#

Why?

vernal minnow
#

im doing it in update

slender nymph
summer stump
polar acorn
vernal minnow
#

well before i can update it?

polar acorn
vernal minnow
#

so that i can use this textmesh thing

#

still learning how textmesh pro works but i assume it still needs a string

summer stump
polar acorn
vernal minnow
#

integers work in the texts?

rocky canyon
#

.ToString()

polar acorn
vernal minnow
polar acorn
summer stump
vernal minnow
#

well now its trying to say im converting a string to textmesh pro...

#

but thanks for the first fix

vernal minnow
#

yep, forgot .text

summer stump
#

You have to access the text property before setting

barren loom
#
using UnityEngine;

public class AlienMovement : MonoBehaviour
{
    [SerializeField]
    private float screenBorder = 30;

    public float moveSpeed = 1.0f;
    public Rigidbody2D rb;
    public float maxVariability = 4.0f;
    public float minVariability = -4.0f;

    private Camera camera1;

    private void Start()
    {
        camera1 = Camera.main;

        // Generate a random variability within the specified range
        float variability = Random.Range(minVariability, maxVariability);

        // Set the velocity based on variability
        rb.velocity = new Vector2(variability, 0) * moveSpeed;
    }
    private void FixedUpdate()
    {
        reverseVelocity();
    }

    /*
     * Checks if the Alien is near the border
     * Changes the direction to the opposite way if the Alien hits the border
     */
    private void reverseVelocity()
    {
        Vector2 screenPosition = camera1.WorldToScreenPoint(rb.position);
        if ((screenPosition.x < screenBorder) || (screenPosition.x > camera1.pixelWidth - screenBorder))
        {
            //Reverses the direction
            rb.velocity = new Vector2(-rb.velocity.x, 0);

        }
    }
}

I'm trying to reverse the velocity of the gameobject after it touches the border of the screen. However, the gameobject does reverse in the unity editor but stays at the border after being built.

slender nymph
#

you do know you have to actually describe what isn't working for anyone to know how to help you, right?

barren loom
#

oh mb

#

the alien just stops at the screen border

rocky canyon
#

i was going to just say Interesting.. :0

barren loom
#

instead of reversing

rocky canyon
#

may have something to do with ur hard coded screenBorder? edit: then again idk, maybe build a development build with debugs in ur methods

queen adder
#

hello

barren loom
rocky canyon
#

isnt there a screenwidth or something?

barren loom
#

Let me try that out rq

#

setting

#

screenBorder = Screen.Width just makes the gameobject stay in place

vernal minnow
#

up until last week, i didnt even know text mesh pro was a thing and tried to argue why i used legacy instead of trying it🙄

slender nymph
#

i wasn't even referring to unity stuff though. i was referring to the fundamentals of c# which includes things like accessing variables and methods from other objects, converting things to strings, and syntax

vernal minnow
#

didnt end well

rocky canyon
# barren loom screenBorder = Screen.Width just makes the gameobject stay in place

i may have mistaken what ur trying to do. i was just saying by using screewidth u can calculate when u reach each side something like this came to mind ```cs
void Update()
{
CheckScreenEdges();
}

void CheckScreenEdges()
{
    Vector2 screenPosition = mainCamera.WorldToScreenPoint(transform.position);

    if (screenPosition.x >= screenWidth)
    {
        rb.velocity = new Vector2(-moveSpeed, 0);
    }
    else if (screenPosition.x <= 0)
    {
        rb.velocity = new Vector2(moveSpeed, 0);
    }
}```
rocky canyon
barren loom
misty hedge
#

If I have a DialogueEvent that extends from the abstract class Event but has a field (string Line) that is not in Event, how I access this field from a List of type Event? I tried casting to DialogueEvent but that did not seem to work.

shell herald
#

idk if this is the right thing, but is it possible to have an "if" with 2 variables?
so

if(bool1 and bool2)
{

}

north kiln
#

one could google "C# and"

gaunt ice
#

Google logical operator

misty hedge
#

(it's &&)

plush chasm
misty hedge
#

No, I tried explicitly casting it to see if that'd let me access that field.

slender nymph
#

you're missing some parentheses to make it work

plush chasm
#

yeah you aren't useingthe casted variable

slender nymph
#

((DialogueLine)events[i]).sLine

plush chasm
#

((DialogueEvent)eventList[0])).Line

misty hedge
#

SIGH

#

Yep, that did in fact work.

#

Very silly oversight, thank you!

slender nymph
#

or instead of using that terrible sType variable, you can instead use the is operator to type test it and put it into a local variable all at the same time

plush chasm
#

I have had that problem many times

slender nymph
#

if(events[i] is DialogeLine dialogueLine)

misty hedge
#

oh! that's even better

late burrow
#

does transform worth referencing if i already have other component and can just .transform

slender nymph
#

not really. it's a micro optimization at best so just accessing the component reference's transform property is perfectly fine in nearly all cases

delicate slate
#

can anybody help me out

summer stump
delicate slate
#

i got this script from a tutorial but i dont know why im not jumping ill put the script in rn

#

how do import code?

summer stump
eternal falconBOT
summer stump
#

Use links if it's longer code

delicate slate
#

!code

eternal falconBOT
summer stump
delicate slate
#

im so confused sorry

#

thats it

summer stump
#

Hmm, the Move call is before you set the velocityY value for jump. Is that how it is in the tutorial?

delicate slate
#

idk i js copied it

#

ive never learned code

rich adder
delicate slate
#

yep

summer stump
# delicate slate do want the tutorial?

Nah, I don't have time to really look through it.
I would learn about Debug.Log() and place that in the UpdateMove method to check things like isGrounded and the values passed into Move

#

Might want to just pause and check out !learn though

delicate slate
#

huh

eternal falconBOT
#

:teacher: Unity Learn ↗

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

teal viper
delicate slate
#

ok

#

thank you for the advice

keen crescent
#

In my game, I'm using ScriptableObjects to create projectiles, which has worked well so far. (For example, each projectile accesses a scriptableobject to get its sprite, properties, etc.) But I want to be able to add a ParticleSystem component to them at runtime, but I don't see a way to store that using a ScriptableObject
Should I just be using prefabs or is there a way to make this work?

timber tide
#

you can store particle system assets onto the SO

#

wait maybe im thinking of vfx graph sec

keen crescent
#

I can technically generate a field for one, but there's no way to populate it with a stored asset since a ParticleSystem is a component that has to be attached to an object

timber tide
#

ah yeah it's connected to a GO as a component

#

so prefab is the idea

keen crescent
#

ah that sucks

delicate slate
#

so much

livid tundra
#

I have some steep stairs that I need my character to run down from the top instead of flying off the top like the General Lee

#

(The car from Dukes of Hazard, not the...you guys get it)

#

I need to make a system to constrain her on the way down while she is in the Move state

frosty hound
#

You need to apply force in the direction of the slope, rather than applying it directly forward

livid tundra
frosty hound
#

Sure

livid tundra
frosty hound
#

It's fine, just a future point

livid tundra
#

you are proposing (if I understand) that in the Move state, when I am slopeDetected(), I manually override the velocity vector?

frosty hound
#

That sounds messy in general

#

I would just add the force in the slope direction regardless of how steep it is. Even on flat ground, you're on a slope.

nimble apex
#

currently i need to reassign shader and reconfigure properties of a material, due to our project architecture and approach, we cannot pre-assign the material/shader to the gameobject , in order to get things done , i need surface type to set to trasparent

so, my question is, what are the shader keyword for "surface type"

#

somehow this is not working, surface type hasnt changed at all

livid tundra
#

Also, does one of the basic C# libraries have a constant sqrt(2) predefined?

frosty hound
#

Parallel to the surface of the ground below the player

livid tundra
#

I assume that by "Force" you mean "velocity"?

#

b.c. I don't know where I can apply a force on the rb

frosty hound
#

You can use AddForce on a rigidbody, or you can modify the velocity directly

buoyant knot
#

if you have a dynamic RB, I strongly recommend against directly modifying velocity until you have more experience

#

because directly modifying velocity quickly leads to spaghetti code when multiple scripts try to do the same thing

odd mason
#

im not sure what is wrong with the class anyone know?

livid tundra
#

I need to get the dot product of a raycast with a collider's normal, does anyone know how to get that?

north kiln
#

What are you struggling with? You just use the dot product on both of those variables, the hit has the normal, and the ray has the direction

odd mason
livid tundra
#

I just want to check if a raycast is hitting normal or not

gaunt ice
#

Normal is not a point

livid tundra
#

I want to turn something on or off depending on whether my slopeCheck raycast is intersecting normal to a surface or not

#

(in 2D)

north kiln
#

still not sure what the difficulty is, just get the dot product and compare it to whatever bias you want

livid tundra
gaunt ice
#

I think he doesnt know what normal is

livid tundra
north kiln
#

You just use the dot product on both of those variables, the hit has the normal, and the ray has the direction

#

What are you struggling with

livid tundra
#

🧐

livid tundra
gaunt ice
#

The normal in unity is exactly what you learn in uni

frosty hound
#

(Get the normal of the ground below the player, and use the cross product to get the slope)

gaunt ice
#

Raycast intersects with triangular mesh at point and normal tells you what is the direction of the triangle facing to

livid tundra
north kiln
#

Great, then what is confusing you? Because I've explained what two things you care to dot product, the exact same two things you mentioned right at the start

gaunt ice
#

Google raycast hit info and read the properties

livid tundra
#

ok, I'm going to do that

round scaffold
#

aw i love interact systems

livid tundra
#

Ok, I don't want to do a second raycast to get the normal when I am already doing that to get a bool

#

I want to keep the raycast2D I am already doing as is and access its normal

#

I know how to do that

#

but right now it is being casted as a bool per the tutorial

gaunt ice
#

Raycast has overloaded method to get back the hit info

livid tundra
#

how do I get the true/false info from a raycast2D?

#

because I need to revise my existing code to only access that part elsewhere

#

if I keep it as a Raycast

gaunt ice
#

Just google or your ide will tell you how the overload methods look like (signatures)

livid tundra
north kiln
gaunt ice
#

Your ide should show you
public return_type same_method()
public other_return_type same_method(int some_int)

livid tundra
#

ok I got it now

fresh trellis
#

i can't drag sound audio mp3 into the unity why?
public AudioSource doorSound;

livid tundra
#

the struct

north kiln
storm shore
#

https://paste.ofcode.org/35aY9ACXbyXSUuafN5x2FMM

This code is supposed to change a shader material values over time and it works for the mesh renderer component but i also want to use it on a skinned mesh renderer and don't know how to do it. Can someone tell me how you can do this.

north kiln
livid tundra
#
public static implicit operator bool(RaycastHit2D hit);
#

🤔

fresh trellis
gaunt ice
#

No, you should look at the method signatures of raycast

fresh trellis
#

i can't drag my sound door in my unity idk why

north kiln
gaunt ice
#

Forgot, mb

fresh trellis
#

hey. any help?

north kiln
#

I explained your issue.

#

An AudioSource is a component, are you looking for AudioClip?

livid tundra
#

:D

public override void Update()
{
    base.Update();

    player.SetVelocity(player.moveSpeed * xInput, rb.velocity.y);
    if (xInput != 0 && player.IsSlopeDetected() && player.IsSlopeDetected().normal != Vector2.up)
    {
        player.rb.velocity = new Vector2(xInput, xInput) * player.moveSpeed / Entity.SQRT_2;
    }
}
#

PERFECT!

#

All I had to do was let a Physics2D.Raycast() method in my IsSlopeDetected() method return the RaycastHit2D type (instead of bool ,which is what the tutorial had me do before). I didn't have to change anything I already wrote because it reads implicitly as a bool.
Then I just accessed the normal property.

#

I still have the rigid body set to isKinematic when in idle state on stairs so it doesn't slip

gaunt ice
#

You can store the hit info in some variable

livid tundra
#

I am calling it again

queen adder
#

Im new to unity, can anybody help me fix these errors?

livid tundra
#

I'll do that

north kiln
queen adder
timber tide
#

some if statements with a handful of prefabs

queen adder
#

Hi, Im new to Unity and I am creating a basic cookie clicker game for a school project. My cookie counter is set to 0 and words perfectly fine, but when I click the cookie it does not register the clicks, and the counter does not increase either when clicking. Any help? >:D Please

slender nymph
#

!code
but also what is calling OnCookieClicked

eternal falconBOT
queen adder
slender nymph
#

that does not answer the question i asked

queen adder
#

sorry english isnt my first language, what is your question?

slender nymph
#

what is calling your OnCookieClicked method

queen adder
slender nymph
#

wdym? you just answered that OnCookieClicked calls IncreaseCookie. so clearly you know what calling a method is, right? so what calls OnCookieClicked

round scaffold
slender nymph
queen adder
#

This code isnt ai generated

slender nymph
#

then what calls OnCookieClicked

queen adder
#

I have no idea

slender nymph
#

the answer is probably nothing which would be the root of your issue. but you seriously need to go learn the basics. there are beginner courses pinned in this channel to help you get started

charred spoke
#

A method that calls another method that has two lines one of which is another method call does look like something a gpt will spew out 🤣

queen adder
round scaffold
#

what if ur teacher finds out its ai code

queen adder
#

bro the code isnt ai

charred spoke
#

Well maybe you should have listened more in class?

queen adder
charred spoke
#

Then why is your assignment in Unity ?

round scaffold
#

if u just need a grade just follow a tutorial and get it done in like a day or two

solemn summit
#

Just make the cookie a UI button and slap your OnCookieClicked on there, bingo bango A+

queen adder
slender nymph
#

so did you think i was asking what called OnCookieClicked for shits and giggles? because the answer is obviously that you need to call that somewhere

queen adder
#

ok but I still dont understand what you are saying

slender nymph
#

something needs to call OnCookieClicked or else it won't be called

#

and what happens when OnCookieClicked is not called?

solemn summit
#

Called = Activated. Something, somewhere, in code or a UI button element, ANYTHING, needs to make that code run

#

Because right now it's just a block of text that isn't doing anything

queen adder
solemn summit
#

Until something CALLS it, and tells it to do what it's holding

queen adder
slender nymph
queen adder
#

I am sorry for this inconvience to you guys though

slender nymph
queen adder
solemn summit
#

Slap a Debug.Log in some functions and see what is getting called and what isn't

eternal needle
timber tide
#

look into how to log to the console and log the method you call with the button

#

from there then you can probably get more help

queen adder
#

I’m using the console and debug log to find what isn’t connecting

#

How to I move on from there

timber tide
#

First thing you should do is check if the method is being called to confirm it's at least being called

#

from there I'd start logging your counter each time you add a value to it

coral locust
#

Hey guys, i have a project due soon and i've been trying to figure out why my player keeps falling through the ground

cloud flume
#

does your character have a collider and the platform/ground

slender nymph
#

Keep in mind that a rigidbody isn't a collider, you would need both

coral locust
#

and a rigidbody

cloud flume
#

you need a collider on the platform

coral locust
#

ok ty

coral locust
#

platform

cloud flume
slender nymph
#

The platforms are on a tilemap, so you could use a tilemap collider

coral locust
slender nymph
#

Probably not

#

But either way, none of this is code related at this point

cloud flume
#

can anyone help me with this, im trying to make it so the camera can move 360 around the character but it seems to get stuck like it hits a wall at a certain point

#

i have a video if you need to watch

slender nymph
#

obligatory: use cinemachine

queen adder
#

@slender nymph You doubted me you pussy bitchass I'm the king lil bro dont ever try to not help me again

cloud flume
cloud flume
queen adder
cloud flume
#

he still tied to help when you were being rude

solemn summit
eternal needle
#

or just blocked by anyone who actually helps in this server.

queen adder
north kiln
#

!warn 643616849296097290 no memes or insults. Next time follow a tutorial or some learning resources and you'll have saved the hours it took you.

eternal falconBOT
#

dynoSuccess nt2heat has been warned.

coral locust
#

is there a reason for why my one way platforms aren't working?

#

i can't jump through from the bottom

round scaffold
#

try making the surface arc 179

coral locust
#

btw this is how it looks like

round scaffold
#

i remember havin a problem like this but i forgot how i dealt with it lol

native seal
#

Can anyone explain why I am getting a Null Reference Exception error here?

slender nymph
#

Have you assigned anything to inventory?

native seal
#

yes

slender nymph
#

Show the full error including the stack trace

native seal
#

NullReferenceException: Object reference not set to an instance of an object
UIInventory.Start () (at Assets/_Scripts/UI/UIInventory.cs:11)

#

the event still works though

#

im just getting that error

slender nymph
#

And line 11 is that line in Start?

native seal
#

11 is the assignment

slender nymph
#

Okay then you have another copy of the component in the scene where inventory was not assigned

gaunt ice
#

See if same script on multiple gameobjects

native seal
#

oh shit thanks

#

feel dumb now

#

i got a question tho with events, what would the difference between "public Action OnItemUpdated" be vs "public event Action OnItemsUpdated" and what does assigning it to delegate {} do? just ensure its not null?

slender nymph
#

The event keyword makes it impossible to invoke the event from any other type of object. And it is not necessary to assign the empty delegate to it, you could just null check it (which you should be doing anyway)

native seal
#

so ?.Invoke to null check

slender nymph
#

Yes

native seal
#

what do you mean "any other type of object"

eternal needle
#

other scripts cannot invoke the event

native seal
#

ah okay

#

so things with a reference to it cant invoke it

#

sort of like private

mystic axle
#

hi

#

can i get some help for something

#

how do i instantiate a prefab so that it is always five units away from the player, but in the direction that the player is facing

slender nymph
#

get the player's position, add 5 units on your preferred axis and use that Vector3 as the position you pass for Instantiate. then get the direction from that position to the player to use for the direction it faces

#

this is a code channel

odd mason
#

oh crap my bad

mystic axle
slender nymph
#

yes, if that is not what you want then you need to be specific

eternal needle
vestal eagle
#

Do unity support rust language?

slender nymph
vestal eagle
#

Nooo

#

Look like i have to other game engine

earnest tendon
#

hello, so im trying to add multiple characters to my game rn, and ive set 2 buttons, one that would start the game with 1 character and a difretn button that would start the game with a difrent character, how would i make it so when the player clicks a button the sprite of the character and the move animation of the character changes to a difrent sprite and movement animation?

#

would i have to make a completely new scene with a difrent character prefab?

slender nymph
#

i would make another character prefab as a prefab variant. but you don't need a copy of the scene for that. just have some object that can be used in both scenes like a DDOL object, scriptable object, or static variable that tells your gameplay scene which player prefab to spawn

fossil drum
slender nymph
#

DontDestroyOnLoad

earnest tendon
#

ah i see

misty raft
#

Question. How do I make it so when the game starts a amount of objects are disabled

slender nymph
#

put those objects into a list/array. on Start or Awake: optionally shuffle said list/array, get random number from 0 to the collection's length or max disabled objects, iterate through the collection and if the index is smaller than the number generated disable that object

shrewd swift
#

i got a problem
I switched computer, my Unity Project is on a USB key.
I did this a ton of times the past months, no issues.
But now I got a bunch of errors, related to some missing references of assemblies.
when opening the error in VS nothing shows

is Unity bugging or something ?

teal gulch
slender nymph
#

library is probably corrupted

shrewd swift
#

how can i reload without loosing stuff ?
URP seems to bug also, mat are now pink

slender nymph
#

you can delete the Library folder and restart Unity and VS and it should theoretically start working. but its' best to not copy your project using a USB like that, but use some sort of version control like git or Unity Version Control instead

vestal eagle
eternal needle
shrewd swift
#

doesnt explain why it happened

teal viper
#

Probably missing/corrupted packages

shrewd swift
#

well rn im removing then re-importing the packages were there is errors, but i dont see how this would solved the issues

shrewd swift
slender nymph
#

well that's probably worse. the issue is likely corrupted files 🤷‍♂️
regenerate your package cache using the instructions i gave you

eternal needle
shrewd swift
shrewd swift
slender nymph
#

sounds like a read/write issue then. hope your drive isn't dying

shrewd swift
#

i hope to

slender nymph
#

if it does, you will have learned a very important lesson about always using version control

mystic axle
#

wait

#

never mind

#

all good

#

sorry

slender nymph
#

Instantiate returns a reference to the object that was instantiated. use that to assign its forward

shrewd swift
#

what is VirtualArtifacts/Primary/ ?

teal viper
shrewd swift
#

ok

#

well deleting library folders and restarting the project fixed all isssues

#

very weird that everything got corrupetd
i'll try installing UVC just in case

teal viper
eternal needle
mystic axle
#

how do i destroy a prefab from a different script

#

i mean

#

an instantiated prefab

#

but not all of the instantiated prefabs

shrewd swift
#

project is on USB since october, from my MAIN pc and LAPTOP i am loading the project from the USB

#

so the files are not "changed" from that

#

maybe i disconnected the usb to soon ? idk, i always make sure unity & VS stoped

teal viper
shrewd swift
#

anyway, I now setup UVC in one of my main drive, will do that same back home

shrewd swift
shrewd swift
eternal needle
#

Either way at least u got some vc

restive kernel
#

Hi im NEW to coding and i thought i might just start by following a tutorial 1 for 1 and i did, this one https://youtu.be/1uW-GbHrtQc?si=KFbQGVzXYBzisfr6 i have followed it exactly but its not woking when the movement script gets dragged to the player file it only dose (pic 1) insted of what is show in the video at 1:40 . had VS Code set to C++ then changed it to C# and it still doesn’t work.

Walk, Run, Jump and Sprint! Easily customizable!
A very simple player movement script that will get you started on your 3d project. Code is pinned in comments.
3D, First person (easy change to third person).
Sub for more :)

▶ Play video
slender nymph
#

1: https://screenshot.help
2. make sure that there are no compile errors in your console
3. and get your !IDE configured using the instructions linked by the bot below 👇

eternal falconBOT
hasty spire
#

im tryna work on an enemy that patrols between a set of points

#

but it is just standing there

#

and wont move

#

here is the setup in the inspector

hexed terrace
#

are the patrol points actually placed at a different position ?

restive kernel
#

@slender nymph thank you soooo much for ur time and help it worked but idk how i think i didn’t have VS code set up properly

hasty spire
#

these are the two points @hexed terrace

icy sluice
restive kernel
#

I wouldn’t mind

icy sluice
#

Give me 10min until i finish my lunch

hexed terrace
#

VSC being "set to" C++ or C# isn't relevant, will make no difference to whether it works or not.

icy sluice
icy sluice
hexed terrace
#
[RequireComponent(typeof(CharacterController))]
public class PlayerController : MonoBehaviour
{```

Use the `RequireComponent` attribute and it will auto add one for you, if there isn't one already
#

(Which is what the tutorial he's doing does)

teal viper
#

My parents always taught me not to take code from strangers.

woeful hedge
#
void OnTriggerEnter2D(Collider2D collider)
    {
        if (collider.gameObject.tag == "Player")
        {
            Debug.Log("Triggered");
            Event.Invoke();
            Audio.Play();
            if (BreakOnActivate)
            {
                Destroy(gameObject, 0f);
            }
        }

    }
#

so I just added this code to play some sfx

#

but the Audio wont come out, what should I do?
the debug.log showed well and the audio file is noting wrong

hexed terrace
#

What GameObject is Audio on ?

woeful hedge
#

itself

#

wait

hexed terrace
#

You're playing it then destroying the gameobject straight away

woeful hedge
woeful hedge
#

nah I hate myself

#

Thanks bro

hexed terrace
#

We've all done it

hasty spire
#

carwash are these logs correct?

hexed terrace
#

You tell me... did you just type them and then take a screen shot? Or did you run the game and test ?

hexed terrace
#

You can edit msgs.

hasty spire
#

i couldnt be bothered

hexed terrace
#

now log out the target pos, not the index

hasty spire
#

would i use a serialize field?

hexed terrace
#

then that's your problem, there is no target position assigned

hasty spire
#

well shouldnt my array handle that?

#

i have the transforms of my points in the array

ruby python
#

Have you capitalised the T in transform in your code?

ruby python
#

Okay, just checking, you'd be surprised at how many times something like that can be the culprit.

hasty spire
ruby python
#

Do you get the Transform error when you try to debug 'patrolPoints[currentPointIndex].position' ?

#

Also, for future reference, don't screenshot code, it's a pia tbh.

!code

eternal falconBOT
gilded pumice
#

Hey guys I have a question, I have this code and I cannot figure out where I'm getting this error. When I fire up the game if I shoot the medium monster first, things go as intended, but when I hit the hard monster I get thrown a NRE error on this script. If I shoot the hard monster first, it goes just fine, but then try to shoot the medium monster and the NRE gets thrown again.

https://paste.ofcode.org/EnMX5GGZfiVTA6JMQPkMCL

I'm kinda at a loss rn

ruby python
#

Okay, what are you debugging when you get the Transform error?

hasty spire
#

i was making a mistake anyways here is he result

ruby python
hasty spire
#

this is my code

ruby python
#

Also, I'm not 100% sure on this, but it may be better to deal with the collision/killing the monsters on the actual monsters themselves instead of referencing them through the bullet (if that makes sense?)

gilded pumice
hasty spire
ruby python
#

Yeah you should just be able to check if the monster has collided with a bullet and adjust the monsters health accordingly. Pretty much exactly the way you have done already but in reverse, and you would only need one 'Monster script' just with different max health levels.

ruby python
#
if (once == false)
    {
    once = true;    
        StartCoroutine(Wait());
    }
else if (transform.position != patrolPoints[currentPointIndex].position)
    {
        transform.position = Vector2.MoveTowards(transform.position, patrolPoints[currentPointIndex].position, speed*Time.deltaTime);
        }

Maybe that?

gilded pumice
ruby python
#

Ah, yeah, sorry, shoulda spotting that tbh. To get around that I would remove the 'find' at the start and just use the collision to grab the script(s)

buoyant knot
#

sounds to me like you need to use more Debug.Assert

hasty spire
#

not working

#

i think im gonna come back to it after sleep

ruby python
gilded pumice
shrewd swift
#

is there a way to make the value not taking to much space ?

shrewd swift
#

how ?

icy sluice
#

You are using 2 floats here

#

Right

#

If you want to change how it looks, you will need to add a custom editor

#

And if you have just these 2 floats, i personaly dont reccomend

#

Use a header as a text and just add a singlecharacter as a value

ruby python
icy sluice
shrewd swift
icy sluice
#

Np

#

Sometimes cheating unity inspector is better than making a whole custom inspector xd

gilded pumice
ruby python
#

Cool. 🙂 No probs.

fringe kindle
#

How do you switch scenes but keep your original position when you switch back to the original scene?

#

Because I know that loadscene resets the scene back to it's original state

#

How do I keep my character's original place in scene A from when I switch to scene B?

gaunt ice
#

general case: from scene A->B->C->....->Z then go back from Z->Y->X.....->A, you need a stack

frosty hound
bright oxide
#

Out of incapsulation point of view, can i destroy a gameObject this way?

brave compass
bright oxide
#

I was thinking of moving the destroy logics to the item script, but then i would have to use IsFull() method from the Inventory, and i dont know if that is good either

modest palm
polar acorn
brave compass
# bright oxide I was thinking of moving the destroy logics to the item script, but then i would...

It's completely subjective which is better, but personally, I don't think it should be the item's responsibility to detect pick ups and add itself to inventories. I prefer to think of items as passive things in the world that are waiting to be picked up. I would separate the pick up behavior into its own script that does the OnTriggerEnter, adding to the inventory and destroying. Think of it as the interface between the "real" world and the abstract inventory world.

polar acorn
#

But having the inventory be responsible for destroying the item only when it actually has room for it is perfectly valid, it's what I'd do as well. The item doesn't know if it should destroy itself without knowledge from the inventory, so it shouldn't be responsible for destroying itself

buoyant knot
#

i disagree. I would do it the other way around

#

i would make Inventory.TryAddItem(Item item);
I’d make it return a bool to let the thing trying to add item to inventory know that it cannot be added.

#

then item should be responsible for knowing if it should destroy itself, or just ignore and stay on the ground, or whatever

#

because only the Item knows what to do when it is personally added to inventory. It might need to invoke something when it is successfully added, or it might be in a pool

polar acorn
bright oxide
tawdry totem
#

basically when im not looking at the weapon im referencing the outline that is false on the code, how i make it doesn't count as an error, the game works just fine with the bug, i just wanna remove the error message

buoyant knot
#

handle the error. don’t ignore it lmao

#

it IS an error, because you are working with something expected to not be null. It is null, and you don’t have a case for it

#

make a case for the thing being null, and make a case for it

eternal needle
swift crag
#

You should have zero errors in your console. If you see them, fix them.

swift crag
#

errors caused by thrown exceptions mean that your code is just..randomly getting murdered

#

which makes it a lot harder to reason about what your code is doing

swift crag
#
if (hoveredWeapon.TryGetComponent(out Outline outline))
  outline.enabled = true;
#

Or, even better: gunScript should reference an Outline component

#

I would do that if every gun had an outline on it

buoyant knot
#

also GunScript should be capitalized

#

it is a class name

tawdry totem
buoyant knot
#

use the VisualStudio rename feature to have it automatically rename gunScript everywhere it appears in code

#

I believe it is shift+ctrl+R, when you click on the name you want to change

buoyant knot
#

example:
[field: SerializeField] public Outline outline {get; private set; }

#

example2:
public Outline outline {get; private set; }
private void Awake() {
outline = GetComponent<Outline>();
}

tawdry totem
#

oh, like an singleton

buoyant knot
#

what? this has nothing to do with a singleton

#

a singleton is a class that enforces that at most 1 instance of it exists at a time, and provides access to that one instance

buoyant knot
#

if that is how you wrote a singleton, then it is not a singleton

#

if you have a monobehaviour singleton, then its Awake needs to check to see if another instance of itself exists already, and if so, destroy what would be the a second instance. If it does not exist, that instance assigns itself as THE instance for the class

#

does that make sense?

tawdry totem
#

uhum

buoyant knot
#

GunScript just needs to hold a reference to a different object that is publicly accessible, but NOT publicly modifiable

buoyant knot
tawdry totem
buoyant knot
#

what? no

#

this is just in the definition of the class

tawdry totem
#

so i can just do this right?

buoyant knot
#

yes

#

and also rename gunScript to GunScript using the Rename feature of your IDE

fringe kindle
#

my SceneManager.LoadScene isn't working. I have the names of the scenes correct but when I press E on the hubworld, it won't load the level I want it to

wintry quarry
#

unless you are spiderman

tawdry totem
buoyant knot
#

Input.GetKeyDown is true for exactly one frame

#

OnTriggerEnter is only even called during fixed update frames

fringe kindle
wintry quarry
#

it's wrong for two reasons

fringe kindle
#

Wait scratch that

wintry quarry
#
  1. OnTriggerEnter is similar to FixedUpdate in that it runs in cadence with the physics update, which doesn't run every frame. It's very likely your key press will land on either side of a physics frame
fringe kindle
#

I forgot I changed that code

wintry quarry
#
  1. The timing required is basically impossible
fringe kindle
#

Forget what I said about it working facepalmsigh

wintry quarry
#

yep

fringe kindle
#

So what could I do instead?

buoyant knot
#

GetKey is true on any frame where the key is down

wintry quarry
#

Depends what behavior you're looking for

#

you want to be able to press a button while inside the trigger?

fringe kindle
#

Yes

wintry quarry
#

Then keep track of when you're inside

#

with a bool

#

set it true in OnTriggerEnter, false in OnTriggerExit

#

then in Update you can listen for the input and check if you're inside as well

#
if (Input.GetKeyDown(...) && currentlyInsideTheThing) {
  // do something
}```
buoyant knot
#

you’d do the same thing with InputSystem, but it would instead invoke just the function of what to do when pressing down

#

instead of checking in update

keen hill
#

yo i need help with referencing the rigidbody of another object and on collision doing something can someone can help me possibly through a vc??

wintry quarry
keen hill
#

i just asked

wintry quarry
#

Explain what you tried and how it went wrong

merry spade
#

Im currently making a Board of buttons and allready have the script to activate them, but now I am thinking of the best way to implement functionality, do I have to implement a new script for every button or how can I call different functions with one script?

wintry quarry
buoyant knot
keen hill
#

okay so im writing a script about picking up an item and then on collision playing a sound but i dont know how to reference a different gameobject's rigidbody and using the fucktion on collisionenter i can provide a script

wintry quarry
lunar grove
#

Anyone know on how to instantiate a Script instance attached to the same GameObject within a Script?

keen hill
#

i want it to react to my picked object collision

buoyant knot
#

i believe the collider has better direct access to the rigidbody, if I’m not mistaken

keen hill
#

so when my held object touches something it makes a sound

#

the problem is i have the pick up script on my player

wintry quarry
merry spade
keen hill
#

and i want to reference the object rigidbody which i did but i dont know how to like "connect it" to on collision enter

buoyant knot
#

as in:
CircleCollider2D myCollider = gameObject.AddComponent<CircleCollider2D>();

keen hill
#

sorry if im wrong im a beggienr

wintry quarry
wintry quarry
#

follow it

merry spade
icy sluice
#

what does he need?

merry spade
wintry quarry
keen hill
#

oh i think i get it now

#

Thanks brb ill let you know if it works

lunar grove
icy sluice
buoyant knot
#

that still doesn’t make sense

lunar grove
#

Oh wait is this the code for what I'm trying to do

swift crag
lunar grove
#
gameObject.GetComponent<SpriteAnimationScript>();
wintry quarry
wintry quarry
icy sluice
lunar grove
wintry quarry
#

Sounds like you already know the answer

lunar grove
icy sluice
#

now that you have SpriteanimationYourNamwwhatever
you can do SpriteanimationYourNamwwhatever.{name of the function}(some args)

wintry quarry
#

this is correct

#

(except you don't need the gameObject part, it's extraneous)

icy sluice
#

oh, yeah

icy sluice
#

no, you dont

#

it already knows you want to pull from object its already on

lunar grove
#

Alright thanks

icy sluice
#

like it would do any difference

swift crag
#

GetComponent is a method on both GameObject and Component.

#

It looks for a component on the game object or the component's game object

buoyant knot
#

in a MonoBehaviour, GetComponent() calls gameObject.GetComponent()

lunar grove
#

Ahh okay okay I see I see thanks for the help!

#

Do i use a descriptive name for the Down Arrow Key when using GetInput?

lunar grove
#

lol

swift crag
#

GetButton doesn't care about specific keys on your keyboard

#

It uses buttons that are defined in the Input Manager

#

like "Fire"

wintry quarry
lunar grove
#

But it has a setting

#

Negative and Non-Negative Names

rocky canyon
#

GetButtons are presets..(automatic) GetKey would be a specific key.. (manual)

lunar grove
swift crag
#

oh, those are names you can use to describe the axis

rocky canyon
#

axis.. like up and down arrow ^

lunar grove
#

ah

#

lol

swift crag
#

I've never touched that before

#

They aren't functional.

keen crescent
#

Having a weird issue: I'm using a script that uses a Level ScriptableObject to instantiate prefab lights etc. for a given level
This works perfectly, but I'm trying to do the exact same thing with a particle system prefab, and I'm getting "The Object you want to instantiate is null." when it is definitely not null. Its field is populated in the ScriptableObject and the there's nothing wrong with the asset itself (in fact, its an exact copy of an asset I'm already instantiating somewhere else, I just copied it to test)
Any ideas?

swift crag
#

I guess you could put in "Up" and "Down" in the positive and negative name fields

#

or "Throttle" and "Brake"

lunar grove
#

Ah i see isee thanks

swift crag
polar acorn
keen crescent
keen crescent
swift crag
#

or your code is doing something else that's causing the error

swift crag
#

now verify that currentLevel is what you think it is

#

if you do this, you can click on the log entry to be taken to the asset

#
Debug.Log("I'm at: " + currentLevel, currentLevel);
keen crescent
polar acorn
swift crag
#

well, it's throwing an exception, so something sure isn't equal

tawdry totem
polar acorn
keen crescent
# polar acorn Okay, what is currentLevel?

A given Level object with its properties read from a Level ScriptableObject
All other values are being read from the SO correctly, it only gives an error during this final step
Commenting that one line out, everything works as expected

swift crag
#

That doesn't answer digi's question

swift crag
#

prove that it's the correct asset

#

It doesn't matter what you think your program is doing

swift crag
#

if your weapon has no outline component, then outline will be null, and you'll get an error

tawdry totem
#

also there is a reference on GunScript

swift crag
#

It sounds to me like hoveredWeapon doesn't have an Outline on it.

wintry quarry
# tawdry totem with the fix

line 35 establishes already that the object does NOT have an outline component. So line 39 will always give you a NullReferenceException

swift crag
#

oh, good catch

#

that else block is in the completely wrong place

wintry quarry
#

What you need to do is save the Outline reference for later

#

in a member variable

swift crag
#

it sounds to me like it should be after the if (Physics.Raycast... bit

keen crescent
swift crag
#

and line 32 shouldn'tbe looking at hoveredWeapon. surely it should be looking at the thing you just hit

keen crescent
#

Yes, but like I said, I already tested that

swift crag
#

So you logged currentLevel before you tried to instantiate its particle system prefab, and when you clicked on the log entry, it took you to the correct asset in the Project window?

keen crescent
#

the currentLevel value isn't itself an asset, but the SO is

wintry quarry
#

I'd do this @tawdry totem

Outline lastOutline;

void Update() {
    if (lastOutline != null) {
       lastOutline.enabled = false;
       lastOutline = null;
    }

    // other stuff
    if (Physics.Raycast(...)) {
      if (hit.transform.TryGetComponent(out Outline newOutline)) {
          lastOutline = newOutline;
          newOutline.enabled = true;
      }
    }
}```
keen hill
#

It works perfectly thanks !

swift crag
#

Or do you just mean you're passing a reference to a scriptable object asset into that method's currentLevel argument?

swift crag
keen crescent
tawdry totem
swift crag
keen crescent
polar acorn
polar acorn
keen crescent
swift crag
#

You're not instilling confidence by ignoring what I'm asking you to do and saying you're "100% sure"

keen crescent
#

Thanks for the help though, I know what I did wrong, I had to fix a line in the Level constructor

polar acorn
swift crag
#

Level has a constructor?!?

keen crescent
#

sorry, not the actual constructor

cosmic quail
#

if theres a bug then u cant be 100% sure that everything is correct

swift crag
#

ah, okay.

cosmic quail
#

you can be 100% sure that something is incorrect tho

swift crag
#

(because ScriptableObject types should not be constructed directly)

keen crescent
polar acorn
#

Once we confirm the level is correct then we move on to seeing if the referenced prefab is correct and so on

swift crag
keen crescent
#

Correct

swift crag
#

that would have been very useful information to have.

polar acorn
#

That's what debugging is, building a core of confirmed truths until you find the one that is different than your assumptions

swift crag
#

and I presume you just weren't copying the particle system prefab reference over, then

swift crag
#

which suggests that you didn't try it...

buoyant knot
#

and dropping a ton of assertions to try to trip up the first part of the chain that does not match assumptions

keen crescent
#

idk why ya'll are assuming I just said I was 100% certain it was reading correctly without testing anything

#

I don't ask questions without trying to debug I promise!

polar acorn
#

and, again, dozens of people a day come in here "100% sure" of things that are just patently untrue

swift crag
#

(they also have generally already 'tried everything' and 'tried thousands of times')

polar acorn
keen crescent
#

Yeah understandable

#

thank you guys

swift crag
#

I was under the false impression that Level was the level scriptable object

buoyant knot
#

all he said is that the instances being accessed are the correct instances

swift crag
#

that was the hangup

#

(which is why sharing code helps, too)

#

i'd have cottoned on pretty quickly then!

keen crescent
lucid path
#

these are in separate scripts, the latter of which is an instantiation. i’d like to avoid using a public bool across the two scripts if that is possible

twin bolt
#

Why am i unable to move if the player is looking completely down? ``` float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");

        Vector3 forward = playerCamera.transform.forward;
        Vector3 right = playerCamera.transform.right;
        forward.y = 0f;
        right.y = 0f;  
        forward.Normalize();
        right.Normalize();

        Vector3 desiredMoveDirection = forward * verticalInput + right * horizontalInput;

        rb.velocity = new Vector3(desiredMoveDirection.x * playerSpeed, rb.velocity.y, desiredMoveDirection.z * playerSpeed);```
wintry quarry
lucid path
wintry quarry
#

instead of using the camera direction you should use the player body's orientation

twin bolt
wintry quarry
#

i.e. rotate the Rigidbody and not the Transform

twin bolt
wintry quarry
wintry quarry
#

not exactly

#

more like:

rb.rotation *= Quaternion.Euler(0, mouseXInput, 0);```
queen adder
#

is it not possible to use if statements in interfaces?

polar acorn
summer stump
queen adder
polar acorn
rocky canyon
#

debug the variable after u assign it and see

polar acorn
rocky canyon
#

if it returns null its not..

queen adder
rocky canyon
#

lol, that'll do it

lunar grove
#
transform.position += new Vector3(0, -0.2f, 0);
#

this changes my object position to -0.2 Y right?

polar acorn
lunar grove
#

not negative?

polar acorn
#

Sorry, -0.2

lunar grove
#

it doesnt change on mine for some reason

#

I coded it to change for every frame that I hold the down arrow key down

lunar grove
#
 private void Update()
    {
        characterDirection += Vector3.down * characterGravity * Time.deltaTime ;

        if(characterController.isGrounded) 
        {
            characterDirection = Vector3.down;

            if(Input.GetButton("Jump") && !Input.GetKey(KeyCode.DownArrow))
            {
                characterDirection = Vector3.up * characterJumpForce;
            }

            if (Input.GetKey(KeyCode.DownArrow))
            {
                dinoAnimation.CancelInvoke();
                dinoAnimation.AltAnimate();
                transform.position += new Vector3(0, -0.2f, 0);
            }

            if (Input.GetKeyUp(KeyCode.DownArrow))
            {         
                dinoAnimation.Animate();
                characterDirection = Vector3.down;
            }
        } 
        else
        {
            if(Input.GetKey(KeyCode.DownArrow))
            {
                characterDirection = Vector3.down * characterDownForce;
            }
        }

        characterController.Move(characterDirection * Time.deltaTime);
    }
#

I just provided the entire update method lol

lunar grove
#

Ah I see thanks

#

but wait

#

oh wait

#

nvm

keen dew
#

Why don't you just apply it to characterDirection

polar acorn
#

if you just add the value to characterDirection it'll get applied to the character controller

#

instead of trying to teleport the object

rocky canyon
#

manipulate this variable all you need prior to the Move function

#

add to it, subtract from it, w/e u need.. keeps it clean and easy

lunar grove
#

Ah but i actually need to just reposition my character to look like its still on the ground

keen dew
#

This is the wrong way to do it altogether

lunar grove
#

i just need it to look like it stays on ground after pressing down key

keen dew
#

I understand what the goal is, but how you're trying to do it won't work

twin bolt
# wintry quarry more like: ```cs rb.rotation *= Quaternion.Euler(0, mouseXInput, 0);```

WHy does the y keep resetting back to 0? ``` yaw = rb.rotation.y + Input.GetAxis("Mouse X") * mouseSensitivity;

            if (!invertCamera)
            {
                pitch -= mouseSensitivity * Input.GetAxis("Mouse Y");
            }
            else
            {
                // Inverted Y
                pitch += mouseSensitivity * Input.GetAxis("Mouse Y");
            }

            // Clamp pitch between lookAngle
            pitch = Mathf.Clamp(pitch, -maxLookAngle, maxLookAngle);

            rb.rotation = Quaternion.Euler(0, yaw, 0);
            playerCamera.transform.localRotation = Quaternion.Euler(pitch, 0, 0);```
lunar grove
keen dew
#

no

wintry quarry