#💻┃code-beginner

1 messages · Page 156 of 1

buoyant knot
#

like saving the whole .asset file

summer pulsar
#

it works here but not there thats why im confused

buoyant knot
#

honeslty, I just need an event that is called automatically in editor, that must be called before I close the inspector for the SO

timber tide
#

Does OnValidate() not get called though? Could check if it does

#

or maybe SerializationCallback interface

north kiln
buoyant knot
silver sun
#

that saved me a considerable amount of time thanks to you.

thick orbit
#

Hello, I'm working on a game that involves soldiers automatically firing on enemy units within a certain range. I have functionality for aiming and firing at a set target, but its a bit choppy getting the logic for choosing a target down. Currently Im using a collider on trigger to determine range that sets collided objects to be the target. However on its own that meant soldiers were switching to new targets once they entered range instead of finishing off their old targets. I have a little progress where now I check to see if the target field is null before the collision sets a new target. The problem with this is that if there are two enemies close by, once the originally targeted enemy dies, the troopers do not target the other once because its already within the collider's sphere. Any ideas how to fix this?

Current relevant code:

private void OnTriggerEnter(Collider collider)
{
    if (collider.TryGetComponent<EnemyID>(out EnemyID enemytroop))
    {
        if (targetTransform == null)
        {
            targetTransform = collider.gameObject.transform;
        }
    }
}
summer pulsar
eternal needle
sour fulcrum
#

bump 😄

timber tide
#

along with managing how you want to focus a target

thick orbit
#

Ok that worked perfectly, thank you

#

OnTriggerStay is exactly what I needed

eternal needle
# thick orbit OnTriggerStay is exactly what I needed

if this is for a lot of units, might want to consider just storing in a list. OnTriggerStay will be called 50 times each frame, for each target, for each enemy. If you dont have too much going on then its not a concern really.
With a list you can also have it easily compare which target is closest, which entered first/last etc

#

basically gives you more control of what to target

queen adder
#

Give them an id and start with the lowest in the array

molten pulsar
#

hi

#

i have a problem whit this line of code

night mural
queen adder
#

Ive never seen a raycast done that way

molten pulsar
#

the line that says if(Physics.Raycast(ray, out hitInfo, distance, mask))

night mural
molten pulsar
#

well when i hit play

night mural
#

you have 2 errors underlined in red that you can hover over and read

#

before you even hit play, you can see that there are errors

molten pulsar
#

yes but what is wrong?

night mural
#

what does the error say? it should tell you

eternal needle
molten pulsar
night mural
#

sounds like you should check that function and make sure your arguments are in the correct order

eternal needle
#

you are using 3d raycast btw

night mural
#

(yeah that's the real problem but hopefully we'd get there through actual debugging)

molten pulsar
night mural
molten pulsar
#

oh

night mural
#

they can't mix

queen adder
#

So what the 2d hit doin

molten pulsar
#

that was a stupid mistake

night mural
#

best kind to make since they are easy to fix

queen adder
#

I imagine it still won't work

night mural
#

if you follow the errors they will get you there

eternal needle
queen adder
#

I cant see how they've got it setup working in the docs

molten pulsar
#

so that finally works

#

ty

queen adder
#

So does Ray just store pos and direction?

night mural
warm depot
#

hello, my script machine is fully broken, I can't right click or zoom in or out or anything. Does anyone know what's going on?

queen adder
#

Script machine?

warm depot
#

yea script machine component for visual scripting

eternal needle
queen adder
#

Haven't a clue, if in doubt restart the editor

swift crag
#

reset your layout in the top right corner if the editor windows are messed up

rocky canyon
#

visual scripting basically a disadvantage imo, less people use it

#

than standard scripting

queen adder
#

IDEs are so complex now they basically are visual scripting

rocky canyon
#

👀 interesting point of view

eternal needle
#

definitely not lol

queen adder
#

You type like 2 letters in a configed Rider and it already knows what you wanna do

rocky canyon
#

sometimes, usually just finishes word.. like autocomplete on ur cellphone.

eternal needle
#

that has nothing to even do with visual scripting

rocky canyon
#

its not gonna autocomplete an entire script, or finish ur system for ya

#

maybe u can find some help in there

#

or if u can convert what u have into normal code u can just ask here, and convert it back into visual code

queen adder
rocky canyon
#

that may be viable

#

no, lol not that know of.. but u made it sound like thats what an IDE does

#

so ur using Bolt?

ionic zephyr
#

should I use RigidBody or Logic to move my character in the overworld of a pokemon type Overworld???'

queen adder
#

No, I just had in my head visual scripting was like that Unreal Engine type thing where you drag the lines around

warm depot
#

its whatever is built into unity

rocky canyon
#

Ideally you should learn to use both tools in tandem because visual scripting is a better solution sometimes, and other times, traditional code is best. Learning how and when to use each is one in the same as learning how to use unity.```
swift crag
rocky canyon
#

^ good reply to a forum thread where they asking regular's for help in visual scripting

swift crag
#

I think the same applies here.

sour fulcrum
#

How does Unity actually create the gameobjects in a scene when a scene is loaded? Is the actual creation in the c++ side of it?

ivory bobcat
#

You can hide the code (syntax) but you cannot hide the logic.

rocky canyon
ionic zephyr
#

like changing the transform.position I mean

rocky canyon
#

do you need a Physics heavy character?

#

if not.. don't use a rigidbody.. use a CC instead

ionic zephyr
#

Not really, I´m worried about collisions

rocky canyon
#

CC will detect collisions just fine

#

it has its own method

queen adder
#

Character controller is a lot less of a headache

ionic zephyr
#

Im using 2D

#

Which is better Character Controller or creating my own logic?

rocky canyon
#

CC doesn't have Gravity so you'll have to code that in
a Rigidbody doesn't have Ground Checks or Stair Climbing Capability you'll have to code that in..

ivory bobcat
#

Or you can roll your own detection system if little to no common game movement is needed. Not very practical though.

rocky canyon
#

what one has the other doesn't pretty much

#

adding gravity is baby steps

ionic zephyr
rocky canyon
#

they both can do teh same things as each other..

queen adder
#

Stairs, slopes, ground detection, friction managing..
Vs
Adding gravity

rocky canyon
#

physics is pretty easy to just setup and like the physics engine react..

ionic zephyr
rocky canyon
#

a CC will be lots of coding to get elevators, or knockbacks, etc to work

#

but a Rigidbody will just work with that stuff, after you code in the ground checks and stuff

queen adder
#

Never thought of that

ivory bobcat
#

If you're doing grid based old school jrpg/dungeon crawler-like, you'll not need anything complex to move your character.

ionic zephyr
#

The thing is I´ll make a transition between battle and overworld exploration

#

so maybe I can use CC for Overworld

#

and RigidBody for the combat phase

ionic zephyr
vernal minnow
#

What would cause an object to freeze a variable after one use in a built version of a game?

ivory bobcat
ionic zephyr
#

No, logic (transform.position)

#

modifying it I mean

vernal minnow
#

My enemies should fire bullets at me, and yet they fire one round and then just stop firing

vernal minnow
#

Yes

ivory bobcat
vernal minnow
#

They still follow the player which is even more confusing

queen adder
#

Probably something running too high FPS that needs to be migrated from Update to FixedUpdate if I had to hazard a guess

#

Did you build as development?

vernal minnow
#

It's a timed event though

ionic zephyr
vernal minnow
vernal minnow
#

What's a development build do?

swift crag
#

put things in FixedUpdate if they need to interact with physics

rocky canyon
#

you'll have a Console.. and see debug logs

queen adder
rocky canyon
#

not applicable

queen adder
swift crag
#

not the other interpretation of "inappropriate"

#

(:

vernal minnow
swift crag
#

Yes.

#

Share your code.

vernal minnow
#

Alright

queen adder
#

I mean, weren't given a lot to work with and that's the only thing I can think of that has caused me errors in build only

ivory bobcat
#

It's assigned the x and y values every update, so perhaps set those values to zero if input is no longer being applied

ionic zephyr
#

Okay, lets see

ivory bobcat
#

We'd need to see where you're calling register x and y

ionic zephyr
#

I thought of adding an if(is pressing w,a,s or d)

rocky canyon
#
        if (Input.GetKey(KeyCode.LeftShift))
        {
            _playerMovement.Run();
        }
        else if (Input.GetKeyUp(KeyCode.LeftShift))
        {
            _playerMovement.StopRunning();
        }```

