#💻┃code-beginner

1 messages · Page 488 of 1

low wasp
#

@slender nymph @toxic cloak Thanks for the help. I was able to get it working. I was stumped for a bit. Then I realized I forgot to enable the renderer again.

pure stag
#

can anyone hop in a vc with me and help me learn this shit, in not learning anything from just coping the videos

deft grail
#

read the docs

#

and try to implement what you want

pure stag
pure stag
deft grail
steep rose
#

well not unfortunately haha

eternal needle
gaunt solstice
#

is there a way to do it where it just generates the points within the cone rather than generating a new point if it isnt in the cone

eternal needle
gaunt solstice
eternal needle
#

Just make sure it's a cone spread and not one which can be square, which I imagine some bad tutorials would end up doing

gaunt solstice
#

thank you

turbid jay
#

Hello, I was messing with animation the other day and I come back today and now my player doesn't move when I press the directional buttons

#

before it was giving me an error for the animator variable

#

Any idea what that could be?

sullen perch
#

I have code that spawns a lot of destinations for ai, but i need the destinations to stay when i hit stop, how do i make a script work when the gaME IS NOT BEING PLAYED

#

sorry for caps

ivory bobcat
rocky canyon
#

has to be an editor script to work not in playmode

#

or u can save it to a file like dalp said

sullen perch
#

how do i save the data to a scriptable object

ivory bobcat
#

https://docs.unity3d.com/Manual/class-ScriptableObject.html

When you use the Editor, you can save data to ScriptableObjects while editing and at run time because ScriptableObjects use the Editor namespace and Editor scripting. In a deployed build, however, you can’t use ScriptableObjects to save data, but you can use the saved data from the ScriptableObject Assets that you set up during development.

Data that you save from Editor Tools to ScriptableObjects as an asset is written to disk and is therefore persistent between sessions.

sullen perch
#

thx

gaunt solstice
tender stag
#

i need to make a script which scales the transform its on down to the target scale which is in a variable

#

but when i scale it the children positions change

#

so i need a reference object and track its original position

#

and then also move the transform so that even if i scale it its gonna be in the same position

#

i need this script to on the start of the game scale the transform on all axis to the "scale" variable, but also move the position of this transform so that the position of the referenceObject doesnt change

ivory bobcat
tender stag
#

like scale the object down

#

but keep all the childrens positions

#

so it doesnt look like it changed

ivory bobcat
#

So.. you don't want to scale it and all of it's children - relative to it.
You want to scale it and all of the other object independently.

tender stag
#

wait

#

im so confused

#

i dont even need a script

#

alright nvm

#

it works

sullen perch
teal viper
#

Also, you know you can dock the game tab/window right?

sullen perch
#

i dont know what you mean

teal viper
sullen perch
#

this is my ai inspecter and it was working before

teal viper
#

Why are there 0 components on the "wolf" object?

sullen perch
#

there is another one in the wolf that contains my logic and visuals

teal viper
#

Why is the logic not on the root object?

sullen perch
#

idk

#

should it be?

teal viper
#

Yes. You want it to move, right? If you're not gonna put the logic and the nav mesh agent on the root, it's not gonna move anywhere. The "wolf" object is basically unrelated to your wolf. It's just another empty object in the scene.

sullen perch
#

oh

#

ok

#

its still spawning under

teal viper
rocky canyon
#

fr we need deets

sullen perch
#

i think i might have solved it, i moved the terrain and didnt bake it againn, now the ai is frozen

rocky canyon
#

ya, b/c u didnt rebake it.. (the actual navmesh is probably no where near where the agent spawned)

sullen perch
#

Yeah but now its frozen and idk why

rocky canyon
rocky canyon
#

if the navmeshagent isnt standing on.. or close enough to a navmesh it doesn't work

#

you probably have an error in ur console saying something like that (that is if u have navmeshagent logic running)

rocky canyon
# rocky canyon

anyway.. this is how i normally spawn my units on uneven terrain

#

starting at 0 + offset higher than highest peak.. (so if ur highest peak was +100 units) i'd start my raycast at 110 units above 0.. and then raycast downards w/ a length longer than that. (so it will touch the terrain)

#

once it hits u have a position that is exactly at the terrain

#

(ofc i use a LayerMask so i can avoid tall buildings and trees and stuff, so its only detecting the ground)

sullen perch
#

i am so confused

sullen perch
#

can you please elaborate

#

the terrain is a navmesh

#

nvm

#

got it to work

ivory jasper
#

how can I some how store all of my game objects in some kind of list/dictionary, then be able to load them back and spawn each saved object accordingly? i'd like to make a save/load system like this, unless there's a better approach

#

the only attributes i'd ideally need to store are position, rotation, and type

rocky canyon
# ivory jasper how can I some how store all of my game objects in some kind of list/dictionary,...

u cant really save objects.. u could since ur already talkin about lists.. add all these gameobjects u want to saved in the list..
each number corresponds to an object..
0 -> this thing
1 -> that tree
2 -> this item.. etc and then save abunch of integers also inside a list or array or something..
then when u go to load.. u can have a script read the value from the save data.. and then load whichever object corresponds to it

echo sand
#
    private Dictionary<KeyCode, System.Action> keyMethods;

    void startMethodBinding()
    {
        keyMethods = new Dictionary<KeyCode, System.Action>
        {
            { KeyCode.LeftShift, updateSprint }
            ...
        };
    }

    void updateSprint()
    {
       ... 
    }

#

is this a valid way to call methods when a key is typed

#

i want to avoid making alot of if statements

steep rose
echo sand
rocky canyon
#

if u figure out the best way to do it holler at me..

#

i gotta making a mapping system soon..

echo sand
#

also how do i iterate trough the keys?

#

i tried this but it doesnt work

 foreach (KeyValuePair < KeyCode, System.Action > Key in keyMethods)
 {
     if (Input.GetKey(Key) == true)
     {

     }
 }
#

i also tried KeyCode instead

eternal needle
# echo sand i tried this but it doesnt work ```csharp foreach (KeyValuePair < KeyCode, Syst...

you can just grab the list of keys https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2.keys?view=net-8.0 or get the actual key from the key value pair https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.keyvaluepair-2.key?view=net-8.0#system-collections-generic-keyvaluepair-2-key
right now you're trying to plug in a KeyValuePair to the GetKey method
Though really id just use the new input system and not do any of this

ivory jasper
echo sand
rocky canyon
#

like here i have two arrays 1 for items and 1 for weapons..
in my load method i'd just loop thru them and i'd have a key or something to compare.. and that would hold all my objects
then the method would just load up all the items i need to begin the game

#

using just integer values..

#

then my Inventory Manager would populate w/ my items and weapons

ivory jasper
#

ah interesting

rocky canyon
#

altho theres many different ways..

eternal needle
queen adder
#

Hi everyone. I have problem.

rocky canyon
#

well, whats the error say?

#

and show Loader.cs !code

eternal falconBOT
ivory jasper
queen adder
eternal needle
# ivory jasper could you elaborate on the ID part?

For anything that youd wanna save in your world, you could assign an ID, associated with the prefab, which could just be a number. Then you save that ID to file along with whatever else. When you read the file, grab the ID and spawn the corresponding prefab

ivory jasper
#

oh okay

twilit jolt
#

Hi everyone, quick question

I'm working on a puzzle automation game, and i have my own level editor, that can save the map i'm working on to a scriptable object, and the game then when playing the level loads the stuff for it in
Editing, saving, loading and playing works perfectly fine, but when i close and reopen unity, one of the scriptable objects storing the level data randomly dumps all it's stored stuff
I have no code that runs without the game running too, so it can't be that i'm calling a function that would do something like this

the map data is basically just a list of a struct that stores the ID of the prefab (it's position in a list of all the prefabs that are in the editor), and the position and rotation of the piece (first pic)
the only time i'm actively modifying this list is when i call the save function, that is tied to a button inside the in game editor, it shouldn't be called anywhere else (pic 2)

am i doing something wrong when setting the stuff in the scriptable object that can cause this, or is this a unity issue? and if it is, is there any way to work around it?


Managed to fix it
For anyone who has this issue, what worked for me was manually marking the SO dirty, and then manually saving the assets

rich adder
twilit jolt
obsidian granite
#

Anyone have an idea on what I could do for arcade-like racecar movement while still having good, realistic car collisions? it's kind of hard for what i'm going for, since i want non-physically realistic movement while also having physically realistic collisions. rn i'm using convex meshcolliders and mesh deformation and such

#

https://www.youtube.com/watch?v=cqATTzJmFDY similar to this, but with mesh colliders on the car

Learn how to create Arcade-style Car Driving in Unity with a brand new tutorial!

Download the setup project files here: https://drive.google.com/open?id=1qVal_BSXdE5mYtA_8douoVSKkYNIAM3w

Wishlist 'Scoot Kaboom and the Tomb of Doom' right now at http://bit.ly/scootkaboom !

Get my new Udemy course 'Learn To Create A First Person Shooter With Un...

▶ Play video
obsidian granite
#

tysm man

rocky canyon
#

but it works pretty well.. considering its just a rolling ball

obsidian granite
#

i actually searchjed on yt for like

#

6 hours and didn't find something

#

u are the actual goat

rocky canyon
obsidian granite
#

it should

rocky canyon
#

could help to see it already setup and everything

#

but.. its a start lol

queen adder
#

ive been trying to make my guy walk up stairs but i cant quite seem to figure it out, he keeps getting stuck and it moves way to jankily when it does work

what am i doing wrong here?

Vector3 qw = manager.gravityDir*1.1f;
RaycastHit lowH;
bool stair = Physics.Raycast(col.bounds.center+qw,frfor,out lowH,0.5f);
if(stair && (Vector3.Dot(lowH.normal,rig.linearVelocity)<0)){
  if(!Physics.Raycast(col.bounds.center+qw/2f,frfor,0.5f)){
  Vector3 climb = transform.position-(manager.gravityDir*stepHeight);
  transform.position = Vector3.Lerp(transform.position,climb+transform.position,0.05f);
   }                }
  }
rocky canyon
#

not sure u wanna go this way.. but a simple way to deal with stairs... is to use a ramp collider instead

#

stairs can just be visual

queen adder
#

i may need actual stair-stepping abilities later on for slight deviations in terrain

steep rose
#

I personally use a raycast suspension on my player to negate this effect

#

Stairs are a pain in general

queen adder
#

whats a raycast suspension?

covert obsidian
#

i have this

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

public class movement : MonoBehaviour
{
    // Start is called before the first frame update
    public Vector3 jump;
    public float jumpForce = 2.0f;

    public bool isGrounded;
    Rigidbody rb;
    void Start()
    {
        rb = GetComponent<Rigidbody>();
        jump = new Vector3(0.0f, 2.0f, 0.0f);
    }
    void OnCollisionStay()
    {
        isGrounded = true;
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown("space") )
        {
            if(isGrounded)
            {
                rb.AddForce(jump * jumpForce, ForceMode.Impulse);
                isGrounded = false;
            }
        }
        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0); // Get the first touch
            
            // Check if it's a tap (or touch began)
            if (touch.phase == TouchPhase.Began)
            {
                Debug.Log("Screen was tapped!");
                // Add your code here to handle the tap
            }
        }
    }
}

but the isgrounded doens't work. it lets me jump while it's not grounded

steep rose
#

You use a raycast and apply suspension forces to your player

#

It will just go up stairs and slopes normally

queen adder
#

oh ok

rocky canyon
queen adder
#

i looked it up, it seems like something used for vehicles?

rocky canyon
#

A detailed look at how we built our physics-based character controller in Unity for our game Very Very Valet - available for Nintendo Switch, PS5, and Steam
BUY NOW!! https://toyful.games/vvv-buy

~ More from Toyful Games ~

▶ Play video
steep rose
#

This this

#

I couldn't find the video

rocky canyon
#

it can be used for vehicles.. but nothing stops it from being on a character

queen adder
#

alright, il watch this then. thanks

steep rose
#

You got that video on speedial spawn

#

Great work

rocky canyon
#

b/c of how clever it is

#

just "game magic" type of thing..

#

ur graphics will have its feet on the ground.. the actual collider tho.. it floating

rotund garnet
#

Is it possible to run a method from a different script which is on the same gameobject?

swift elbow
#

usually you will have to use GetComponent<>() to reference and set its value to whatever component you choose get

wintry quarry
#

Get a reference to it, and call the method

rotund garnet
#

thank god

languid spire
languid spire
#

exactly

swift elbow
#

i dont understand

#

why drag and drop when you can just call get component in start\

languid spire
#

If both scripts are on the same game object setting the reference in the inspector is better than using GetComponent

swift elbow
#

why?

languid spire
#

because then you dont need the GetComponent call

swift elbow
#

using get component is so much easier...

languid spire
#

really? why have an extra line of code which could go wrong if you don't have to?

swift elbow
#

id rather have its value be set automatically and find the script on its own rather than sometimes forgetting to drag and drop in the inspector and getting null ref errors

#

plus get component cant really go wrong as long as you have [requirecomponenttypeof()]

languid spire
#

and if you forget to add the script you still get a null ref

swift elbow
#

its less of a headache for me in all honesty and i wished i did this more when i was starting out fresh

languid spire
#

so 2 extra lines of unnecessary code

swift elbow
#

"unnecessary" to you 🤷‍♂️

languid spire
#

I don't think you would find many people who would agree with you

swift elbow
#

and thats ok 👍

languid spire
#

It has always been a design philosophy in Unity to keep GetComponent calls to an absolute minimum

swift elbow
#

is there a specific reason?

languid spire
#

overhead and easy to break

swift elbow
#

easy to break?

#

how so?

languid spire
#

script execution order for one

swift elbow
#

true, i never thought of that nor ran into that as an issue before

#

thanks for the insight, i guess

languid spire
#

yep, SEO can bite you in the arse more often than you would think

rotund garnet
#

this is what u were talking about, right, Steve?

languid spire
#

yes

idle ginkgo
#

hi I have been using unity version control

#

but i wanna switch to github

#

do i need to disable unity one

toxic cloak
languid spire
tulip pilot
#

Gentlemen I need some help, I have been assigned a project wherein my objective is to simulate a electric motor connected to a load in order to derive the heat, power consumption etc.

the project is a Proof-of-Concept and so far i have managed to basically achieve nothing so far. I have tried to attach the speed of the motor shaft to the sprocket, that did not work, and the opposite too which also did not work