this is a little off... GetKeyUp() would be registered on the next frame..
vernal minnow
vernal minnow
rocky canyon
#

getkey and getkeyup can't be triggered on the same frame

#

so the else if() really isnt necessary

swift crag
#
if(transform.position.x == target.x && transform.position.y == target.y)

I'm not a huge fan of this. It actually should work okay, since you're using Vector2.MoveTowards, which returns exactly the "to" vector if it's close enough

#

But exact comparisons of floats like this are just inviting problems with floating point error

ivory bobcat
swift crag
#

especially if you're setting the position into transform.position

swift crag
#

That's going to update your transform's local position.

#

This may result in a slightly different world position than the one you asked for.

#

Instead, do this:

if (Vector3.Distance(transform.position, target) < 0.01f)
#

pick some small value

rocky canyon
#

for those to work they'd have to be in seperate if statements

ivory bobcat
#

With your second script, we can assume that the movement vector can be a zero vector. Anything multiplied by zero (all parts of the vector are zero) will result in a zero vector. Either movement somehow isn't zero or something else is moving the character.

rocky canyon
#

the else if block checking for Input.GetKeyUp(KeyCode.LeftShift) might not be triggered if another key is pressed in between the Update frames. If another key is pressed, the else if block won't be executed even if the Left Shift key is released in the same frame.

vernal minnow
swift crag
swift crag
#

basically, favor checking if two vectors are really close together rather than testing if their x and y values are identical

vernal minnow
ionic zephyr
#

the thing is that it is not a big movement but it is a tiny little space that my character advances because of inertia or moment of some kind

swift crag
#

the development build should give you more readable logs

ivory bobcat
vernal minnow
ionic zephyr
#

which I don´t like at all for a game of this characteristics

vernal minnow
#

ill be back in a bit if i find anything odd

rocky canyon
#

you can use an additional condition to check if ur registerX and Y are zero.. or (approximately 0) and if they are can call a function to stop the player

ionic zephyr
#

oh okay, thanks

#

is it strange to this?

#

just curiosity

rocky canyon
#

my controllers usually stop on their own. b/c they're continuously using the inputs with a multiplier to move..

#

when its 0 (0 * multiplier = 0) so no forces/movement goes thru the player

ivory bobcat
#

Maybe consider raw input

ionic zephyr
#

sorry, what is raw input

ivory bobcat
#

With raw input, the values will be either zero, one or negative one. You'll not get the miniscule values in between, which you aren't wanting as those values will count towards the normalized result.

ionic zephyr
#

oooh thanks a lot

#

My God this is just what I needed

#

thanks a lot

rocky canyon
#

how'd u write ur code? most tutorials will explain the difference.. thats the very first thing i learned in unity

#

good segue on how smoothing works

gritty notch
#

does anyone know how i can get world bounds of a ui element?

rocky canyon
#

thats a good one.

vernal minnow
ivory bobcat
#

Could probably convert the screen coordinates to world coordinates, blue's on the more appropriate track

vernal minnow
#

its saying the object that i want to instantiate is null after the first fire@swift crag

#

any idea what could cause that?

swift crag
#

Oh, are you destroying the prefab

vernal minnow
#

shouldnt be

wintry quarry
#

sounds like you might be

vernal minnow
#

should be destroying closes just like all the other enemies

swift crag
#

Yeah. You’re destroying shot

vernal minnow
#

bruh... clones*

wintry quarry
#

You're definitely destroying the prefab

swift crag
#

you're discarding the instantiated object

vernal minnow
#

i keep getting blocked by the mod bot lol

north kiln
#

Good

wintry quarry
#
var cloneBullet = Instantiate(prefab, ...);
// later
Destroy(cloneBullet);```
#

What you have right now is Destroy(prefab)

swift crag
#

You should have been getting a bunch of warnings in your console about trying to destroy a prefab.

wintry quarry
#

naming your variables more clearly would help avoid this btw. If your variable was called bulletPrefab you would be less likely to accidentally destroy it

vernal minnow
wintry quarry
swift crag
#

even if you hit your mailbox with your car, your front door will be fine

vernal minnow
#

the enemy for one

#

enemy shooter ai*

wintry quarry
#

well where's your code that destroys enemies

#

presumably it's not this same code

swift crag
#

EnemyShooterAI does not destroy anything other than its shot prefab.

wintry quarry
vernal minnow
swift crag
vernal minnow
#

fair enough

ivory bobcat
#

How to post !code

eternal falconBOT
swift crag
#

i presume it correctly destroys the instance, or doesn't destroy anything at all

vernal minnow
#

wait so the coroutine is just removing the prefab?

#

so whys it work in the editor?

swift crag
#

It is passing the reference to the prefab to Destroy

swift crag
#

You will find out why.

wintry quarry
swift crag
#

you really shouldn't be ignoring warning messages in your console. Unity isn't printing them for fun.

vernal minnow
#

im a dimwit

#

i have had an error for a while like that

#

wasnt causing issues so i ignored it

swift crag
#

Yes.

vernal minnow
#

wow im dense

swift crag
#

A prefab is a kind of asset, and you were asking Unity to destroy the asset.

ivory bobcat
#

With an error, your play session will attempt to run the most recent working version that did not have any errors

ivory bobcat
#

Oh, runtime error

swift crag
#

and when it's a compile error, unity just refuses to run :p

vernal minnow
#

GameObject laser = (GameObject)Instantiate(CirclePrefab, firePoint.position /*+ new Vector3(0.0f, 0.0f, 0)*/, itGuy.rotation /*Quaternion.identity*/); so a variation of this should fix it?

#

thats the players version

swift crag
#

why are you casting that to a GameObject?

#

what is the type of CirclePrefab?

vernal minnow
#

the prefab is the bullet

#

they share a similar name being 1 and 2

swift crag
#

okay, and what is the type of the CirclePrefab variable?

vernal minnow
#

public GameObject CirclePrefab;

swift crag
#

okay, so there's no need for that GameObject cast

#

that was confusing to me

#

anyway, yes, you'll save the reference returned by Instantiate

#

then pass that to your destroy coroutine

#

Alternatively

#

You can just do Destroy(thing, 2f); to destroy something after 2 seconds

vernal minnow
swift crag
vernal minnow
#

the rest does

swift crag
#

if you mean when you pass a rotation to Instantiate, then no

#

Instantiate always returns whatever the type of its first argument is

vernal minnow
#

`float worldHeight = Camera.main.orthographicSize * 2.0F;
float worldWidth = worldHeight * Camera.main.aspect;
Vector2 position;
position.x = Random.value * worldWidth - worldWidth / 2.0F;
Debug.Log("Laser 1 Fired Successfully");
GameObject laser = (GameObject)Instantiate(CirclePrefab, firePoint.position , itGuy.rotation );
Rigidbody2D rb = laser.GetComponent<Rigidbody2D>();
rb.velocity = transform.right * laserSpeed;
StartCoroutine(scheduleDestroy(5.0F, laser));
IEnumerator scheduleDestroy(float delay, GameObject target)
{
yield return new WaitForSeconds(delay);

                Destroy(target);
            }`
#

heres the full thing

#

lotta extra stuff that i didnt fix tho...

ivory bobcat
swift crag
#

which reads out the rotation of the Transform named itGuy

#

regardless, the cast is not necessary: the method will return a GameObject if you give it a GameObject

vernal minnow
#

ah

swift crag
#

The cast might have been necessary in Unity's ancient past

vernal minnow
#

its a tag check mb

swift crag
#

maybe before they included the generic Instantiate method

#

in that case, it would've always returned UnityEngine.Object

north kiln
swift crag
#

Safari's bold font is AGGRESSIVE

#

it looks so thin in Chrome

vernal minnow
#

its for collisions maybe? if not then ya are right about it being unneccesary

swift crag
#

you would not cast to GameObject in a collision method either

vernal minnow
#

not even comparing gameboject tags?

deft siren
#

the audio is set to be hearable up to the circle but i hear it max volume all the way in the house

north kiln
swift crag
#

you'd just get the game object of the collider or rigidbody you hit directly

swift crag
north kiln
#

Rarely do you have to cast something

swift crag
#

Casting is necessary when you have a less-specific type than you want. This often indicates you're doing something wrong.

vernal minnow
#

ig im just using non necessary stuff...

swift crag
#

You should do things for strong reasons, not just because you saw it once!

vernal minnow
#

thats honestly a bad habit im guessing

swift crag
#

Yes. It leads to code that implies things that aren't true, which makes it hard to reason about your code

#

GameObject foo = (GameObject) Instantiate(something); implies that something is not a GameObject

#

and there aren't many other valid types for something in that case

#

pretty much just UnityEngine.Object

vernal minnow
#

carp, i still broke it lol

#

GameObject shot = (GameObject)Instantiate(shot, transform.position, Quaternion.identity);

swift crag
#

You already have a variable called shot

near wadi
ivory bobcat
#

Why the cast?

near wadi
#

i thought i was the only one who said carp

swift crag
#

Now, it's not an error to declare a local variable with the same name as a field

#

But this does shadow the field

#

shot no longer refers to the field

vernal minnow
#

still giving the same error, do i need to directly add a prefab variable to the script?

swift crag
#

So you're trying to pass shot, the local variable, to Instantiate

vernal minnow
#

so im still killing the prefab...

vernal minnow
swift crag
#

what did you change it to?

vernal minnow
#

im still coroutining the shot...

swift crag
#

Answer my question, please

#

I can't help you if you go running off doing random stuff

vernal minnow
#

`if(timeBetweenShots <= 0)
{
//GameObject laser = (GameObject)Instantiate(CirclePrefab, firePoint.position /+ new Vector3(0.0f, 0.0f, 0)/, itGuy.rotation /Quaternion.identity/);
GameObject bullet = (GameObject)Instantiate(shot, transform.position, Quaternion.identity);
timeBetweenShots = startTimeBetweenShots;
StartCoroutine(scheduleDestroy(2.0F, bullet));
IEnumerator scheduleDestroy(float delay, GameObject target)
{
yield return new WaitForSeconds(delay);

            Destroy(target);
        }
    }`
#

fixed it

#

and youwere right

swift crag
#

This looks fine, save for the pointless (GameObject) cast that you can just get rid of.

vernal minnow
vernal minnow
swift crag
#

Of course not, as long as the type of shot is GameObject

vernal minnow
#

bullet = Instantiate(shot, transform.position, Quaternion.identity);

#

so like that?

swift crag
#

You still need to declare bullet

#

GameObject bullet = Instantiate(...)

vernal minnow
#

GameObject bullet = Instantiate(shot, transform.position, Quaternion.identity);

#

ill try it, now im curious why i ever was casting it to start with?

#

my 3rd project and ive done it on all 3

buoyant knot
#

but hear me out.
(int) (short) (long) (uint) (int) enumState

vernal minnow
#

whats uint?

buoyant knot
#

unsigned int

vernal minnow
#

and enumstate

buoyant knot
#

32 bits of unadulterated INTEGER

vernal minnow
swift crag
#

do not worry about it.

#

you will know if you actually need an unsigned integer

buoyant knot
#

an enum is an integer, with special named values

swift crag
#

enumState is a variable name

vernal minnow
buoyant knot
#

uint is really useful when you want to do bitmath, but negative numbers are confusing

swift crag
#

I presume it's an enum type.

vernal minnow
#

mb

swift crag
#

an enum lets you declare a new type with a fixed set of values

#
public enum Color {
  Red,
  Green,
  Blue
}
#

internally, an enum is just an integer

#

in this case, Red=0, Green=1, Blue=2

#

Enums show up fairly often in Unity. They're used wherever there's a small set of options.

vernal minnow
swift crag
#

No.

#

Color.Red, Color.Green, and Color.Blue are the three values of the Color enum.

buoyant knot
#

uint just lets you handle the actual 32 bits without messing with negative numbers flipping bits and all that crap

swift crag
#
Color myColor = Color.green;
vernal minnow
#

oh...

buoyant knot
#

don’t name your enum Color. That is confusing

swift crag
#

it collides with Unity's Color, yes

#

it was a simple example

buoyant knot
#

public enum Cardinal { Up = 1, Right = 2, Down = 4, Left = 8}
This defines an enumeration type called Cardinal

swift crag
#

now you're naming enums after birds!

vernal minnow
#

im both confused and intrigued

#

cardinal directions

#

oh

#

that was a joke...

buoyant knot
#

let’s say i have Cardinal direction. This represents a direction, but in code, it is actually just an integer

vernal minnow
#

oki, now i have a stupid unrelated question

buoyant knot
#

but now I can do things like check direction == Cardinal.Up; instead of direction == 1, which makes no sense when you look at it

#

enum types are just integers with predefined values specific to that enum type

vernal minnow
#

when running build, how do i force the build to specific screen size/resolution

#

my build makes the game look funny bc the resolution is way off

buoyant knot
#

been a long time, but I would check Project settings

vernal minnow
#

yeah... i tried that, and the internets unity looks different from mine

#

kinda triggering tbh

#

the how too looked easy and mine didnt even have the same settings

#

@swift crag thx man, ya fixed my broken enemy issue

near wadi
#

can't reference a prefab in a prefab because.. FU that's why
EDIT: In the end, this was due to user error, and does actually work as one would expect

#

I have a simple overhead healthbar HUD Canvas thing that is a prefab. good luck getting it working on multiple enemy prefabs without jumping through so many hoops it would make an acrobat nauseous

shell sorrel
#

prefabs can reference other prefabs and assets just fine

#

they just cant reference scene objects for obvious reasons

vernal minnow
#

Do the enemies need an overhead healthbar?

#

Or is it a player health bar?

shell sorrel
#

also there are many ways to make references, if enemies need health bars for example, just have them notify a system in your UI and pass a self reference

near wadi
#

enemy health bar

dusty coral
#

@north kiln i removed the parenthesis, i dont get the error anymore but the debug.log is not being triggered

near wadi
#

the issue is not adjusting the value of the Health Bar, it is getting it to recognize the health bar to begin with. it is a nested prefab. Best method i have found so far is FIndGameObjectWithTag. dilemma being, i assumed that since it was on the same object, finding each other would be a simple GetComponent, but it seems that is not the case with nested prefabs

north kiln
dusty coral
#

oh 😅

#

its good now

near wadi
#

Here is an example of what i am having issue with. i am sure there is a simple way around it, i just do not know it.

using UnityEngine;
using UnityEngine.UI;

public class HungryAnimal : MonoBehaviour
{
    void Start()
    {
        Canvas WhyYouNoWork = GetComponent<Canvas>();
        if ( WhyYouNoWork != null ) { Debug.Log("Found"); }
    }
}
#

the Canvas is not found. this is after unpacking it, and also just flat out adding another Canvas as a test

teal viper
near wadi
teal viper
#

Then why should it find it?

near wadi
#

they are on the same object. why should it Not find it?

teal viper
#

GetComponent only gets components on the same object.

near wadi
#

ok, perhaps a misunderstanding. the Script and the Canvas are on the same Prefab

teal viper
#

Does the prefab root have a canvas component?

near wadi
#

i think so?

teal viper
#

Do you see it in the hierarchy inspector on the left side?

near wadi
#

in this screenshot, no. i do see it in the hierarchy labeled windows though

teal viper
#

Okay, lets make things clear: what is displayed in the hierarchy?

#

And what is displayed in the inspector?

near wadi
#

They are both in the image shared above.. what are we trying to get to here?

teal viper
#

What does the hierarchy show in general?

#

What does each element in it correspond to?

near wadi
#

sorry, i do not know what you mean.. the screenshot is of the hierarchy..

teal viper
#

I'm trying to figure out if you understand what a hierarchy is

north kiln
teal viper
#

Do you?

shell sorrel
#

we have not seen a screenshot that shows your canvas component yet

near wadi
#

is the hierarchy in the screenshot or not?

shell sorrel
#

GetComponent only looks on the gameobject its called on and no further

teal viper
shell sorrel
#

so will only find components on the exact same gameobject

near wadi
#

is a prefab a gameobject?

north kiln
#

It's made up of gameobjects.

shell sorrel
#

its made of one or many gameobjects

near wadi
#

ok, that is helpful

teal viper
# near wadi ok, that is helpful

A hierarchy always shows only gameObjects and their relationship. Inspector only ever shows components(aside from materials and custom inspectors) of the selected object.

#

If you don't see a component in the inspector GetComponent wouldn't find it either.

near wadi
#

Ok, so at this point, the way i am finding it is by Tag. it seemed to me that there should be a more direct route to 'find' it

teal viper
#

Prefab or not doesn't matter. Consider prefab edit mode as a small separate scene. It doesn't change how components and gameObjects work.

north kiln
#

A serialized reference would be direct

near wadi
#

Ok, therein lies the problem, i cannot seem to serialize a reference to something in the same prefab

north kiln
#

You can do that just fine

shell sorrel
#

you can do that just fine, a prefab can have references to stuff inside of its self and assets including other prefabs

#

only restriction is scene objects

near wadi
#

When i attempt to Drag the the thing titled Canvas, which is of Type Canvas from the Prefab (shared prefab), to the serialized reference spot, i get just a red circle with a line

shell sorrel
#

take bigger screen shot that shows the object you are trying to drag in as well

#

it sounds like it is either not a canvas or its a scene object and not part of the prefab

near wadi
north kiln
#

Can you show the canvas' inspector?

near wadi
#

so at this moment, i find by Tag, then assign the Camera on Start

north kiln
#

You should be able to drag that object into that reference just fine, if it's not allowing you then that's very strange. Are you looking at that inspector with the root of the prefab selected from the hierarchy window? Or did you have it selected from the project

near wadi
#

this is the main prefab that i double clicked in the Project

north kiln
#

Perhaps select the root via the hierarchy and see if you can drag and drop then

near wadi
#

Yes! Thank you

#

By having this 'active/highlighted' i was able to drag the Canvas to the Serialized Field

#

i am not 100% sure how i screwed it up, but i am sure it was user error

#

Thanks again everyone

shell sorrel
#

You likely did not have it opened in the prefab editor and were trying to drag in a canvas from your scene not the one in the prefab

near wadi
#

i think you are right. I must have been flip flopping between double clicked open, and single click selected, and not realizing it

#

Oh, no.. there is none in the Scene. pretty sure it was the half open, click vs double click thing

#

I can reproduce it now. when in this single clicked state, i cannot drag to it

#

but when in this double clicked state, i can

#

Yet, both show it available, and indentical Inspector (for most parts)

#

Obvious now, but in my frustration i did not realize i was alternating between fully open and not.

abstract hedge
#

i cant fix my sliding issue

#

still

nimble apex
#
public class SocketIndicator : MonoBehaviour
{
  public enum Status { Idle, On, Disconnect, Emit }

  [SerializeField] private Text indicator;
  [SerializeField] private int statusResetDuration;

  public void OnStatusChange(Status status)
  {
    StopCoroutine(ResetStatus());

    switch (status)
    {
      case Status.Idle:
        indicator.text = "I";
        break;
      case Status.On:// 3 seconds reset to idle
        indicator.text = "R";
        StartCoroutine(ResetStatus());
        break;
      case Status.Emit:// 3 seconds reset to idle
        indicator.text = "E";
        StartCoroutine(ResetStatus());
        break;
      case Status.Disconnect:
        indicator.text = "D";
        break;
      default:
        indicator.text = "N/A";
        break;
    }
  }

  public void OnStatusChange_Reconnect(int attempt)
  {
    indicator.text = attempt.ToString();
  }

  private IEnumerator ResetStatus()
  {
    yield return new WaitForSeconds(statusResetDuration);
    indicator.text = "I";
  }
}```