#

I am basically stumped at this point, Internet and CGPT have not been helpful

#

right now all this is just a fancy screensaver

tulip pilot
teal viper
#

Can you record a video?

tulip pilot
#

I can, but to explain in words basically the Motor Shaft and the Sprocket both move independant of each other based on values inputted manually

#

there is just no Linkage between the two

teal viper
tulip pilot
# teal viper You'll need to only move the motor and everything else would either need to be l...

I see, There is a problem here tho, the Chain and Sprocket are generated with the use of a Tool from the Asset Store: https://assetstore.unity.com/packages/tools/game-toolkits/chain-and-gear-generator-273628

Get the Chain and Gear Generator package from Kaliper Tech and speed up your game development process. Find this & other Game Toolkits options on the Unity Asset Store.

#

The Speed at which the Sprockets rotate is controlled by it's own script via the variable "Machinery speed"

#

Changing the sprokets to Rigid body might break the whole thing

charred spoke
#

Looks to me that you can easily feed the shaft speed into this machinery speed variable

teal viper
tulip pilot
#

now if I can get away with doing that without physical accuracy, I'll take it

teal viper
tulip pilot
#

I see

#

Do I have any options with regard to using Chains and Sprockets?

#

I'll settle with Gears too

teal viper
tulip pilot
#

I see, so what are my avenues here

#

because I am a Complete Beginner to Unity

#

like, 0 experience whatsoever

teal viper
#

Research the available physics components, like joints and stuff and use them in the setup.

#

The only script you would need is one on the motor to set it's torque.

tulip pilot
#

I see

#

Thankyou mate

#

alright so I changed the layout, used two gears, and now only the left gear is spinning not driving the one on the right

#

The gear on the left is fixed joined to the Shaft which rotates it, the gear on the right is also fixed joined to the shaft which is to be rotated

lunar kelp
#

@hexed terrace whats wrong on line 37?

hexed terrace
fervent abyss
#

whats the best way to play an animation backwards?

languid spire
fervent abyss
#

retractAnimator.speed = -1; this right?

languid spire
#

well it does work so you've done something wrong

fervent abyss
#

its a code matter

#

i need to do it from code 😊

tulip pilot
#

Well I tried mesh colliders to try and have the two gears spin each other

#

suffice to say it didn't work at all

slender nymph
tulip pilot
lunar kelp
hexed terrace
#

The problem is obvious. You are giving values in the Y and Z axis, when you want to give JUST Y.. zero out the other axis.

#

0, Yval, 0

lunar kelp
hexed terrace
#

so.. read the error. research the solution

lunar kelp
#

at least did i do it right?

hexed terrace
#

nope

#

don't you think setting targetRotation to 0, Yval, 0 would be the obvious thing to do ?

lunar kelp
#

im new i have no idea

hexed terrace
#

It's LOGIC

lunar kelp
#

yeah but where do i exactly put it that i dont get

hexed terrace
#

think about it.. you want the correct rotation before you set the turret rotation

#

step through the life of targetRotation, think about it

#

you're also dealing with Quaternions for some reason, would be easier with eulers

slender nymph
#

there's not enough context here

fervent abyss
tulip pilot
#

I just straight up used a script to do the job for me

languid spire
#

you are setting the speed of the snimator not the animation

fervent abyss
fervent abyss
#

im using an animator btw

#

ok

slender nymph
#

how could i know if the PlayBack method is even being called

fervent abyss
#

theres a code above the video

slender nymph
#

please learn to read

slender nymph
#

and enough with the stupid emoji replies, use a reaction so i don't get pinged for inane bullshit

fervent abyss
slender nymph
#

right so i'm definitely not helping you anymore

fervent abyss
#

right... have a good day

fervent abyss
#

i cant set it

languid spire
#

not sure it would work for you if you are not using Animator states anyway

slender nymph
#

well that's certainly not a code question, nor is it unity related. but you do know discord has an inbox that will show you all of the direct replies and messages you've received right?

wet bobcat
#

no thanks I look at it and remove the previous post

vagrant harness
#

Anyone know why this isn't working -_-"