is it optimized enough?
#

we planned to make an indicator UI that told users and beta tester the websocket status
as you see in the code, when websocket event is called, they will call this script as well

abstract hedge
#

can someone help me, i still cant figure my movement controller out

near wadi
#

so, to double verify, like the GetComponent, there is no GetObjectOfTypeAndName in this prefab?, it would always be a Find scenario? When not serializing, i mean

near wadi
near wadi
#

ok, that shows the final issue, but not anything about your actual controller

abstract hedge
#

idk what is is though

near wadi
#

Did you write code to make a controller, or are you using a third party controller code?

abstract hedge
#

im using one from a video

near wadi
#

So, you would need to share the code

abstract hedge
#

/code

near wadi
#

!code

eternal falconBOT
abstract hedge
#

thanks

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

public class PlayerMovement : MonoBehaviour
{
    private CharacterController controller;

    public float speed = 12f;
    public float gravity = -9.81f * 2;
    public float jumpHeight = 3f;

    public Transform groundCheck;
    public float groundDistance = 0.4f;
    public LayerMask groundMask;

    Vector3 velocity;

    bool isGrounded;
    bool isMoving;

    private Vector3 lastPosition = new Vector3(0f,0f,0f);

    
    void Start()
    {
        controller = GetComponent<CharacterController>();
    }

    
    void Update()
    {
        
        isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);

        if (isGrounded && velocity.y < 0)
        {
            velocity.y = -2f;
        }



        float x = Input.GetAxisRaw("Horizontal");
        float z = Input.GetAxisRaw("Vertical");


        Vector3 move = transform.right * x + transform.forward * z;



        controller.Move(move * speed * Time.deltaTime);

        if (Input.GetButtonDown("Jump") && isGrounded)
        {

            velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
        }


        velocity.y += gravity * Time.deltaTime;


        controller.Move(velocity * Time.deltaTime);

        if (lastPosition != gameObject.transform.position && isGrounded == true)
        {
            isMoving = true;

        }
        else
        {
            isMoving = false;

        }

        lastPosition = gameObject.transform.position;
    }
}
teal viper
# abstract hedge this

Can you maybe start the game paused, switch to the scene view and take a screenshot from the bird's eye view?

abstract hedge
#

alr

near wadi
#

Also, when that happens, are you holding down a key, or does it just kamikaze off the side on its own?

abstract hedge
#

yea

#

it just kamikazes

teal viper
#

Also if you could record a video of the issue with your mouse rotation disabled, it would be helpful.

near wadi
#

you perhaps have a joystick or a space mouse attached to your computer?

abstract hedge
#

no, i only have mouse and keyboard

near wadi
#

ok

abstract hedge
#

i just had to go back to a save, i bluescreened

deft siren
#

how do i keep edits i make while playing?

teal viper
# abstract hedge

I really think that the issue could be related to your mouse rotation code. Could you disable the component and record a video of the issue again?

abstract hedge
#

yes

teal viper
#

Mp4 please?

abstract hedge
#

gotu

teal viper
deft siren
abstract hedge
#

@teal viper

deft siren
#

hey so my Ai script was working just fine for some time but now it wont detect the player

#

it was not facing the right direction so to solve it i placed the scripts into a parent in the parent (but i dont think that could be affecting in any way)

#

heres how it looks (mazeDog: scripts + mesh, dog: animations and objects)

#

and heres the script

abstract hedge
teal viper
# abstract hedge

Okay. Can you make the input variables public or serialized fields so that we can see them in the inspector and record a video just like the one you made again?

abstract hedge
#

yea, 1 second

teal viper
abstract hedge
teal viper
teal viper
abstract hedge
#

alr

teal viper
#

Yes. Now record a video like before.

abstract hedge
#

alr 1 min, i have to throw some stuff away il be back

queen adder
#

Can you lend me the code? It helps me a lot for other things? blushie

teal viper
#

Don't take code from strangers. They might kidnap you and sell your kidneys.

rocky canyon
sonic dome
#

what other way should i do this?

abstract hedge
#

wait mp4

sonic dome
#
using UnityEngine;

public class Movement : MonoBehaviour
{
    private Rigidbody rb;
    [SerializeField]
    private float speed;
    private Vector3 direction;
    private Animator anim;

    void Start()
    {
        rb = GetComponent<Rigidbody>();
        anim = GetComponent<Animator>();
    }


    void OnMove(InputValue value)
    {
        direction = value.Get<Vector3>();
    }

    void Update()
    {
        Motion();
        if(rb.velocity.x > 0)
        {
            anim.SetBool("Walk", true);
        }
        else if(rb.velocity.x == 0)
        {
            anim.SetBool("Walk", false);
        }
    }

    void Motion()
    {
        rb.velocity = direction * speed * Time.deltaTime;
    }
}

can anyone tell why my player is going homelander mode and just flying without me pressing anything value of speed is 1000

teal viper
# abstract hedge

From this video your input is pressed all the way until the end of the video.

abstract hedge
#

so the game thinks im clicking/ pushing something

teal viper
#

It thinks you're holding the movement keys

abstract hedge
#

how would i fix that?

sonic dome
teal viper
abstract hedge
#

no im not touching my keyboard

teal viper
small mantle
#

I still don't understand how this code works. How can I visualize this? ```cs
Vector2 direction = new Vector2(mousePos.x - playerPos.position.x, mousePos.y - playerPos.transform.position.y);

abstract hedge
#

after i hit play no

teal viper
abstract hedge
#

ok

#

these?

teal viper
abstract hedge
#

idk, i have never touched these settings

#

1 sec letme move my mouse out of the ss

teal viper
#

And the other one's?

abstract hedge
#

its just so that you can see the setting that was coverd in horizontal

teal viper
#

You have 2 Horizontal and Vertical. Take a screenshot of the other ones too

abstract hedge
#

oh

teal viper
#

Remove these

abstract hedge
#

ok

teal viper
#

Or even just reset the whole input manager.

abstract hedge
#

it was there when i reset the input manager

teal viper
#

Click the 3 dots at the top right and select reset or clear.

abstract hedge
#

it only says reset

teal viper
#

Okay. Then maybe it's not related. Try removing them manually or changing the name.

#

Also, do you have a joystick connected?

abstract hedge
#

i just deleted them

abstract hedge
teal viper
#

Does that fix the issue?

abstract hedge
#

idk il check

#

EYS
"

#

YES

small mantle
#

I'm having an issue with the player skipping frames when moving. I know its because its rotation, how can I solve this? ```cs
// Inside the Update Method

// This is the mouseCusor Code....
Vector2 direction = new Vector2(mouseCursorPosition.x - playerPosition.position.x, mouseCursorPosition.y - playerPosition.transform.position.y);

    playerPosition.transform.up = direction;