public GameObject[] dataPlanes;
// Start is called before the first frame update
void Start()
{
    for (int i = 0; i < 100; i++)
    {
        dataPlanes[i] = (transform.GetChild(i).gameObject);
    }
vagrant harness
#

It isn't assigning any list items

cosmic dagger
#

an array is fixed size. you need to initialize it with a set number . . .

vagrant harness
#

Nevermind, figured it out

    public GameObject[] dataPlanes;
    // Start is called before the first frame update
    void Start()
    {
        dataPlanes = new GameObject[100];
        for (int i = 0; i < 100; i++)
        {
            dataPlanes[i] = (transform.GetChild(i).gameObject);
        }
cosmic dagger
#

then you can populate it with . . .

cosmic dagger
cosmic dagger
# vagrant harness It isn't assigning any list items

i noticed you called it a list. this is where the error lies. GameObject[] is an array which has a fixed size (length) and cannot be changed. List<GameObject> is a list which can grow/shrink dynamically. both are called collections which store a group of objects . . .

vagrant harness
#

I only called it a list cuz I've used Visual Scripting for years lol

tender stag
#

why is the event being called before the for loop?

verbal dome
tender stag
#

by commenting out the for loop

#

and seeing if the OnEnteredSeat triggers a bool to false

#

and it does

lunar kelp
tender stag
#

because of the for loop

verbal dome
#

Idk what your code does but the for loop definitely runs before the event invoke

tender stag
tender stag
#

so im not sure

verbal dome
#

Use Debug.Log or debugger

strong wren
#

You'll probably figure out the issue if you attach and step through it

tender stag
#

but how the fuck does it not set the bool

#

the for loop resets it

#

wait

#

something is wrong

ashen frigate
#

hello

#

can i ask here unity question ?

cosmic dagger
#

this channel is for beginner coding questions. if you want general unity questions, try #💻┃unity-talk

ashen frigate
#

im a beginner

#

kinda

cosmic dagger
#

that's fine, as long as it's related to coding, then you're in the right place . . .

hexed terrace
#

!ask

eternal falconBOT
ashen frigate
#

ive made a state machine for my game and theres a logic if player grounded you can jump once
im trying to change it to double jump
but im kinda having troble with it

my jump state https://pastebin.com/dTBemRd3
my machine state https://pastebin.com/5qP9dkDB

lunar kelp
#

can this be an model issue?

silk night
hexed terrace
#

he has

#

Show where the axis for the turret transform is

silk night
#

ahh further up, aight

rich adder
lunar kelp
rich adder
#

wat?

#

Im talking about the gizmos, for the pivot. The axis directions

#

the colored arrows

lunar kelp
#

i thought u meant this

rich adder
#

yes and you show what it looks like in the scene

#

with turret selected

lunar kelp
cosmic dagger
rich adder
# lunar kelp

what is the pivot for the top part, that seems to be the part rotating

wintry quarry
# lunar kelp

Looks like you have the base here.
Select the gun part

lunar kelp
#

first one is the head and second one is the partToRotate

lunar kelp
rich adder
hexed terrace
#

make sure this is set to local

rich adder
#

it is apparently (hopefully)

hexed terrace
#

Ah, that was scrolled off screen

lunar kelp
rich adder
#

why did you put it back to center?

rich adder
#

X axis should not be Top / Down

hexed terrace
#

Green = Y, should be pointing up

rich adder
#

and blue is correct for the first one but not the second

vestal adder
#

can seeing if my game strains the cpu, ram or gpu help me tell what in my game could use optimising

hexed terrace
#

AND you want it located at the rotation point.. not in some random position (or centered)

rich adder
vestal adder
#

i have used it maybe i am missing something

lunar kelp
vestal adder
#

does the profiler show exactly what is straining the game or something

rich adder
#

Blue is always your Forward

#

either use blender and fix it, or just make a parent object then adjust the child so the foward matches parent blue

rich adder
hexed terrace
#

you'd ideally want the Z axis pointing the same way as the barrels... otherwise you're going to have to add 180 to your look at calcs

vestal adder
#

i have used it

rich adder
#

used it and used it properly are two different things

lunar kelp
vestal adder
#

what should i be getting from this

hexed terrace
# vestal adder

Clicking on those graphs will give you information. Also, this isn't a code question, so shouldn't be in here.

Probably look on !learn 👇 for guides on how to use the profiler

rich adder
eternal falconBOT
#

:teacher: Unity Learn ↗

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

vestal adder
#

my fault

rich adder
tulip nimbus
#

IDK if this is the channel to ask, Can anyone explain to me why this code does not work. The tags are assigned but it just wont do anything at all once a collision happens...

rich adder
#

also why is the top OnTriggerEnter nested inside another method 🤔

tulip nimbus
#

as im fairly new, i dont know whether the function is called every frame or once start is hit

rich adder
#

its the first call when something enters a trigger

tulip nimbus
#

thanks alot for the info

rich adder
#

the barrel of a gun

lunar kelp
#

oh

rich adder
lunar kelp
rich adder
#

so any object that has some sort of pointing direction, ideally want this fix

tulip nimbus
#

Another quick question, how do you combine if statements? For me i get a compiler error if i do it like this. How do i do it right?

toxic cloak
cosmic dagger
night raptor
#

double modulo 🤔

tulip nimbus
rich adder
rich adder
tulip nimbus
#

Ok what did i do wrong this time?

cosmic dagger
#

hover over the red squiggly error . . .

tulip nimbus
cosmic dagger
#

you have to look at the mistake in order to understand what you did wrong . . .

rich adder
tulip nimbus
toxic cloak
tulip nimbus
#

Im a total beginner so i appreciate your help so much guys

rich adder
#

its also not in the same statement

polar acorn
cosmic dagger
rich adder
#

closed the first parenthesis too early

tulip nimbus
#

Guys it works you are truly the best

#

i appreciate it so much

vestal adder
#

do these switch states need to be in update, they control where the enemy will go and seem to be using alot of computing power

    {
        switch (state)
        {
            case State.Idle:
            if (Health.health <= 0)
            {
                anim.SetBool("idle", true);
            }
            break;

            case State.Patrol:              
            Patrol();                         
            break;

            case State.Chase:                                                   
            Chase();             
            break;

        }

    }```
tulip nimbus
#

it is like magic onceit works and now i feel kinda dumb haha

rich adder
polar acorn
toxic cloak
cosmic dagger
vestal adder
rich adder
toxic cloak
rich adder
#

any c# tutorial will do. Usually find better less click bait trash that way than Unity specific ones

ashen frigate
#

jumpCount is set to 2 after i jump

#

and _DoubleJump idk

rich adder
cosmic dagger
ashen frigate
#

_DoubleJump is somthing ive add to debug but it dosnt seem like its effecting it

#

_DoubleJump = flag

rich adder
#

then find out why

ashen frigate
#

ive tried idk why

rich adder
#

try it how ? did you debug it where is the debugging and what did you check in debugging
I dont see one single log in your code. nvm maybe 1 and it prints something not helpful

cosmic dagger
ashen frigate
#

ive tried flag "_DoubleJump" = 0 then check if its 1 then dont enter if(...)

cosmic dagger
ashen frigate
#

it jump to 2

#

ive pressed jump 1 time

cosmic dagger
#

is there anywhere else you are increasing JumpCount? search your scripts . . .

ashen frigate
#

but no doublejump still

#

ive placed public for double jump and it seem to be stuck in 1

#
rich adder
eternal falconBOT
rich adder
#

pastebin sucks a donkey

#

half the page wasted on bs scam
not vertical screen friendly

ashen frigate
rich adder
ashen frigate
#

i want to be able to do double jump

rich adder
#

so is HandleJump hitting ?

ashen frigate
#

yea it does the first jump

#

but not the secound

#

im mean in air jump "double jump"

rich adder
#

tihis ?

 else if (Ctx.DoubleJump < 1)
        {
            Debug.Log("enterd the double jump if :: ");
            HandleJump();
        }
ashen frigate
#

i think handlejump should be able to do as many jumps as u want if u calling it the only thing that should stop it is if statement

ashen frigate
rich adder
#

taking out the grounded if and if for counts, are you able to run Handle jump multiple times

ashen frigate
rich adder
lunar kelp
rich adder
#

since you're rotating the parent , the rest is just visuals

ashen frigate
lunar kelp
ashen frigate
rich adder
rich adder
ashen frigate
#

XD ok i wasnt sure im kinda confuse about all of this

rich adder
#

imo this is already overcomplicated statemachine for simple setup

#

its complicating it more for you

#

how many states are you really having ? if you're new to FSM start with something simpler like enum and switch statement

toxic cloak
frank flare
#

So there's a project where there are 4 buttons and each button has a special effect when I click it. For an example one of these buttons move that big cube on the video up when it's clicked. How can I make some event that moves that cube up that gets called from a button's script?

using UnityEngine;
using UnityEngine.InputSystem;

public class Keyboard : MonoBehaviour
{
    private Camera playerCamera;

    void Start()
    {
        playerCamera = Camera.main;
    }

    void Update()
    {
        Mouse mouse = Mouse.current;
        if (mouse.leftButton.wasPressedThisFrame)
        {
            Vector3 mousePosition = mouse.position.ReadValue();
            Ray ray = playerCamera.ScreenPointToRay(mousePosition);
            if (Physics.Raycast(ray, out RaycastHit hit))
            {
                if (hit.collider.gameObject == gameObject)
                {
                    Debug.Log("u"); // instead put here an event and from the other script log "u" and move the cube up
                }
            }
        }
    }
}

Not sure if it's related to #💻┃code-beginner but anyways

ashen frigate
#

public override void CheckSwitchStates()
{
//if (Ctx.CharacterController.isGrounded)
//{
Ctx.IsJumping = false;
Ctx.DoubleJump = 0;
SwitchState(Factory.Grounded());
Debug.Log("isGrounded :: ");
//}
if (Ctx.DoubleJump < 1)
{
Debug.Log("enterd the double jump if :: ");
HandleJump();
}
}

public override void CheckSwitchStates() {
if (Ctx.IsJumpPressed && !Ctx.RequireNewJumpPress)
{
SwitchState(Factory.Jump());
}
}
its going up no gravity
if i press jump it stops it

lunar kelp
rich adder
#

also would use UnityEvent or something to Invoke

rich adder
frank flare
rich adder
ashen frigate
lunar kelp
frank flare
rich adder
lunar kelp
#

what am i supposed to do in the script?

frank flare
rich adder
#
if (Physics.Raycast(ray, out RaycastHit hit))
            {
                if (hit.collider.TryGetComponent(out Keyboard keyboard))
                {
                    keyboard.DoSomethingInThisKeyboard();
                }
            }```
chrome chasm
#

Does anyone know how I can render a particle system over a screen space canvas (which fills the whole screen)?

rich adder
#

code comes after..

lunar kelp
rich adder
#

btw when someone says "shown" they mean visually

#

I'm not at your computer nor am i psychic so I can't see what you see

rich adder
# lunar kelp

alr what about PartToRotate, show the inspectors too..

rich adder
# lunar kelp

okay which object has the script you shown snippet from, can you show the inspector for it

frank flare
rich adder
rich adder
#

specifically said that

frank flare
lunar kelp
rich adder
frank flare
lunar kelp
#

you said we'll do the scripting later

rich adder
#

then on Keyboard you put each thing you want to do different

rich adder
#

need to make sure its referencing the correct Transform

lunar kelp
#

oh u mean partToRotate?

#

not really

rich adder
#

instead of PartToRotate

#

you're rotating the one with the incorrect axes

#

thats first

#

Turrent 2 component should be on Turret root gameobject anyway.. and referencing PartToRotate in the Transform Turret field

#

you should not put logic scripts buried in the mesh

lunar kelp
rich adder
#

just show screenshots so we dont get confused

lunar kelp
#

the video u sent me earlier

rich adder
#

this is correct

#

Your reference on the script is not

lunar kelp
#

which is?

rich adder
lunar kelp
#

ohhh

rich adder
#

please tell me you understand 5% of what we're doing so i can keep going notlikethis

lunar kelp
#

it fixed a bit

rich adder
#

ok now

#

fix the code

lunar kelp
#

so the parent was useless?

rich adder
#

what?

lunar kelp
#

was it just a minor mistake i made or was the parent essential

rich adder
#

its there to ensure the code matches the axes correctly

#

try changing code to

Vector3 directionToTarget = target.position - turret.position;
directionToTarget.y = 0f;
if (directionToTarget != Vector3.zero)
{
    Quaternion targetRotation = Quaternion.LookRotation(directionToTarget);
    turret.rotation = Quaternion.RotateTowards(turret.rotation, targetRotation, rotationSpeed * Time.deltaTime);
//etc
}
#

did it work ? @lunar kelp

frank flare
# rich adder OH nah you should have this On 1 script on player

what's the difference between this

using UnityEngine;
using UnityEngine.InputSystem;

public class Keyboard : MonoBehaviour
{
    public void DoSomethingInThisKeyboard()
    {
        Debug.Log("y");
    }
}

which gets called by

if (hit.collider.TryGetComponent(out Keyboard keyboard))
                {
                    Debug.Log("u");
                    keyboard.DoSomethingInThisKeyboard();
                }

and having DoSomethingInThisKeyboard as some event... or something...

lunar kelp
#

2 actually

rich adder
# lunar kelp

well no one said copy it verbatim. It was an example

#

obv you replace it with whatever your names are

lunar kelp
#

oh right i completely missed it

rich adder
#

if you do this you can plug a different thing inside the inspector on each Keyboard

cosmic dagger
ancient karma
#

Having trouble making a camera control system for aiming in my top down game. I have written this script to handle moving the camera to where the player is aiming, but because you aim by clicking on the screen somewhere, when the camera moves to that position the cursor's location in 3d space changes, resulting in the aim moving constantly in the direction you are clicking

#
        if (Input.GetMouseButton(1))
        {

            RaycastHit hit;
            Ray ray = cam.GetComponent<Camera>().ScreenPointToRay(Input.mousePosition);

            //if the player clicked on a valid location
            if (Physics.Raycast(ray, out hit))
            {

                //handle camera movement
                aimPoint.transform.position = hit.point;

...

#

I think I would need to offset the cursor by the amount the camera moved, but I'm not exactly sure how I would accomplish that and I didn't see anything similar on the forums

lunar kelp
#

i tried to put partToRotate but it didnt work for some reason

rich adder
ancient karma
#

the idea was that you would aim at a location and the camera would move over where you are aiming to give you a better look

rich adder
#

or do you not want player to be able to aim outside the colliders?

#

its shifting up and down probably because if height variation in hitpoint

ancient karma
#

shifting up and down isn't really the issue, that I can solve by stripping the vertical component from the vector

rich adder
#

but mainly you want to add like a min distance before camera follows the cursor

rich adder
#

something to keep in mind

ancient karma
#

yeah, thats alright for now. I will probably change that now that I am reading about planeRaycast since having your aim get stuck on that isn't the most pleasent

#

but the core issue still persists, it's using the mouse position as more of a movement vector than a target to observe while aiming

dusky bay
#

I keep getting this error, I've tried everything to fix it, Google, Youtube and even myself but I simply can't get rid of this error.
Here is where the error directs to:

if (ShouldLoadText)
            {
//this one                
if (dialogues.Dialogues[DialogueIndex - 1] != null) StartCoroutine(LoadText(dialogues.Dialogues[DialogueIndex - 1], SpeechBubble));
                ShouldLoadText = false;
                gameObject.transform.GetChild(0).gameObject.SetActive(false);
                gameObject.transform.GetChild(dialogues.Expression[DialogueIndex - 1]).gameObject.SetActive(true);
            }
rich adder
dusky bay
#

I can't do that, it's essential to my game.

rich adder
#

no make the index within the bounds

#

idk how you got otherwise from what i said

dusky bay
#

sorry abt that

rich adder
#

there are multiple collections to check here

dusky bay
#

I tried this:

if(DialogueIndex < 0) DialogueIndex = 0;
        if(DialogueIndex > dialogues.Dialogues.Count - 1) DialogueIndex = dialogues.Dialogues.Count - 1;
``` but I still get errors
rich adder
#

GetChild can also return out of bounds btw

dusky bay
#

this will check if it's out of range or negative, but I still get errors

dusky bay
rich adder
#

I mean its possible thats the one, but its good to double check because transform basically holds collection of children

#

Debug.Log the indexes in the code

dusky bay
#

what should I do, like before?

dusky bay
rich adder
dusky bay
rich adder
#

also make sure you add this to second parameter of Debug.Log

dusky bay
#

oh yeah one thing to state is that the error is outputted alot of times, like 1k

rich adder
#

then it means you tried doing it 1k 🤷‍♂️

dusky bay
#

I did the embed wrong

#

so ignore the cs

rich adder
dusky bay
rich adder
dusky bay
#

I've only got one object using the script

rich adder
#

still its good habit to do so for future

#

there could one day be an object with the same component that has an empty collection and you dont notice etc.

dusky bay
#

ok

ancient karma
# rich adder something like this ?

https://youtu.be/sWCnL-3JMag?t=184 more along these lines

If you're new to Foxhole or are struggling with picking up kills with a rifle this guide will take you through some quickstart tips that you can use right now to improve your aim and land some hits.

Normally I would enter chapters but it's a short video and if you need to watch some of it you should probably watch the whole thing - I hope it he...

▶ Play video
dusky bay
rich adder
#

everything else moves the same

dusky bay
weak cedar
#

!ask

eternal falconBOT
weak cedar
#

!code

eternal falconBOT
weak cedar
#

            Touch touch = Input.GetTouch(0);
            if (EventSystem.current.IsPointerOverGameObject(touch.fingerId))
            {
                Debug.Log("yes");
                return;
            }
            if (um.gameState == GameState.MainMenu)
            {
                Debug.Log("touch");
                um.DraggedAtStart();
            }
ancient karma
# rich adder I dont understand this just zooms out for longer range

crude drawing time. green represents the non aiming fov around player P, orange represents the fov while aiming at the target T. The camera is normally centered on the player, but then aiming it shifts to a point between the player and the target (and zooms accordingly) to give a better look at where you are shooting

weak cedar
rich adder
# ancient karma crude drawing time. green represents the non aiming fov around player P, orange ...

use 2 cameras with cinemachine, 1 that follows the player.
To get the inbetween effect would be easier to do 2 Transforms, 1 is the target position on cursor transform and the second is the origin of the weapon or whatever aim origin.
The Target Group in cinemachine could probably always keep a proper view between the two. Then just toggle between the two cameras, cineamchine adds nice smoothing you can adjust

ancient karma
#

lol I forgot the actual problem my b, I have the camera movement sorted, just gotta lerp and it will smooth out. the issue is when the camera moves, the cursor is no longer in the same location in 3d space, and it moves the camera target point, which then further moves the cursors poition in 3d space, and so on

rich adder
#

so put a variable for the position that doesnt change unless you cancel out them aim

ancient karma
#

would that prevent you from adjusting your aim without letting go then aiming again?

frank flare
rich adder
rich adder
#

so when you aim you hold say right mouse, then it locks that position, if you move the mouse the camera is still locked on that spot instead of mouse

ancient karma
#

unless I'm misunderstanding, that would prevent you from moving your aim without letting go of it first, it would be like playing call of duty except you cant move your camera while ADS'd

rich adder
ancient karma
#

lmao I probably explained it poorly

rich adder
#

its also a little confusing since I have a similiar project but ig we have different purposes on aim 😅

ancient karma
#

its not so much the camera that needs to stop moving, its the cursor

rich adder
#

well you can't technically stop the cursor but you can for example stop capturing its movement for your calc

#

or if your cursor is custom you can just stop running whatever scripts sets its pos

ancient karma
#

I did think of that, stopping and starting capturing it only while the cursor is actually in motion/input on mouse axis

#

But since the cursor gets offset by the camera movement, moving the cursor after the offset would just be the same problem

#

I just read something about making a custom cursor based on the mouse position's delta. That might be the way I have to go

versed zinc
#

can anyone please help? I want my enemy to lock in on me but it doesnt. I use enemy.transform.LookAt(enemy.Player.transform); to do it and also it lays down. here how it looks like:

ancient karma
#

Then the camera movement wont move the cursor, only mouse movement will move the cursor. in theory

frank flare
rich adder
ancient karma
#

LOL, there's the miscommunication 😆

#

I'll give that a shot and see how it turns out

rich adder
#

just not the way you expected

versed zinc
#

ik but how to fix it

rich adder
#

you have to fix the pivot

#

transform.LookAt uses the Forward(blue arrow) of the transform to look at somewhere

#

make sure you adjust it in Pivot / Local mode not Global

versed zinc
#

ok

#

ill try

versed zinc
#

oh

#

wait

rich adder
versed zinc
#

I did center

rich adder
#

there are more steps, which still includes you fixing the pivot 😂

versed zinc
#

how to do it

rich adder
#

make it child of a parent object then rotate child to match the blue arrow on parent

pulsar meteor
#

help i had a player controll but it didnt save and everthing is gone

rich adder
#

what didnt save ?

#

whats a "player controll"

pulsar meteor
#

wsad

#

idk

rich adder
#

wsad? idk what that is

versed zinc
pulsar meteor
#

it just didnt save i hit ctrl s but it didnt save

rich adder
#

what didn't save ? I have no idea

rich adder
pulsar meteor
rich adder
pulsar meteor
versed zinc
rich adder
pulsar meteor
#

and thats it

versed zinc
#

it works

rich adder
hallow acorn
#

hey i just wrote my script that checks for a raycast every frame until it hits something with a special tag and ive been wondering if it matters if i check for the input and than the raycast or the raycast and the input at the same time. does it affect performance in a noticable way?

shell sorrel
#

well do you only care about the raycast when a certain input is happening?

cosmic dagger
rich adder
#

if you want prompts then you need Raycastfirst then buttonPress

#

eg like inspecting an item before text of "press E to interact"

shell sorrel
#

also the cost of a raycast per frame is not much in the grand scheme of things

hallow acorn
shell sorrel
#

so if you want to popup something up based on it, before input yeah its fine to do that every frame

cosmic dagger
#

yeah, they're cheap . . .

shell sorrel
#

i would use the nonalloc version if you can

rich adder
#

mostly thats only if seek more than 1 collider

#

like RaycastAll etc.

hallow acorn
hallow acorn
shell sorrel
#

now you need logic to count frames vs just doing it

#

and the user might notice

#

think about this in a shooter 90% of weapons are hitscan and some fire very fast and its fine

hallow acorn
#

yeah ok i might just cast the raycast and its good enough haha

steep rose
shell sorrel
#

like generally do not do work that is not required, but if you have a use for something just for for it

#

better to keep things simple, then over complicate it worrying aobut performance problems that do not exist

hallow acorn
twin bolt
shell sorrel
#

if you do hit perf issues you got the profiler to tell you exactly why

rich adder
steep rose
#

im guessing its asking for a float

rich adder
#

pretty sure its not a float

#

its a ParameterFloat or some shit

twin bolt
shell sorrel
#

did you read the error?

rich adder
#

check the docs

shell sorrel
#

its highlighted red and should tell you

twin bolt
#

Severity Code Description Project File Line Suppression State
Error (active) CS1503 Argument 1: cannot convert from 'UnityEngine.Rendering.ClampedFloatParameter' to 'float' Assembly-CSharp C:\Users\RATPr\My Game\Assets#My Stuff#Main\Scripts\Main\Mechanics\Autofocus.cs 36

shell sorrel
#

so there is your answer

#

its expecting a float you gave it a ClampedFloatParameter

twin bolt
#

I mean that prior to writing the code, i thought it would be a float.

rich adder
#

ohh ClampedFloatParameter, I was off by the Clamped 😛

twin bolt
shell sorrel
#

read the docs see what that type provides for you

rich adder
#

you have to cast it

#

since you get a Single

shell sorrel
#

it seems to have a GetValue method

twin bolt
#

Oh ok.

#

Still gives Severity Code Description Project File Line Suppression State
Error (active) CS0029 Cannot implicitly convert type 'float' to 'UnityEngine.Rendering.ClampedFloatParameter' Assembly-CSharp C:\Users\RATPr\My Game\Assets#My Stuff#Main\Scripts\Main\Mechanics\Autofocus.cs 38

shell sorrel
#

did you save

#

even if it failed for a other reason the error would differ

#

signature is T GetValue<T>() so if you give it float it will return float

pulsar meteor
#

i have the error parameter doesnt exist and it exist help

twin bolt
#

Yep i saved and it still gives same error..

rich adder
#

you really dont know why after what we said?

#

Mathf.MoveTowards returns float

#

focalLength expects ClampedFloatParameter

#

what is wrong here?

steep rose
#

talk with words

eternal falconBOT
polar acorn
twin bolt
rich adder
#

that works too ig thought it was a private set 👍

stuck palm
#

if I remove a field in a scriptable object, will the data stored in other fields be lost?

rich adder
shell sorrel
stuck palm
#

I mean like if I have a scriptable object asset, and remove a field from the script, will the data in the other fields be lost

cosmic dagger
rich adder
#

ohhh like reset

#

no it wont

#

only when you change the names of the field it affects that fields data but not others

stuck palm
#

thank you

rich adder
stuck palm
#

fr 😅

#

how does unity handle the preservation of that data when you remove and add fields?

rich adder
#

ima guess reflection

#

only touch the entry/field affected or sum

#

it all goess in the text file / yaml is just like removing any other entry in a organized structure

twin bolt
#

Okay so now it changes the focal length but not every update, only everytime the "focus" bool is toggled. ``` void Update()
{
RaycastHit hit;
if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, maxPickupDistance))
{
if(hit.transform.tag == "Interactible" || hit.transform.tag == "Item" || hit.transform.tag == "Door" || hit.transform.tag == "BigItem" || hit.transform.tag == "Lock" || hit.transform.tag == "Paper" || hit.transform.tag == "Important")
{
Focus = true;
}
else
{
Focus = false;
}
}
else
{
Focus = false;
}

    if(Focus == true && DOFSetting.focalLength.value != 0f)
    {
        DOFSetting.focalLength.value = Mathf.MoveTowards(DOFSetting.focalLength.value , 0f, 10 * Time.deltaTime);
    }

    if (Focus == false && DOFSetting.focalLength.value != 50f)
    {
        DOFSetting.focalLength.value = Mathf.MoveTowards(DOFSetting.focalLength.value, 50f, 10 * Time.deltaTime);
    }
}```
#

I'm trying to make it fade to 0 or fade to 50

pulsar meteor
#

why isnt it working

cosmic dagger
rich adder
pulsar meteor
twin bolt
pulsar meteor
steep rose
pulsar meteor
steep rose
#

i have zero clue on what you are seeing

cosmic dagger
# pulsar meteor what then?

i don't know what you're trying to do because that wasn't explained, but i'm talking about the warning message from your console screenshot . . .

steep rose
pulsar meteor
steep rose
pulsar meteor
steep rose
#

thats..

#

okay

rich adder
steep rose
#

im flabbergasted

pulsar meteor
cosmic dagger
pulsar meteor
#

but the error say si dont have is walking

#

but i have

#

and i have this also

cosmic dagger
pulsar meteor
steep rose
#

show us the entire script !code

eternal falconBOT
cosmic dagger
#

if you clear the console and run the game, does the warning still appear?

steep rose
#

are you actually getting the correct animator?

pulsar meteor
#

yess

#

i didnt move

#

is this a common problem

cosmic dagger
#

as dec_vew mentioned, is the correct animator referenced?

pulsar meteor
#

yea i checked

twin bolt
steep rose
pulsar meteor
steep rose
#

show us that transition

pulsar meteor
rich adder
twin bolt
#

It only moves when the bool is changed.

deft grail
#

!code

eternal falconBOT
cosmic dagger
#

!code

eternal falconBOT
rich adder
steep rose
#

im a bit stumped here

pulsar meteor
faint osprey
#

how do you round a float to 3 sf ive tried mathf.round but its not working

twin bolt
# rich adder which one you have 2

Both lines dont move every frame. ```
if(Focus == true && DOFSetting.focalLength.value != 0f)
{
DOFSetting.focalLength.value = Mathf.MoveTowards(DOFSetting.focalLength.value , 0f, 10 * Time.deltaTime);
}

    if (Focus == false && DOFSetting.focalLength.value != 50f)
    {
        DOFSetting.focalLength.value = Mathf.MoveTowards(DOFSetting.focalLength.value, 50f, 10 * Time.deltaTime);
    }```
wraith phoenix
#

Anyone know why my PlayerDash() is not firing when I press the associated button?

{
    // Inspector Variables
    [SerializeField] private TrailRenderer myTrailRenderer;

    // Operational Variables
    private bool isDashing = false;
    private float coreMoveSpeed;
    private float dashSpeed;
    private float dashCDTimer;
    private float dashDuration;
    
    // Scripts
    private PlayerController playerController;
    private PlayerControls playerControls;
    
    private void Awake() {
        playerControls = new PlayerControls();
    }

    void Start()
    {
        playerController = GetComponent<PlayerController>();
        coreMoveSpeed = GetComponent<BaseStats>().GetStat(Attributes.MoveSpeed);
        dashSpeed = GetComponent<BaseStats>().GetStat(Attributes.DashSpeed);
        dashDuration = GetComponent<BaseStats>().GetStat(Attributes.DashDuration);
        dashCDTimer = GetComponent<BaseStats>().GetStat(Attributes.DashCDTimer);
        
        playerControls.Movement.Dash.performed += _ => PlayerDash();
    }

    private void Update() {
        if(playerControls.Movement.Dash.triggered){PlayerDash();}
    }

    private void OnEnable() {    
        playerControls.Enable();
    }

    private void OnDisable() {
        playerControls.Disable();
    }

    private void PlayerDash() {
        Debug.Log("Dash fired");

        if(!isDashing && Stamina.Instance.CurrentStamina > 0) {
            Stamina.Instance.UseStamina();
            isDashing = true;
            playerController.moveSpeed *= dashSpeed;
            myTrailRenderer.emitting = true;
            StartCoroutine(EndDashRoutine());
        }
    }

    private IEnumerator EndDashRoutine() {
        yield return new WaitForSeconds(dashDuration);
        playerController.moveSpeed = coreMoveSpeed;
        myTrailRenderer.emitting = false;
        yield return new WaitForSeconds(dashCDTimer);
        isDashing = false; 
    }
}```
deft grail
steep rose
deft grail
#

oh i see in Update, thats kinda hidden

faint osprey
slender nymph
#

if you want to snap the float to the nearest thousands digit (which is what i assume you meant with "to 3 sf", use the Snapping.Snap method

cosmic dagger
faint osprey
wraith phoenix
faint osprey
faint osprey
#

literally was just on that lol

slender nymph
faint osprey
#

literally dont know it says rounds value to closest multiple of snap so does that mean if i put 0.1 it will round to 0.1, 0.2, 0.3

slender nymph
#

yes

steep rose
elder fern
#

hello guys i am using videoplayer, but how do i check if the video has finished? thanks
i have tried looking in the docs but i still dont get it
i have been stuck for 30 mins

faint osprey
#

it didnt work im still getting floats that are 6 decimals long

#
                Snapping.Snap(CDP.HPS, 0.01f);
                CDP.HPSDisplay.text = "(HPS: " + CDP.HPS.ToString() + ")";```
#

thats the code im using

slender nymph
#

remember that floats are value types

#

and that Snap returns the value

faint osprey
#

CDP.HPS = Snapping.Snap(CDP.HPS, 0.01f);
so shod be this?

rich adder
slender nymph
faint osprey
elder fern
#

like what variables should i change and so and so

rich adder
steep rose
#

its just a void

#

which you invokerepeated

rich adder
#

literaly just

  [SerializeField] VideoPlayer videoplayer;
  void OnEnable()
  {
      videoplayer.loopPointReached += Videoplayer_loopPointReached;
  } 
    private void Videoplayer_loopPointReached(VideoPlayer source)
    {
        //do somehting
    }
elder fern
#

ok ty

#

what does serialize field do?

#

sorry i am very new to unity

rich adder
steep rose
elder fern
#

oh ok

#

ty

rich adder
# elder fern sorry i am very new to unity

btw when subscribing to event is good measure to unsubscribe, dont forget to clean up by doing the opposite in the OnDisable or OnDestroy method
eg cs void OnDisable() { videoplayer.loopPointReached -= Videoplayer_loopPointReached; }

cosmic dagger
wraith phoenix
#

Well, at least my debug log is recording lol.
Now to get it to actually adjust my move speed from my primary movement script (:

cosmic dagger
#

well, that's a start . . .

wraith phoenix
# cosmic dagger oh, nice. what was the solution?

I'm not entirely sure lol.
I changed:
playerControls.Movement.Dash.performed += _ => PlayerDash();
to:
playerControls.Movement.Dash.started += _ => PlayerDash();

But I also did a few other things.

#

This was in the Start()^

#

Removed the stamina references and now it 100% works!
Now just to bring back in the stamina control and tweak the duration / speed.

#

It's a kind of cool system to use if anyone wants to have different dashes for different character classes.
Feel free to ask if anyone wants more details (:

cosmic dagger
thorny fern
#

Hello!
I started learning Unity and i want to ask a few questions regarding scripting.
I learned how to disable a script from another script (using a toggle event for on/off)
I have a Circle prefab that i spawn on the screen multiple times whenever i click a button. The circle prefab has a script attached to it that makes the circle moving in random direction. While in edit mode i can see in hierarchy tab that a clone of the prefab is created each time. Because each of the circles move in a different direction, my understanding is that the script is also cloned? I want to make a button to stop all moving circles at the same time. Here are my questions:

  1. Can i disable/enable the Circle prefab script for all clones at once or do i have to loop through all of them and disable each one individually?
  2. When disabling a script and then enabling it again, does the Start() function execute again?
  3. In a scene with multiple scripts each with their own Update() function, does Unity use any multithreading for running all the Update() functions? I read something about the order in which those are run -> does it imply that all Update() functions are ran sequentially single threaded?
wraith phoenix
cosmic dagger
rich adder
# thorny fern Hello! I started learning Unity and i want to ask a few questions regarding scri...
  1. loop though all of them yes but disabling parent gameobject disables all child gameobjects scripts from running though (unless they have something else referencing the script and running a function)
  2. no it does not, only OnEnable and OnDisable do for example
  3. unity runs single-threaded until you use jobs so all Updates are ran sequentially also no guarntee which script runs first the specific event,
queen adder
#

hi my capsule character clip through the wall its acting like there is no collision how to fix that?

rich adder
steep rose
wraith phoenix
rich adder
rich adder
#

also the inspector for this gameobject

thorny fern
steep rose
eternal falconBOT
rich adder
#

main useful only if you're doing long and complex calculations

wraith phoenix
thorny fern
thorny fern
rich adder
#

solving issues by tossing multicore at them isn't always the solution

#

lot of people still have cpus that perform better on single core

thorny fern
cosmic dagger
# thorny fern Hello! I started learning Unity and i want to ask a few questions regarding scri...
  1. Yes: PART 1: by using events, each circle instance can subscribe to an event. when that event is called, all circles will execute the method subscribed to the event (disabling them).
    PART 2: you can add each instantiated circle to a list, then loop and disable the script on each circle

  2. No: Start is only called once during the lifetime of a GameObject, however, OnEnable is called every time the script is enabled (or the GameObject becomes active).

  3. By default, Unity is single-threaded. you can setup a system where an UpdateManager with a list iterates runs an OnUpdate method on each component (in the list), or an event that other scripts subscribe their custom OnUpdate method to that runs when the event is invoked . . .

rich adder
thorny fern
#

both

rich adder
#

look into pooling
probably would do that first before jumping straight into multi-thread / jobs esp in the beginning

wraith phoenix
rich adder
#

you dont have to exactly understand the details on how it works

#

just passes specfic data "grouped up" the way its expected

#
public event Action MyAction;
 public event Action<int> MyActionWithInt;
 void Foo()
 {
     MyAction += Bar;
     MyActionWithInt += Bar; // gives error because bar is missing expected int in signature 
// void Bar (int theValue) {}
 }
 void Bar()
 {

 }```
cosmic dagger
cosmic dagger
autumn pine
#

Alright so im getting a null reference exception when trying to use OnDisable() and I think im tracing it back to this.enabled not existing

#

but it does exist

rich adder
#

cant be this

polar acorn
#

!code

eternal falconBOT
rich adder
wraith phoenix
autumn pine
cosmic dagger
autumn pine
rich adder
polar acorn
#

It is a variable of type InputAction.CallbackContext named ctx

autumn pine
rich adder
autumn pine
#

ghostchase is a subclass of ghostbehaviour

polar acorn
autumn pine
#

which contains the Enable method

wraith phoenix
#

Or just "Context"?

rich adder
#

or just Context

polar acorn
cosmic dagger
rich adder
#

you can literally name it bananas and the compiler wont care

#

chungasAmogus lol

autumn pine
#

everything checks out when I look it over

wraith phoenix
rich adder
cosmic dagger
polar acorn
autumn pine
polar acorn
#

or a breakpoint

autumn pine
rich adder
#

before that line

#

same method

polar acorn
cosmic dagger
earnest helm
#

https://gdl.space/ipekejutag.cs
ive followed this movement script from a tutorial but im running into an issue where simple bumps or dips like in the photo means the player can't walk up them

rich adder
autumn pine
polar acorn
#

Or stop trying to use it if it's null

autumn pine
#

it shouldnt be null

#

im not sure why it is

polar acorn
rich adder
autumn pine
rich adder
#

oh my

polar acorn
# autumn pine

Does the object with the Ghost component on it have a GhostScatter component on it as well when it's created?

rich adder
#

and if you do check if this function running at all

autumn pine
polar acorn
rich adder
wraith phoenix
autumn pine
#

ill check and see if everything gets assigned

polar acorn
shell sorrel
cosmic dagger
shell sorrel
#

playerControls.Movement.Dash.started += PlayerDash

polar acorn
#

That is no longer valid

wraith phoenix
shell sorrel
#

also your -= to unsub before was not even working, since both times you are adding and removing functions you just created in that place

#

not the one you actaully defined permanently

autumn pine
cosmic dagger
#

as mentioned earlier, you need to use a method in order to sub and unsub correctly because an anonymous delegate (using a lambda =>) creates a method on-the-spot and therefore cannot be referenced to use later to unsubscribe . . .

polar acorn
# autumn pine yes it is assigned correctly

Then one of these situations is happening:

  1. You're checking it in OnEnable before awake runs
  2. The object with scatter set is not the same as the object you're checking in OnEnable
  3. Something is setting scatter to null between awake and OnEnable