// This is the Movement Code....
if (moveVector != Vector2.zero) {
rb.MovePosition(rb.position + moveVector.normalized * moveSpeed * multiplier * Time.fixedDeltaTime);
}

teal viper
#

And it provides input.

abstract hedge
#

i figured it out

#

it was a usb stick

teal viper
#

A USB stick..?🤔

abstract hedge
#

yea, i unplugged it and it worked

teal viper
#

Like a memory USB?

abstract hedge
#

yea

teal viper
#

Lol okay

abstract hedge
#

idk how it works but idc it worked

sonic dome
#

Is there a way to get the magnitude of vectors?

north kiln
#

!docs

eternal falconBOT
odd mason
#

hey so im trying to use my animation triggers but whenever i do set them off my project freezes, cant find a way where it wont do this

keen dew
#

This code doesn't cause it. Post the entire script

#

!code

eternal falconBOT
odd mason
#

?*

keen dew
#

no

#

read the bot message

odd mason
#

oh k my bad

#

alright did it

keen dew
#

There's nothing there that should cause the editor to freeze

#

Do you mean that the editor freezes and you have to force quit it?

odd mason
#

no just that the game preview freezes, sorry about the poor wording choice

#

i thought this would work for animation control but yeah it just always freezes, been lost only problem ive had, the triggers work when i set them with the editor so i dont think its the animations causing the freezing, im pretty sure theyre running over and over but i thought this wouldn't cause that, unsure what to do

keen dew
#

Do the animations play at all?

odd mason
#

not sure since it just freezes

#

lemme check if hte triggers even activate though

#

ummm i got my editor stuck fullscreen on one editor window, know how to fix this?, cant check the triggers cause of it

#

i did before but i cannot find it again forgot how lol

oblique ginkgo
odd mason
#

thank you so much

#

yeah it jsut makes the game freeze, the triggers dont even get a chance to run

#

the idle state bar is just stuck

craggy lava
#

Why is my INT not default assigned to 0

int point;

if (point == 0)
{
      // CODE HERE     
}
Use of unassigned local variable 'point'
#

the int should by default be 0

gaunt ice
#

This is stack variable

craggy lava
gaunt ice
#

It doesnt have default value
Memory in stack

teal viper
#

In C# you have to initialize your vatiables

#

Unless they're class members

craggy lava
#

oh ok

oblique ginkgo
#

You don't have to initialize ref types if they're serialized in unity, though

teal viper
odd mason
crisp gate
#

for some reason when i use Kinetic rigidbody, it doesnt detect collision, but dynamic does?

#

i dont want dynamic cuz the bullets just send the enemies flying

brisk escarp
#

umm im falling through the floor and sticking to the otherside of the floor... and the vs code not showing any error also there are no errors showing on unity any one have a clue to this issue?

crude prawn
#

i had a programming exam and my teacher said that a would equal to b is this true?

lean basin
#

I have a Vector3 that represent movement of a player without considering direction.
How do I manipulate the vector to make the value facing on transform.forward?

I usually multiply the vector to transform.forward, and transform.right then sum them up. I wonder if there are more elegant solution.

Vector3 velocity = someVelocity();
Vector3 forwardMovement = velocity*transform.forward;
Vector3 sideMovement = velocity*transform.right;
Vector3 newVelocity = forwardMovement+sideMovement;
crude prawn
rare basin
#

how

#

basic c# concept

#

you can google in 2minutes

#

or less

crude prawn
#

i will try

rare basin
#

or just try it yourself

#

and print the value 🤔

crude prawn
#

i did but it gives me an error

rare basin
#

did you read the error?

crude prawn
#

cannot convert int to bool i know

rare basin
#

yup

#

you cannot assign values

#

inside if brackets

#

= is assignment sign

raw yoke
#

you must use == in order to compare two values

crude prawn
#

in the answers i typed "The compiler would have gave you an error because you cant assign values inside the parameters in a "if" statement. Variabel a wouldnt have touched and would have remained at 1.

rare basin
crude prawn
#

This is exactly what i typed

raw yoke
crude prawn
#

i know right

rare basin
#

better answer would be

crude prawn
#

i got wrong

rare basin
#

that the code wouldn't compile

crude prawn
#

yeah its translated so its bad english

rare basin
#

if it was

a = b;
if (a==b)
{
//code
}
#

then it would be true, and a will be 2

#

but you cannot do

if(a=b)
crude prawn
#

yes i do know that but i got a wrong answer how do i convince my teacher to give me a point for that

teal viper
#

Actually you can make assignments in the condition. It's legal. At least under certain circumstances.

rare basin
crude prawn
#

Yeah and i still got a wrong answer so i dont know

crude prawn
#

but that a wouldnt equal 1

rare basin
#

it will be equal to 1

#

because the code wont even compile

#

and wont run

#

so it wont change to anything

#

infact a wont even exist

#

because... the program didin't run and compile

crude prawn
#

yeah xd

rare basin
#

a wont ever be declared

crude prawn
#

yeah thats the thing so im not sure why he said a would equal to b

rare basin
#

what is the correct answer your teacher said?

crude prawn
#

a = b

rare basin
#

🤔

#

10seconds in google

#

literalyl copy paste this message

rare basin
#

and that the code wont even compile

nimble apex
rare basin
#

so a wouldnt be created

#

so a doesnt have any value

#

because it doesnt exist

crude prawn
#

ill tell him this thank you

teal viper
crude prawn
rare basin
#

do you have the question?

#

maybe you misunderstood it

#

but you said "the teacher put this error on purpose"?

#

why would he do that?

crude prawn
#

ig to test us

rare basin
#

so you spotted the error

crude prawn
#

i didnt misunderstood it the whole class got the same answer

rare basin
#

and he knows that this code is wrong and wont compile

crude prawn
#

yes

rare basin
#

so why does he say that the correct answer is a=b

#

tell him to explain

crude prawn
#

haha i have no idea ill ask him

#

and ill update you

nimble apex
#

unity has no dll in project file?

#

i need the assembly definition of default assembly

rare basin
#

i believe the default one isn't in the project files

true heart
#

i made a tilemap for the background in my game, it had the grass tiles stone and so on. i was wondering is it possible to make another tile map to add rocks and stumps while still showing the other background behind it. as when i tried it looked liek this

timber tide
#

if(a=b) is actually legit syntax in c++ to check assignment

#

c# it's a compiler error

nimble apex
#

the problem is i need to modify a script inside a plugin, that plugin has its own assembly/library , so all the scripts including that one is enclosed inside the library

from that script, i cant reference all my other managers because theyre all in default assembly, they dont have one

#

but, you cannot pull that one out from the plugin, so many other scripts are depending on that script

#

its sad scripts that dont have assembly can just reference other one by doing "using xxx;"
but theres no "using default;"

timber tide
rare basin
#

atleast from what i understand

rare basin
true heart
#

i was hoping to use a tile map for both as it woudl make it much easier for me to edit as i coudl just add decorations ontop using the tile thign instead of having to place images is there really no way of makign teh rocks have a transparent background around it to show teh bottom layer?

rare basin
#

its a common mistake

timber tide
#

yeah, I actually remember seeing a question like that going from java to c++ because it's also a compiler error in java haha

rare basin
#

In C++, the expression if(a=b) is a valid assignment statement

teal viper
rare basin
#

yes

#

and it will always evaluate to true

#

if a=2, and b=4

#

if(a=b) will return true in c++

#

because this is just a normal assignment

#

it's essentially checking if the assignment operation was successful, not if the numbers are matching

earnest tendon
#

ok so im trying to change the scene in my game after a ceirtain time limit, i got it set to 30 seconds rn so i can test it, but for some reason when it loads the next scene it doesnt load anything like i need it to load, i cant move the player and no ui elements update

ivory bobcat
earnest tendon
#

no it doesnt seem to be that

#

i could try something

#

but it wouldnt really fix the issue

#

rn the way i got it set up you gotta go through a character select screen in order to enter the level

ivory bobcat
#

There isn't enough information.

earnest tendon
#

theres not alot of info i can give, i got no idea whats going on, all ik is that the way i got my game set up you gotta go through a character select screen in order to play the game but if i boot up the game from the game scene itself without going through the character select screen then the issue im having occurs, where i cant move the player and the UI doesnt update to show the current stats

ivory bobcat
#

Well, this is a coding channel so we're assuming you'd have some kind of code to be viewed.

earnest tendon
#
if (stopwatchTime >= timeLimit)
        {
            SceneManager.LoadScene("Next Level");
        }

this is the code i got rn that changes the current scene

#

ive tried difrent methods to load the next level but none work

ivory bobcat
#

if i boot up the game from the game scene itself without going through the character select screen
Meaning, you've got some dependency with the character selection screen. Maybe persistent data that's only generated in the character selection screen.

ivory bobcat
earnest tendon
#

theres nothing that gets added in the character select screen, it just has the buttons that send you to the next scene with all the needed dependencies to controll the character or obtain items

ivory bobcat
earnest tendon
#

the only thing that happens is that the buttons are what allows the player to move

#

but if i do the same for the other levels then the player would just reset to the base stats

rare basin
#

causing to load the same scene every frame might cause some issues

ivory bobcat
rare basin
#

might need some kind of secure on that, like a bool isLoaded

ivory bobcat
rare basin
ivory bobcat
#

Probably something along the lines of...

  • Title -> Character Selection -> Play (works)
  • Title -> Play (don't work - missing persistent data/configurations from Character Selection)
  • Play (don't work- missing persistent data/configurations from Character Selection)
    etc
earnest tendon
rare basin
#

put debug logs in there

ivory bobcat
#

Where the solution would be to decouple the dependent data from Character Selection and have an intermediary

  • Title -> Character Selection -> Setup -> Play
  • Title -> Setup -> Play
  • Setup -> Play
    Where all of the above would Play after loading the setups.
rare basin
#

and show the console

#

when you load the scene

ivory bobcat
#

Is that what's missing if you don't load the character selection screen first?

earnest tendon
#

yes thats what missing

#

but if i just load it like i do there it resets the character back to 0

ivory bobcat
#

Sounds like it UnityChanThink

the issue im having occurs, where i cant move the player and the UI doesnt update to show the current stats

foggy magnet
#

Hi, I'm trying to use the c# tripple quoted strings ( so I can use newlines in the string literal ) , like string str = """ .... """;

It just isn't working though, Visual Studio doesn't recognise it as a multiline string, and neither does Unity as the console thinks I need newlines etc..

Is this kind of """ string supported in unity c# ?

fossil drum
foggy magnet
#

Thanks for the link. That's not for the """ string though, that's the one that begins with @ by thelooks of it.

The """ string allows you to have newlines also. But I'm wondering if it is a later version of c# than Unity suppots maybe?

fossil drum
#

Hmm, then I don't understand the difference between 1 string with newlines and @ or $ in it, and your version with newlines. Never used that style outside of Python.

keen dew
#

String literals with triple quotes is a C# 11 feature, Unity uses C# 9

foggy magnet
#

Aha brill, thanks, ok I can stop tying that now 🙂

Actually, it makes me do things properly anyway, I was trying to just use a JSON string I was pasting in, but I'll do it properly with JSON Serialization instead now.

foggy magnet
keen dew
#

@-strings can also have newlines but I'm not sure if that's also an addition to later versions

fossil drum
north kiln
#

Raw string literals are C# 11

#

Unity is C# ~9

north kiln
#

comparing the pair

fossil drum
#

Thanks, that explains the difference then.

foggy magnet
#

waaa, strange day today, now I just pressed a weird key combination in Visual Studio Community and all my code has gone a funny colour.

Has anyone seen this before? I'm not sure what I pressed or what it means. It is just this one cs file, and I've quite Visual Studio and reopned it and this file still has this weird colouring?

I must have turned on some mode, but I've never seen it before.

kindred halo
keen dew
#

Put the log outside the if block

vale bloom
#

hi, is anybody know how to debug / attach android from visual studio code in macos ?

rare basin
#

did you try google?

vale bloom
#

yes, i cant find any

#

I can debug Unity Editor, but not the android. i cant find anything on google

languid spire
#

you dont attach VS to your device you attach it in Unity in the build settings

stuck palm
#

How could you do a dash with the character controller? Cus you can't just add an impulse force like a rigidbody

frosty hound
#

The CC requires you manage your own velocity. Add a dash velocity to your movement that slows down to zero over a small amount of time.

stuck palm
#

Oh yeahh

#

Like move velocity+ dash velocity

frosty hound
#

Yep

stuck palm
#

I was thinking of just changing move velocity

#

Thanks thats a lot easier

#

Would I use a coroutine for making the dash velocity go to zero?

frosty hound
#

Sure you can override the movement instead. Up to you really.

#

Lots of people would use coroutines for that, yeah. I personally would not. Again, up to you in the end.

stuck palm
#

Idk what the word is

frosty hound
#

Update

stuck palm
#

Decreasing a value over time

#

Oh yeah I guess that could work

frosty hound
#

It's how I do it here. This is super old though, but only gif I could find.

vale bloom
languid spire
vale bloom
#

I was able to run the app Ok in android,
what i need is debug the app, and setup breakpoint etc

languid spire
#

Ah, then I suspect you would need Android Studio for that

sonic dome
jaunty heath
sonic dome
#

so roation works with the OnMove direction

jaunty heath
sonic dome
#

so should i use somthing like vector3.forward

jaunty heath
#

(also i would not set velocity of a rigiybody directly, but rather use things like AddForce but thats another story)

ivory bobcat
sonic dome
jaunty heath
jaunty heath
ivory bobcat
sonic dome
#

yes i did

#

time for the test

sonic dome
#

no wait

#

my bad

#

let me try one thing

#

naw

#

this looks so bugged

#

maybe cuz i m chaning the transform and rb.velocity at the same time

#

still isnt working

ivory bobcat
#

transform.rotation = orientation.rotation;

sonic dome
#

how will this help?

ivory bobcat
sonic dome
#

but then the character wont rotate

#

it will be just the camera

ivory bobcat
sonic dome
#

like i showed no error

#

but still doesnt move in the direction i want

ivory bobcat
#

Just set the forward direction to the velocity vector...

sonic dome
sonic dome
#

what?

ivory bobcat
#

What did you not understand?

sonic dome
lavish gate
sonic dome
ivory bobcat
#

I want you to set the forward direction to the velocity vector if it's magnitude wasn't zero. I want you to remove the rotation assignment at the end of the function.

lavish gate
sonic dome
#

like this?

ivory bobcat
sonic dome
sonic dome
lavish gate
#

value.Get<Vector3>(); i have never seen this syntax in my life

ivory bobcat
#

Define not working. (you'd want to tell folks what is happening instead)

sonic dome
ivory bobcat
lavish gate
#

okay i see

sonic dome
ivory bobcat
#

I thought you were wanting to look in the direction you're moving...

sonic dome
lavish gate
#

Mhm

ivory bobcat
sonic dome
#

let me try

ivory bobcat
#

Relative to your direction field

lavish gate
#

Dalphat have you used unity events much

ivory bobcat
#

Make sure to revert to your original setup - remove the changes done.

frank flare
#

When I add Rigidbody to Cube (5) it falls under the ground. How do I make it stay?

ivory bobcat
lavish gate
sonic dome
#

the player is rotating

#

but the movement is still the same

lavish gate
frank flare
# lavish gate Does the floor have a collider?

I can walk on the floor and when there is no Rigidbody exactly on childs of Bottle nothing falls down. Bottle also has a Rigidbody, so I don't think it has to do anything with the floor

lavish gate
#

Oh sorry i read the question wrong

ivory bobcat
lavish gate
ivory bobcat
#

Assuming this script is on the camera or in the same orientation as the camera

lavish gate
#

Why do you need rigidbody on the bottle?

frank flare
lavish gate
#

Why not just have a singular rigidbody?

rare basin
sonic dome
frank flare
lavish gate
#

bobber?

frank flare
#

it should have some challenge on flopping the bottle, but not like when the flop is 100% accurate that the bottle will go down at the good rotation

rare basin
frank flare
ivory bobcat
lavish gate
#

id reckon just add one rigidbody to the main object and have a few box colliders attached to the bottle

lavish gate
#

You can have multiple box colliders

frank flare
frank flare
ivory bobcat
ivory bobcat
#

You may want to use the other overload
public Vector3 InverseTransformDirection(float x, float y, float z);
Setting the x equal to your x direction and z equal to your y direction

lavish gate
sonic dome
ivory bobcat
sonic dome
#

direction = Transform.InverseTransformDirection(value.Get<Vector3>().x,value.Get<Vector3>().z,value.Get<Vector3>().y); ?

ivory bobcat
#

I don't want to advise you to write code you aren't sure of, so I'll probably stop after this..cs var input = value.Get<Vector3>(); direction = transform.InverseTransformDirection(input.x, 0f, input.y);Edited

sonic dome
#

see it works but

frank flare
sonic dome
# sonic dome see it works but

cuz once i choose a direction i have to stop and look into another one to go in that direaction it does not chage if i m in motion

#

proly cuz its in OnMove

#

i just want a way to put it in update

ivory bobcat
#

Maybe just apply the changes to the result before assigning to velocity in Motion

sonic dome
frank flare
ivory bobcat
sonic dome
kind bramble
#

What is the diffrent between 3d and 3d URP

sonic dome
#

direction vector?

rare basin
#

he wont make the code for you

#

everytime

#

he showed you all the functions and approaches you can take

#

think of it yourself, then ask a specific question

sonic dome
#

okk

#

i did

rare basin
sonic dome
# sonic dome i did

var result = direction;
rb.velocity = transform.InverseTransformDirection(result.x, 0f, result.y);

#

but now the

#

player wont move forward

rare basin
#

do you understand how InverseTransformDirection works

#

or you just blindly copy&pasted it

#

from the code he sent

sonic dome
#

right?

rare basin
#

you ask me?

sonic dome
#

no thats what i think it does

rare basin
#

you need to know it, not think it does that

#

dont work with code you dont understand

sonic dome
rare basin
#

you will understand it even better if you do it yourself instead of someone else making it for you

sonic dome
#

i am not asking him to code anything for me

rich adder
#

please stop using pastebin, it sucks ass @sonic dome

#

use one of the sites !code

eternal falconBOT
languid spire
rich adder
#

You keep AddForce in update , what do you expect to happen

#

esp with impulse

sonic dome
#

so whats the proper way to do it?

sonic dome
rich adder
#

what are you trying to achieve

sonic dome
#

well tbh this new input system wasnt working out for me so i just went back to basics and now everything works

rich adder
#

the input has no relelation to this, you changed how you call the movement

#

velocity is a fixed value instead of AddForce, which...keeps adding force duh

frank flare
sonic dome
#

ya but there were some complications like OnMove would only take the 1st input and not change my direction mid motion

rare basin
#

thats not related

sonic dome
frank flare
#

I'm trying something, how do I make an object change local position to another local position?

sonic dome
sonic dome
rich adder
#

also u should not use GetInput in fixed update

rich adder
#

because it could miss the initial keydown and only "catchup" on the next physics loop

#

not noticeable with GetKey as much as GetKeyDown but you still have slight delays

sonic dome
#

so i should do all that in update and then do the motion in fixed update?

rich adder
#

yes

#

store ur inputs in a v2

sonic dome
#

okk

rich adder
#

huh as for slipping, it shouldnt with velocity

#

are you sure the script was applied from old?

sonic dome
rich adder
#

for .velocity

#
 void Update()
    {
        movement.x = Input.GetAxis("Horizontal");
        movement.y = Input.GetAxis("Vertical");
        LookRot();
    }
    Vector2 movement;
    void FixedUpdate()
    {
        if (movement != Vector2.zero)
        {
            rb.velocity = movement.y * speed * transform.forward;
        }
    }```
radiant sail
sonic dome
#

will it slow the velocity as well?

rich adder
sonic dome
#

tysm

rich adder
# sonic dome tysm

btw keep in mind .velocity will override any external forces, including gravity

#

so it "Falls slow"

#

or if at all

sonic dome
swift crag
#

One option is to split the current velocity into two parts

#
  • aligned with gravity
  • not aligned with gravity
#

you then only modify the second part

sonic dome
#

hows that done?

swift crag
#

using Vector3.Project and Vector3.ProjectOnPlane

#

Vector3.Project tells you how much of the first vector is aligned with the second vector

#
Vector3 gravityVelocity = Vector3.Project(rb.velocity, Vector3.down);
rare basin
swift crag
#

well, actually, what I just said is what the dot product is, whoops

#

I should say that Project gives you the part that's aligned

#

Vector3.ProjectOnPlane does the opposite. It gives you the part that's not aligned

#
Vector3 movementVelocity = Vector3.ProjectOnPlane(rb.velocity, Vector3.down);
rare basin
#

hmm i think i don't get it