#💻┃code-beginner

1 messages · Page 292 of 1

modest sluice
#

im tring to create a LSystemBrnachPrefab by dragging this asset into the LSystemBrnachPrefab object and i get "no monobehavior scripts in the file or their names do not match the file name"

uncut shoal
#

o yea I used 'MinMaxSlider'

#

How do I make it work

wintry quarry
uncut shoal
#

o I found it I think

#

'AllowNesting'

#

yep it works

#

the variables are starting to get a ridiculous amount of attributes on here

south sky
#

Wait can you explain this to me my brain is fried atm

#

So the Instantiate<foo>(foo original) returns the references of foo

#

The hell does that mean

wintry quarry
#

Instantiate returns the new object it created

#

It would be pretty lame if it didn't

south sky
#

So it destroys it as well or only returns the values of the object?

wintry quarry
#

why would it destroy anything

#

it creates a copy of the thing you fed in as a parameter

south sky
#

Thats the problem

wintry quarry
#

Why is that a problem?

willow scroll
south sky
#

Bc the player cant be fed as a parameter as the object I want to instantiate is a prefab within a prefab

#

It wont let me

wintry quarry
south sky
#

Also

south sky
#

Ill try this time

raw kindle
#

Getting a cant find collider error even though it exists, I have 2 gameobject in the world both being under the "core class", I have code that loops through a list I made of the "cores" the first iteration goes well but I get the error on the second one even though they are perfect copies other than there index . If only one "core" exists no error is found https://gdl.space/edokayuxaj.cpp

wintry quarry
#

the first iteration goes well but I get the error on the second one even though they are perfect copies other than there index
Sharing the error you are receiving is always the best place to start

#

"an error" is vague

south sky
raw kindle
wintry quarry
tender stag
#

why is this happening?

wintry quarry
raw kindle
wintry quarry
rocky canyon
wintry quarry
wintry quarry
# south sky Cool cool

you wuill have to modify the example slightly since you're using GameObject instead of Transform and your script is not called Enemy, you called it something like DogEnemyAI

tender stag
raw kindle
wintry quarry
#

but other than that, it will work

wintry quarry
rocky canyon
south sky
tender stag
#

yeah

raw kindle
#

if (core.Object.GetComponent<CompositeCollider2D>().IsTouching(_object.gameObject.GetComponent<BoxCollider2D>()) & !_object.Stuck)

tender stag
#

its like it doesnt exist

wintry quarry
#

my thing was just an example

#

using example names

rocky canyon
tender stag
wintry quarry
rocky canyon
#

thnk

wintry quarry
raw kindle
#

but its child has one

wintry quarry
#

your code is asking for a BoxCollider2D

#

if you want the thing from the child, you'd have to get it from the child

raw kindle
#

oh wait sorry I give wrong info

#

_object.gameobject is boxcollider, core.object... is composite collider

rocky canyon
#

when all 3 are in the variable list

tender stag
#

im gonna try this

raw kindle
#

oh wait one moment

tender stag
#

@rocky canyon

#

but still

#

weird

rocky canyon
#

good good.. idk sometimes third party assets just be like that

#

probably needs to set via a function b/c it has to do other things in the package for it to work out correctly

meager crow
#

hello, i have been trying to acess rigidbody from my script but there is just no sign of iit, any help?

wintry quarry
#

!ide

eternal falconBOT
south sky
#

Is the transform of an object public so can can i use foo = GetComponent<script> then foo.transform.position?

wintry quarry
#

because you can just do transform directly

south sky
#

Oh damn ddint knpw

#

Umm could you

#

You know

#

Show an example

wintry quarry
#

transform

#

that's the example

#

or someObject.transform

south sky
#

Lol

#

Cool

carmine sierra
#

!code

eternal falconBOT
meager crow
carmine sierra
#
  public float countdown; // Initial countdown time in seconds

    void Update() {
        if (countdown > 0) {
            countdown -= Time.deltaTime; // Reduce the countdown by the elapsed time
        }
        else if (countdown == 0) {
            
        }
        // Display the countdown time in seconds
        timer.text = countdown.ToString("F0"); // Rounded to whole seconds
    }

How can I make it so countdown rounds to the seconds (integers)

#

as currently just the text ui is rounded

slender nymph
#

why? you would typically only want the displayed value to be rounded

carmine sierra
wintry quarry
carmine sierra
#

but currently I can't get countdown at 0 since it skips to negative

slender nymph
#

don't check if it is exactly 0, just check if it is equal to or less than 0

carmine sierra
#

okay cool thanks

slender nymph
#

in fact, you don't even need the second condition, just use else

wintry quarry
meager crow
wintry quarry
meager crow
#

no rigidbody showing.

wintry quarry
#

Your IDE isn't successfully configured yet

#

you have to follow all the steps

meager crow
#

and checekd if its a proper version or not.

#

but I still cant see it.

slender nymph
#

any errors in vs code's console? and if not, have you regenerated project files?

carmine sierra
#

how can I get a bool value from another scene?

#

ddol doesnt work apparently?

wintry quarry
#

DDOL works fine

rocky canyon
#

you cant grab a value from a different scene

wintry quarry
#

"scenes" don't hold values

#

scens have objects in them, and those objects have scripts on them, and the scripts can hold values

carmine sierra
#

public void NextScene() { //Runs on the click of the button
SceneManager.LoadScene(nextScene); //Loads the next scene
player2Turn = true;
DontDestroyOnLoad(player2Turn);
}

#

so whats wrong with this?

#

ohh right mb

#

ddol is for gameobjects

wintry quarry
#

yeah you can't just DDOL a bool lol

carmine sierra
#

if i say ddol gameobject is that the script's object or just the script

#

i just want the script

wintry quarry
#

What do you think

carmine sierra
#

the objectg

wintry quarry
#

DontDestroyOnLoad(gameObject) < pretty clear what's being DDOL'ed here

carmine sierra
#

no clue

wintry quarry
#

it wouldn't make sense to DDOL just a script. Scripts have to be attached to GameObjects at all time

carmine sierra
#

oh ok

wintry quarry
#

Is the script being passed in, or the object?

viral hemlock
#

Quick question, is it possible to have multiple camera angles in a 2d game?

wintry quarry
viral hemlock
wintry quarry
#

that's up to you. There are many ways I could imagine it working

#

"2D game" is also pretty loosely defined

#

Have you ever heard of Fez?
https://www.youtube.com/watch?v=lrEsNI0aCPk

Explore a serene and beautiful world full of secrets, puzzles and hidden treasures in FEZ, available now on Nintendo Switch! Learn more: https://www.nintendo.com/games/detail/fez-switch

#FEZgame #IndieWorld #NintendoSwitch

Subscribe for more Nintendo fun! https://goo.gl/HYYsot

Visit Nintendo.com for all the latest! http://www.nintendo.com/
...

▶ Play video
karmic kindle
carmine sierra
#

is there a way to move all instances of a prefab into one gameobject, so that they can be grouped, and moved to the ddol scene, so they can be loaded again when the scene is re-loaded

rare basin
#

parent them

#

and set the parent as ddol

carmine sierra
#

also how would you instantiate objects into that particular gameobject

#

rather than straight into the hierarchy

summer stump
#

If you look at the docs, one takes a parent parameter

lunar fern
#

why is my player not moving when he should. when i press any of the wasd keys the transform changes but i still dont move. if you need a video i can send one. here is the code: https://gdl.space/igoxafubol.cs

rancid tinsel
ivory bobcat
wintry quarry
#

nor into this input handling bit:
Input.GetAxis("Horizontal") * (1000 / 10 + (Input.GetAxis("Horizontal") * -100)) * Time.deltaTime

#

you're multiplying so much deltaTime in here your forces are absolutely tiny

#

there is no need for deltaTime adjustment with AddForce, least of all in FixedUpdate

#

Also isn't 1000 / 10 just 100? Why not just write 100

#

this is very strange

#

Vector3.ClampMagnitude(rb.velocity, MaxSpeed*Time.deltaTime); < you also don't want it in the clamp here

lunar fern
#

idk im learning unity and my brain has gone caput for the last week

wintry quarry
#

you are throwing deltaTime in a lot of places randomly

#

it doesn't belong in any of these places

lunar fern
#

ill try and fix it upp a litle with the delta time's and se if it works

wintry quarry
#

remove all of them

#

and all of the magic numbers

lunar fern
#

what magic numbers?

wintry quarry
#

(1000 / 10
* -100)
* 100;

lunar fern
#

oh ok

wintry quarry
#

most of thiose are just being cancelled out by deltaTime anyway.

#

Strip this down to almost nothing

#

simplify it

#

then build off a simple working foundation

ivory bobcat
#

Log stuff and see what's happening

carmine sierra
#

1code

#

!code

eternal falconBOT
carmine sierra
#
 [SerializeField] bool player2Turn;

    void Start() {
        player2Turn = GameObject.FindGameObjectWithTag("player2turn");
        if (player2Turn == true) {
            Camera.main.transform.position.x = 44.6f;
        }
    }

why does the camera's position not change

carmine sierra
south sky
#

This code nono work and i dont understand why. I touch the enemy and they dont ge tdestroyed

lunar fern
summer stump
wintry quarry
south sky
lunar fern
south sky
wintry quarry
summer stump
wintry quarry
#

Note that Collision is not the right parameter type

south sky
#

Thanks

#

I love you man

carmine sierra
wintry quarry
#

it will not compile

carmine sierra
wintry quarry
#

Look at your console window

#

you have a compile error, no?

summer stump
wintry quarry
#

That's actually not the problem

#

it's the assignment

#

You can't modify an anonymous copy of the position vector that will be forgotten instantly

ivory bobcat
wintry quarry
#

You need to do e.g.

Vector3 pos = Camera.main.transform.position;
pos.x = 44.6f;
Camera.main.transform.position = pos;```
carmine sierra
wintry quarry
#

no

#

it has nothing to do with the number of full stops

carmine sierra
#

so why does pos.x need to be split up

#

can it not be pos.x = 44.6f;

wintry quarry
#

when you do transform.position it is a property that returns a COPY of the position vector

#

you are not saving that copy anywhere

#

so changing the x of that copy will be useless

ivory bobcat
carmine sierra
#

okay so basically can't edit the camera's transform without saving it's position as a variable first?

summer stump
#

You can't modify a component of its position
Only change the whole thing

carmine sierra
#

Vector3 pos = Camera.main.transform.position;
pos.x = 44.6f;

wintry quarry
#

beause pos is a copy

ivory bobcat
# carmine sierra okay so basically can't edit the camera's transform without saving it's position...

Properties are short handed getter and setter methods for backing fields. Assigning directly to the property is valid. Reading the value of the property is valid. As you access the x component of the vector 3 from the position property, you're invoking the getter and only receiving a copy of the back field (the actual vector 3). If you want to modify the back field, you'll need to assign a value (vector 3 in your case) to the position property as a whole - modifying a component of the returned position will throw an error as the value returned isn't a variable.

rancid tinsel
ivory bobcat
#

See why it's picking one over the other - assuming it's alternating or simply moving towards the wrong destination

rich adder
#

@rocky canyon aw yeah new update.
We are back !

rancid tinsel
rancid tinsel
#

ok i fixed it not changing directions properly

#

but when it reached the patrolPoints[0] path, it starts moving towards patrolPoints[1] extremely slowly

#

same thing happens when it tries to move to patrolPoints[0] again after reaching patrolPoints[1]

rocky canyon
rich adder
rocky canyon
#

aye

#

when i Restart to download i thought it was just the program

#

my screens went black and then my data light just blinked over and over..

#

scared me for a second

rich adder
#

😮

rocky canyon
#

it was in limbo until i pressed my space key.. and then the monitors came back on.. and the Updated Readme was on VSCode

#

scary stuff lmao

#

my computer doesnt do well with Restarts anyway

rich adder
#

that would bug me, but only because my laptop is close to death Gpu wise

rocky canyon
#

sometimes i have to hard-shutdown even during Windows Updates

#

cuz it'll get hung between the boot loader and windows

rich adder
#

haha yeah never have any problems on macos. Wind kinda blows

rocky canyon
#

microsoft for life..

rich adder
#

even Microsoft employees use macbooks UnityChanLOL

#

watch their live streams

rocky canyon
#

nah i believe u

rich adder
#

always tell the truth even when i lie

modest sluice
#

when i create this object, i intend to copy the transform of LSystemBranchPrefab, LSystemBranchPrefaband Base are both at 0,0,0.
it keeps putting the clone at (35.38,-0.06,2.57)
https://hastebin.com/share/wohiquqaji.java

wintry quarry
modest sluice
#

i dont think so they should both be 0,0,0

wintry quarry
#

You are using Transform newPlant = Instantiate(plantPrefab, transform.position, Quaternion.identity, transform);
So transform.position is what's being used as the position.

rich adder
wintry quarry
#

but you're also making it a child of this object so it should be 0,0,0 local position but possibly not in world space

#

Where are you seeing the (35.38,-0.06,2.57)?

modest sluice
#

everything is a t 0,0,0 in my scene

rich adder
#

yeah if ur parenting u want localPosition

modest sluice
dusk musk
#

Hey everyone! I'm learning about Inheritance and Polymorphism. I thought I understood, but when setting up something simple to test the principle, my game does not behave as expected. Would someone mind to help me? 🙂

I have a CubeParent object with a CubeParent script, and a CubeChild with a CubeChild script. The CubeParent script contains two public virtual void methods, which are called in the Update and Start methods.

The CubeChild script calls those 2 parent methods in its own Start and Update scripts. I'm currently not overriding anything.

Strangely enough, my 2 objects do not behave the same.

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

public class CubeParent : MonoBehaviour
{
    public virtual void cubeProperties()
    {
        transform.position = new Vector3(-2, .5f, -2);
        transform.localScale = new Vector3(2, 2, 2);
    }

    public virtual void cubeMovement()
    {
        transform.Translate(Vector3.forward * 1 * Time.deltaTime);
        transform.Rotate(Vector3.up * 10 * Time.deltaTime);
    }

    private void Start()
    {
        cubeProperties();
    }

    private void Update()
    {
        cubeMovement();
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CubeChild : CubeParent
{

    private void Start()
    {
        cubeProperties();
    }

    private void Update()
    {
        cubeMovement();
    }
}

And here's a video of game.

rich adder
#

😮

wintry quarry
rancid tinsel
modest sluice
rancid tinsel
#

its saying object reference not set but very clearly is in the inspector and was working fine a second ago

rich adder
carmine sierra
#

how do i instantiate an object and assign it a parent?

#

woodInstance = Instantiate(woodPrefab, placeholder.transform.position, Quaternion.Euler(0, 0, rotation), woodParent.transform);

this is what i tried

rich adder
rancid tinsel
carmine sierra
#

but why does it need to be a transform

rich adder
wintry quarry
# modest sluice

That's a different script. The script you sent was LSystemBranch
this is LSystem

wintry quarry
rancid tinsel
rich adder
rancid tinsel
#

got rid of it and the issue is gone

modest sluice
wintry quarry
carmine sierra
rancid tinsel
carmine sierra
#

but i assigned it in the inspector but it still gives me a reference error, saying it is unassigned

wintry quarry
#

prefabs live in your project folder, not the scene

modest sluice
wintry quarry
rich adder
modest sluice
meager crow
#

why cant i find the create physic material option?

rancid tinsel
rich adder
wintry quarry
meager crow
#

xD

#

w8

#

i think i know why...

rich adder
meager crow
#

ye ik

#

anyways ty

wintry quarry
carmine sierra
# wintry quarry Show the full error message - including filename and line number

UnassignedReferenceException: The variable woodParent of SpawnWood has not been assigned.
You probably need to assign the woodParent variable of the SpawnWood script in the inspector.
UnityEngine.Object+MarshalledUnityObject.ThrowNullExceptionObjectImpl (System.Object obj) (at <d0f92ebb771e4783b0ea9f13bfbe129b>:0)
UnityEngine.GameObject.get_transform () (at <d0f92ebb771e4783b0ea9f13bfbe129b>:0)
SpawnWood.PlaceOnClick () (at Assets/Scripts/SpawnWood.cs:71)
SpawnWood.Update () (at Assets/Scripts/SpawnWood.cs:43)

dusk musk
rocky canyon
#

this smells wrong

wintry quarry
#

otherwise - your code is setting it to null

rancid tinsel
wintry quarry
#

so it's basically running twice on that object

rocky canyon
#

wood (1) looks like it may be an instance of wood

dusk musk
rich adder
wintry quarry
rancid tinsel
rich adder
#

Oh Patrol is not in coroutine.

rancid tinsel
#

yeah

carmine sierra
rocky canyon
#

ahh

rich adder
# rancid tinsel yeah

these indexes should be dynamically changed btw, not sure hard coding index is good idea
are you sure patrolPoints[1].position is correct ? Inspect the agent gizmos during playmode, see where the red destination is set to

rocky canyon
wintry quarry
rich adder
#

t:scriptname

#

in the hierarchy

carmine sierra
rancid tinsel
#

ill check the gizmos now

dusk musk
# wintry quarry my guess was actually that you would have put BOTH child and parent on it. Not t...

Haha could've definetely happend too! Would you mind helping me with one more thing? I have now added an override. My parent method has 2 lines. I only want to override 1 line, and keep 1 line the same. Should I ONLY write the line I want to change? And will the line I don't change, still work? Because now I have only added 1 line in the override, and it seems the line I don't want to override isn't being taken into account.

The child script:

    public override void cubeProperties()
    {
        transform.position = new Vector3(2, .5f, 2);
    }

The parent script:

    public virtual void cubeProperties()
    {
        transform.position = new Vector3(-2, .5f, -2);
        transform.localScale = new Vector3(2, 2, 2);
    }

When I start my game, the localScale isn't updated on Start in my child object.

rancid tinsel
#

if yes then it seems to be working fine

rich adder
#

ok so the destination is set correctly , its just not going there?

rancid tinsel
#

it is but incredibly slowly

rich adder
#

or very slow at least

rancid tinsel
#

yes

#

and i tested it earlier and it does the same thing if it reaches the [1] point

#

and goes back to [0]

wintry quarry
rancid tinsel
#

so it seems to be a case of after reaching the first point it breaks

rich adder
#

I wonder if its because the SetDestination is being spammed over and over, I recall last time it give me similiar issues adding it to Update\

wintry quarry
rich adder
#

navmesh agent was never like that before, but I think they changed something. Gotta test it again been a while

rancid tinsel
rich adder
dusk musk
rancid tinsel
#

which is why im trying with vector3.distance

rich adder
#

yeah like if(distance <= agent.stoppingDistance + 0.4f) SetNewDest

#

I add a bit of threshold to agent.stoppingDistance cause sometimes it doesn't stop at its stopping distance precise

rancid tinsel
#

whats the distance variable?

rich adder
#

Vector3.distance

rancid tinsel
#

ah okay

rich adder
#

from agent to destination

rancid tinsel
#

and im assuming that would be assigned in update

rich adder
#

yeah ideally u want V3.Dist to run every frame

#

or in my case I do everything in coroutines

rancid tinsel
#

so like this if i understand it correctly?

#

obviously falls apart if i was to add more patrol points but i dont think i will be

rich adder
#

but yeah like you said because ur hard coding index

rich adder
rancid tinsel
#

i was gonna say, it broke 😭

rich adder
rancid tinsel
rich adder
#

the agent.dest ==
might be messing with it

rancid tinsel
#

yeah cuz i think the floating points dont match

rich adder
#

again I just increase indexes is cleaner

#

nah Vector3s have approximation

#

for equality check

#

they're just probably too far when that runs

rancid tinsel
#

for some reason since i implemented your distance thing, it now rotates the object around the x axis?

#

no idea why

#

this was the bit for rotating

rich adder
#

uhh that transform.up don't look right

rapid mountain
#

u can use stopping distance and remaining distance

rich adder
#

wouldn't that be transform.forward?

rancid tinsel
#

forward ends up with this

#

since its a 2D project im guessing

rich adder
#

wait ur in 2D?

carmine sierra
#

balance = MoneyManager.p1Balance;
..
balance -= MoneyManager.TriShot_Price; //Subtracts the tri-shot price

what reason could there be for the balance in the moneymanager script to not be subtracted

rancid tinsel
#

yes

rich adder
#

oh its topdown, ok I see why you mean

rancid tinsel
#

no but its a unity 2D project

rapid mountain
rancid tinsel
#

let me link what I used for 2D navmesh one sec

rich adder
rancid tinsel
#

and followed a tutorial with it let me find it

rich adder
#

ohh the 2D navmes extension

rancid tinsel
rapid mountain
eternal falconBOT
rancid tinsel
#

i think i followed this one

#

but either way it seems to be following the same extension

rich adder
#

Id try cleaning up the index part first, just incase

rancid tinsel
hushed hinge
#

look at the warning at the corner, I tried to make this ui image into a child so i can have it come along into the next scene when the white image is fading away instead of making it look like it just disappear immediatly when i go over to the next scene but something is not working, how can i turn the ui image object into a child for uicontainer gameobject?

summer stump
rancid tinsel
#

i did this for index, not sure if thats what you meant

rapid mountain
rich adder
#

transform.up is fine

rich adder
#

no need for if else

#

h/o ill show u example

carmine sierra
#

cause it was working before

#

unless i changed it

summer stump
#

It is a separate thing

carmine sierra
#

what does that mean though

summer stump
summer stump
#

Balance will not affect the variable in MoneyManager at all

carmine sierra
#

yeah since i changed that it stopped working

#

so the reference doesnt affect the OG

summer stump
#

This is a difference between value and reference types

summer stump
carmine sierra
#

true you told me this many times

#

just feels like it defies logic a bit

rapid mountain
carmine sierra
#

but computer logic is diff

summer stump
# carmine sierra just feels like it defies logic a bit

If you named it balanceAtThisPoint that would make more sense?
Like, if you need to know what it was before some change so you can revert it, then balance is useful
Otherwise, having the balance variable doesn't really make sense

carmine sierra
#

just used it to clean up code

dusk musk
#

@wintry quarry Can I ask you one more thing about inheritance/polymorphism? Question is: should I include declarations like "public float speed =..." or "private GameManager gameManager" in the child script - or will they also be inherited?

rapid mountain
rich adder
#

sorry I took a bit was making dinner

#

You prob dont need the magic 0.4

rancid tinsel
#

its alright dw

rapid mountain
rancid tinsel
wintry quarry
rancid tinsel
#

the agent unfortunately does stop moving though

#

i genuinely have no idea what might be causing it

rich adder
wintry quarry
rapid mountain
rapid mountain
rancid tinsel
rich adder
#

You should not be using rigidbody on navmesh agent

rancid tinsel
#

yeah i assumed so

rich adder
#
public class Agentmove : MonoBehaviour
{
    [SerializeField] private NavMeshAgent agent;
    [SerializeField] private Transform[] patrolPoints;

    private int currentPointIndex;
    private void Update()
    {
        if (agent.remainingDistance <= agent.stoppingDistance)
        {
            currentPointIndex = (currentPointIndex + 1) % patrolPoints.Length;
            agent.SetDestination(patrolPoints[currentPointIndex].position);
        }
    }
}```
rancid tinsel
#

just double checking

#

ok i got rid of setdestination in start

#

it moves again

#

but very slow

rich adder
#

you remove the rigidbody ?

rancid tinsel
#

yes

#

i only had it in for a second tho to test

dusty silo
#

Can someone explain why my Debug.DrawLine calls are not working?
T,F,Tmmand Tm are custom classes but can be implicitly converted into Vector2 or Vector3

if (Geometry.intersect(F, T, Tmm, Tm)) {
                    Debug.Log($"<b><color=#FF0000>Line follow-tail {Geometry.color($"[{F.ToString}-{T.ToString}]", Geometry.EdgeColor)} intersects line Tmm-Tm{Geometry.color($"[{Tmm.ToString}-{Tm.ToString}]", Geometry.EdgeColor)}</color></b>");
                    Debug.DrawLine(F, T, Color.red, 100f);
                    Debug.DrawLine(Tmm, Tm, Color.red, 100f);
                }```
dusk musk
# rancid tinsel could you post what you did with yours? also are you using a rigidbody at all?

Of course! Here is my currenet parent class.

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

public class CubeParent : MonoBehaviour
{
    //Scoring
    private GameManager gameManager;
    private int value = 10;

    //Enemy speed variable
    private float speed = 1.0f;

    //Find enemy Rigidbody
    private Rigidbody enemyRb;

    //Find player GameObject
    private GameObject player;

    public virtual void Scoring()
    {
        gameManager.UpdateScore(value);
        Debug.Log("Score added = " + value);
        Destroy(gameObject);
    }

    public virtual void Movement()
    {
        Vector3 lookDirection = (player.transform.position - transform.position).normalized;
        enemyRb.AddForce(lookDirection * speed);
    }

    public virtual void CubeSettings()
    {
        gameManager = GameObject.Find("Game Manager").GetComponent<GameManager>();
        enemyRb = GetComponent<Rigidbody>();
        player = GameObject.Find("Player Main Camera");
    }

    private void Start()
    {
        CubeSettings();
    }

    private void Update()
    {
        Movement();
    }
    private void OnMouseDown()
    {
        Scoring();
    }
}

And my child script is empty, and I think everything behaves exactly like the same:

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

public class CubeChild : CubeParent
{

}

The thing I'm now goign to experiment with, is making changes, and seeing if I have to repeat the declerations.

rapid mountain
rancid tinsel
dusk musk
dusty silo
rapid mountain
hushed hinge
rancid tinsel
#

im trying to change rotation like this now but im still getting 90/-90 in x even though im setting agent.updateRotation to false

summer stump
rich adder
eternal needle
rich adder
#

and are you sure your pivots are correct too

hushed hinge
rancid tinsel
dusk musk
#

@wintry quarry Back again. Would you mind helping me one more time? In my parent script I have a private integer value. In the Scoring method I set this integer to 10.

Now in my child script, I want the value integer to be 5.

However, MSFT VS gives this error: "'member' is inaccessible due to its protection level"

What should I do?

Parent script: https://gdl.space/iwuveqesem.cs
Child script: https://gdl.space/lijamolilu.cs

rancid tinsel
#

if im setting x to 0 why would it change it to -90 or 90

wintry quarry
languid spire
hushed hinge
rich adder
eternal needle
dusk musk
# wintry quarry It needs to be `protected` to be accessbile from the child

Thank you - that worked. I guess that didn't fix everything yet. In my child script, the value added is still the parent value, not the child value.

here's my child script:

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

public class CubeChild : CubeParent
{
    public override void Scoring()
    {
        base.Scoring();
        value = 5;
    }
}

Any more advice you can share? Much appreciated.

dusk musk
rancid tinsel
rancid tinsel
summer stump
rich adder
rancid tinsel
#

thats the issue im having

#

im only trying to rotate on z, but it changes x anyway

rich adder
#

you wrote -90 in the inspector

rancid tinsel
#

that was to show an example

rich adder
#

oh.

rancid tinsel
#

of how the 2 rotations arent the same

rich adder
#

did you try the line from earlier too

rancid tinsel
#

the Quaternion.Euler?

rich adder
#

ya

wintry quarry
rancid tinsel
#

yeah, it has the same result

rich adder
wintry quarry
#

(even having a field here makes little sense)

rich adder
#

this is after rotated ?

rancid tinsel
#

here is out of playmode

rancid tinsel
hushed hinge
frigid sequoia
#

This is definitely not lasting 1 sec as intended, am I using Lerp wrong?

frigid sequoia
rich adder
#

all good!

rich adder
rancid tinsel
#

navarone to be completely honest, if the project is to just make a vertical slice so like 1 prototype level, would it just be simpler to scrap navmesh all together and do it script

#

oh but then id have to code obstacle avoidance myself

#

😭

rich adder
#

yup

summer stump
rancid tinsel
rich adder
#

if that doesn't work, try rotating without the Navmesh agent. See if thats somehow messing with it

#

although transforms rotation should override any navmesh agent component

rancid tinsel
#

or is it Space.World

hushed hinge
rancid tinsel
#

im assuming space.self since im changing its local rotation..?

hushed hinge
#

but the ui container is in canvas

rich adder
rancid tinsel
#

they both still result in x rotation being 90 or -90

#

transform.up method seems to work fine anyway idk what im doing

rich adder
#

ahhhhhhhhhhhhhhhh

summer stump
# hushed hinge

Oh, ok. Ddol won't work then
Cant't ddol a child
If the parent is NOT in ddol, it gets destroyed, along with all its children

rich adder
#

thats probably why @rancid tinsel

#

you still have transform.up =

rancid tinsel
#

i had it removed

rich adder
#

you're getting some weird gimbal lock

#

oh

#

well nvm that then

rancid tinsel
#

and only used it for chasing player

#

maybe the reason it slows down/stops after reaching the point is to do with the agent settings i have?

rich adder
#

you tried the without the navmesh agent thing ?

hushed hinge
summer stump
rich adder
frigid sequoia
#

Ok I have like kinda of a complex question now. How can I tell a bullet that it has already hit an enemy and it cannot hit again?

rich adder
#

or you could probably pass a Physics.IgnoreCollision after

#

dependig what ur doing

rancid tinsel
#

what if i used normal movement for patrolling and then navmesh for chasing the player?

#

i think that could work and be way simpler

frigid sequoia
frigid sequoia
rich adder
rancid tinsel
#

it works completely fine for chasing the player/returning to the start position

rich adder
rancid tinsel
#

it just breaks when changing between the patrol points

frigid sequoia
summer stump
rich adder
#

verify its working by checking playmode if they are in separate scene called DDOL

dusk musk
dusk musk
summer stump
# hushed hinge like this?

This is certainly not what I said to do, and it is so crapped that it shows nothing useful
Please stop cropping things so much (as I've said so many times)

hushed hinge
summer stump
languid spire
hushed hinge
dusk musk
languid spire
#

of course not becaue the first thing you do in the parent script is set value back to 10

lone iris
#

Im trying to make a 2 fighting game (smashbros-like) and i have no idea of how i could make the knockback system

dusk musk
hushed hinge
# hushed hinge oh

it seems like the image is like behind the other canvas image but the white image doesn't even fade away

summer stump
#

Gotta use sorting layers though

languid spire
dusk musk
smoky jetty
#

So I'm kind of learning the hard way, now that my project is getting bigger, the importance of decoupling code. I have a player and I have UI elements like a spedometer and a boost meter. These UI elements read data from a script on the player every frame, like the player's speed or their "boost amount." So the UI elements are grabbing a reference to the player, which is tightly coupling the two. So I want to now learn how to decouple my UI and player, but I'm struggling to find out the best way. I think events are generally frowned upon if its data pretty much being changed every frame. Any other good solutions out there for this kind of thing? Or are events perfectly ok?

hushed hinge
summer stump
wintry quarry
#

UI listening to the state of some other object is the perfect use case for events

smoky jetty
#

I see, even if data is being updated every frame? Like for a spedometer? if that's the case, I'll try out events

wintry quarry
#

yes

smoky jetty
#

very cool, ty! 👍

wintry quarry
#

I mean the other option is just having the Ui script read it from the player object each frame

#

the referential consequences are the same

#

the UI references the player

#

the important thing is the player shouldn't reference the UI

hushed hinge
deft quarry
#

Hey all! Whenever I move, my camera jitters, it's not smooth, and I can't bring myself to move on without fixing it. Im sorry for sounding like a broken record since I know this problem comes up a lot, but ive searched through several forums and other answers and nothing seems to work. Can someone please help?

(I am new to unity by the way)

PlayerMove Script : https://gdl.space/kizodiqeri.cpp
CameraMove Script : https://gdl.space/calahopeba.cpp
CameraControls Script : https://gdl.space/ahevasitej.cpp

carmine sierra
#

if i duplicate a script into another object, if I change some code, will it change it on both objects

#

i feel like this is an obvious question

#

but would I need to make another script for this other object

#

and then change what I want

willow scroll
wintry quarry
carmine sierra
#

ctrl d

#

on the object with the script inside

willow scroll
carmine sierra
#

so i need to make the name different?

#

make a new script

#

and copy and paste

untold raptor
#
if (Input.GetKeyDown(KeyCode.F)){
            if (canpickup){
                if(obj){
                    itemData = obj.GetComponent<ItemData>();
                    foreach (GameObject slot in inventorySlots){
                        Image img = slot.GetComponent<Image>();
                        img.sprite = itemData.icon;
                    }
                    Destroy(obj);
                }
            }
        }```

the icons that exist already I placed, for some reason the icons arent setting (ItemData.icon is a sprite)
wintry quarry
carmine sierra
#

well i want one script for player 2 and one for player 1

#

is there another common way of doing this

wintry quarry
willow scroll
wintry quarry
#

if they have the same gameplay, they generally should have the same scripts

carmine sierra
#

so i could use that

wintry quarry
untold raptor
#

yeah atm i am

willow scroll
carmine sierra
#

if i have the same script in two objects, can they each have different field references

wintry quarry
carmine sierra
#

oh okay this should be fine then

#

thanks

willow scroll
willow scroll
deft quarry
willow scroll
grim pecan
#

I imported an asset called DOTween for a FOV change for dashing but its not working?

wintry quarry
#

DOTween works!

#

can confirm

grim pecan
#

but whenever i do using DG.Tweening; it says theres nothing called DG

timber tide
#

convince me to download Dotween vs methods like MoveTowards, RotateTowards, and lerps

grim pecan
#

i only downloaded DOTween cause the tutorial i was following said to do it

willow scroll
#

Camera movement

wintry quarry
grim pecan
#

i probably didnt

wintry quarry
#

or you're typing that in the wrong place

grim pecan
#

how would you import DOTween

#

its showing it in the plugins

wintry quarry
timber tide
#

seem alright I guess if you don't want to shove everything into update, but then you got coroutines too

#

probably end up using it for some card UI interaction stuff though

grim pecan
copper sable
#

ello, made a lil script and attached it to my camera object, but it's not working.
so it's a script for a third-person camera (so it follows my player), but when i play the game it's not exactly third-person.
any help?

using UnityEngine;

public class CamFollowPlayer : MonoBehaviour
{

    public Transform player;

    // Update is called once per frame
    void Update()
    {
        transform.position = player.transform.position + new Vector3(0, 1, -5);
    }
}
grim pecan
#

theres no utility panel that i can find in either one of them

rare basin
#

Just importing it won't do

grim pecan
#

where is the dotween panel

rare basin
#

Tools and Demignant

grim pecan
#

where is tools and demigiant

grim pecan
rare basin
#

its not in files

#

Tools tab at the top bar

#

and then Demignant

grim pecan
#

cant find anything called the tools tab

#

im might be dumb but where is it

thorn tapir
grim pecan
thorn tapir
#

you didn't install dotween correctly then

#

delete it and make sure you install it from the package manager

#

and ensure that it's compatible with whatever unity version you're using

rare basin
#

yes, dont drag&drop the files

#

actually import it from package manager

quick kelp
#

whats the simplest way to save scenes

dapper forge
#

What u mean with Save scene ?

quick kelp
#

like the player exits a room and it saves the scene

dapper forge
#

an easy way is to save it local

#

There are many tutorials on youtube just type unity save/load

summer stump
quick kelp
#

alrighty i'll look into it

#

thanks

fast swan
#

are there any vc in this server?

#

i need help with sliding mechanics

slender nymph
atomic sierra
#

do you guys use any websites to organize your ideas for a new unity project?

#

because whenever i want to practice unity, i always start on a blank slate and make new features as i go without every planning ahead

#

its easier to making simple coding projects bc u can always build onto them, but with unity its a lot harder to me

young fossil
atomic sierra
young fossil
# atomic sierra but how do you avoid making your project end up being really convoluted?

It's a massive subject. It's called software engineering. Depending on what context you make games for, it could be something you absolutely require or just something that helps.

One concept that is echoed through software engineering is the concept of scale. If your project is going to be a small game, for example, a Mario clone with just three levels. Then the requirement for planning is significantly less.

But if the plan is to ship a game with many features and you're working in a team of people. All of a sudden the engineering aspect becomes incredibly important

atomic sierra
#

so what about for the purpose of practicing and wanting to add more and more features?

young fossil
#

What is your end goal. Then you decide what amount of planning you need

atomic sierra
#

oh i c. well i do want to grow adept at using unity. but maybe more into 2d development like building platformers or roguelikes.

#

also learning 3d wouldnt hurt either. idk

young fossil
atomic sierra
#

for fun

#

but also for the purpose of selling them too

#

but as of right now its just for fun

young fossil
#

Then I'd say learn the very basics if you are working on your own.

Here's some tools I recommend:
Easier stuff I'd recommend now

  • SimpleNote, this is a basic note taking app that works on mobile and PC. Totally free.
  • Mircosoft To-Do, this works on Windows and mobile. You can do a to-do list, very simple and easy.

These are for later, maybe bookmark them

  • Trello, this is a very famous website for planning. Sort of like a To-Do list.
  • Obsidian, this is basically more complicated but has lots of features for planning, graphing and making things look nice (tag systems, markdown, etc)

As for the actual planning, you create a concept of the game (you already have some ideas, platformers or roguelikes for example)

Then you write down each component. Start big, break into smaller bits.

atomic sierra
#

i appreciate the insight jack, thanks

young fossil
#

So example

Will the game have combat?
If yes...

  1. Will the combat be shooting?
  2. Will the combat be fighting?
  3. etc etc

Then you start to get to the code planning. Just do this and see what works

#

If you incorperate a bit of planning into your projects, you will get better and better overtime.

atomic sierra
#

oh i c, thanks a lot for the advice i never thought it out that way as im pretty new to this sort of stuff

carmine sierra
#

if (weaponsCollider == weaponFire.weaponInstance.GetComponent<Collider2D>())

im getting no syntax errors but this doesnt seem valid

eternal falconBOT
summer stump
summer stump
carmine sierra
modest sluice
#

im having difficulty setting the material to the Default-Diffusion

        public Renderer ren;
        public Material mat;

        void Start()
        {
            GameObject BaseGO = new GameObject();
           
            BaseGO.AddComponent<UnityEngine.MeshRenderer>();

            ren = BaseGO.GetComponent<Renderer>();
          //  mat = ren.materials;
            mat = new Material(Shader.Find("Diffuse"));
          //  ren.materials = mat; 
young fossil
#

I want to make a pause game feature inside my GameManager. Right now I am using Action<bool> OnGamePaused How do I make my event observable for changes?

summer stump
#

With what?

#

Debug that find is getting the right object

#

Find is usually very brittle and should pretty much NEVER be used

whole idol
carmine sierra
#

!code

eternal falconBOT
summer stump
carmine sierra
#

Anyone able to read this?
https://paste.ofcode.org/NzykMeNnjb2PupFVdkSuWF
I have two origin positions, my question is, how could I get the origin's position, and then insert it's x and y values into my nested for loop, when generating each player's building grid? Thanks, if you need anymore context I can explain.

modest sluice
summer stump
#

I'm not really sure what you're asking at the end there

But a serialized reference would avoid the need to care what the name is at all. Generally, if you are checking the name of an object for logic reasons, something is going wrong.

wintry quarry
#

although I guess for Renderer it's guaranteed

#

This was CGPT generated though so of course it's shite

cosmic dagger
young fossil
#

ChatGPT seems to just ignore good practices. So annoying

summer stump
#

As I said, names should not be relevant here at all. Stop using find

young fossil
#

Spits out convoluted code for something really simple

summer stump
#

Drag the object you want into the field in the inspector

modest sluice
cosmic dagger
summer stump
#

That is almost always the most preferable way to do it

young fossil
summer stump
#

Make a singleton

modest sluice
summer stump
#

And look into additive scene loading

cosmic dagger
summer stump
#

Generally you only HAVE one (renderer), of course

cosmic dagger
cosmic dagger
#

I may have misread that . . .

crisp dew
#

Hi there, I'm creating an angry birds clone and have followed a tutorial to set up the basic gameplay. Now I'm feeling stuck in tutorial hell. I'd like to add some abilities like explode on impact or altering the mass but don't know what questions to ask. Does anyone know what concepts, videos, or articles I should look into to begin?

cosmic dagger
carmine sierra
carmine sierra
summer stump
#

It definitely gets that way. That's why avoiding bad practices like find is so important. It takes longer to get going when you set things up properly, but it makes it scale SO much more easily.

Reduce dependencies
Divide responsibilities

Those two can seem to run against each other, but they are very important

carmine sierra
#

!code

eternal falconBOT
carmine sierra
#
GameObject origin;
    Vector3 originPos;
    [SerializeField] bool player2Turn;
    void Start() {
        player2Turn = GameObject.FindGameObjectWithTag("player2turn"); // Finds the gameobject containing the script with the player2turn bool
        if (!player2Turn) {
            origin = GameObject.FindGameObjectWithTag("Origin");
            originPos = origin.transform.position;       
        } else {
            origin = GameObject.FindGameObjectWithTag("Origin");
            originPos = origin.transform.position;
        }
        originPos = origin.transform.position;
        GenerateGrid();
    }
    void GenerateGrid() {
        int origin_X = originPos.x
        int origin_Y = 
        if (!player2Turn) {
            for (int x = ; x <= width; x += 3) {
                for (int y = 0; y <= height; y += 3) {               
                    x_Pos = (x / 10f) - 0.15f;
                    y_Pos = (y / 10f) - 0.15f;
                    GameObject spawnedPoint = Instantiate(pointPrefab, new Vector3(x_Pos, y_Pos), Quaternion.identity, pointParent.transform); //Instantiates a new point for each loop cycle
                    spawnedPoint.name = $"Point {x_Pos} {y_Pos}"; //Names each tile according to their tile co-ords
        }}}
        else {
            for (int x = 2; x <= width; x += 3) {
                for (int y = 0; y <= height; y += 3) {               
                    x_Pos = (x / 10f) - 0.15f;
                    y_Pos = (y / 10f) - 0.15f;
                    GameObject spawnedPoint = Instantiate(pointPrefab, new Vector3(x_Pos, y_Pos), Quaternion.identity, pointParent.transform); //Instantiates a new point for each loop cycle
                    spawnedPoint.name = $"Point {x_Pos} {y_Pos}"; //Names each tile according to their tile co-ords 
        }}}
    }
carmine sierra
summer stump
#

So, what was changed?

#

I still see Find

#

Did you rename the objects or something?

#

Also, why the double variables? FullscreenToggle and fullscreenToggle
PauseButton and uiPaused (that last one makes it sound like it should be a bool instead of an object)

red raven
#
public override void OnActionReceived(ActionBuffers actionBuffers)
    {        
        ActionSegment<float> continuousActions = actionBuffers.ContinuousActions;

        print(continuousActions[1]);
#

it keeps printing 0's

#

idk why

summer stump
red raven
#

wdym

#

its a value between -1 and 1? no?

summer stump
summer stump
red raven
#

R u asking me as in, think about it or what does it mean?

summer stump
red raven
#

do you not know or are you asking me to look it up again?

#

oh

summer stump
#

If it's from a package, you should say that

red raven
#

I wrote it in the summer

#

im back at it again

#

I must've miss guessed how the usage

summer stump
#

Look at it

#

What is ContinuousActions?

eternal needle
#

if u are unable to debug why a value is 0, i have doubts that you wrote these scripts...

summer stump
#

We are not mind readers, nor can we look at code you haven't shared

red raven
#

its from ML

#

I didnt write that part

untold raptor
#
if (Physics.Raycast(Camera.main.transform.position, forwardDirection, out RaycastHit hit, Mathf.Infinity, layerMask))  
        {
            hitPoint = hit.point;
            if (ghostBlock == null)
            {
                ghostBlock = Instantiate(buildingPrefabs[BlockID], hitPoint, Quaternion.identity);
                SetTriggersRecursive(ghostBlock.transform);
            }
            else
            {
                // Move the ghost block to the snapped position
                ghostBlock.transform.position = hitPoint + new Vector3(0, 0.7f, 0);
            }```
Any ideas why the block jitters back forth like that? (code snipped)
red raven
#

Sorry, I thought you'd understand with the screenshot

#

how many people name their stuff the exact same thing as the ML agents thing

summer stump
red raven
#

aah

#

ima just ask in unity talk

summer stump
summer stump
whole idol
#

My player's got a one-way ticket to the moon every time they jump, I asked earlier, someone said anonymous methods are lowkey bad and i shouldn't be using them the way i am rn in my lambda functions, but after looking at it for nearly half an hour i still don't see how that's related to my player being infected with this Jumpitis syndrome, but anyway here's the code abyss: https://gdl.space/egasezemew.cs
its kinda messy..

summer stump
#

I feel like the gravity is going weird, but it's really hard to follow honestly

wintry quarry
#

so off to the moon you go

whole idol
rich bluff
whole idol
# summer stump That is a wild nested ternary 🤣 Also, shouldn't the jumpingforce line be affe...
using System;
using System.Collections.Generic;
using UnityEngine;

public static class scr_Models
{
    #region - Player -
    [Serializable]

    public class PlayerSettingsModel
    {
        [Header("View Settings")]
        public float ViewXSensitivity;
        public float ViewYSensitivity;



        public bool ViewXInverted;
        public bool ViewYInverted;
        [Header("Movement")]
        public float WalkingForwardSpeed;
        public float WalkingBackwardSpeed;
        public float WalkingStrafeSpeed;

        [Header("Jumping")]
        public float JumpingHeight;
        public float JumpingFalloff;
    }
    #endregion
}

maybe this should help ? It's hard to follow for me too, and I wrote that code

rich bluff
#

so your jumpingForce never changes

summer stump
summer stump
whole idol
summer stump
whole idol
#

I tried many things but I dont know how heigh the player will go before he falls back down

agile mesa
crisp dew
#

Hi there, I'm creating an angry birds clone and have followed a tutorial to set up the basic gameplay. Now I'm feeling stuck in tutorial hell. I'd like to add some abilities like explode on impact or altering the mass but don't know what questions to ask. Does anyone know what concepts, videos, or articles I should look into to begin?

inland monolith
summer stump
eternal falconBOT
#

:teacher: Unity Learn ↗

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

crisp dew
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

summer stump
crisp dew
#

Oh lol I see thank you

wintry quarry
#

It works fine when you have a good understanding of the principles involved.

north kiln
#

@queen adder we can do without the references to suicide thanks

summer stump
#

Saving stuff for scene persistance is not the best. Just use ddol or additive scene loading

#

Also, you should absolutely stop and set up version control now

opal vortex
summer stump
#

Manual copy backups are a really poor way of doing things.
Get on version control like now

whole idol
#

ok so after some tweaks and twists i got to this

https://gdl.space/ekukanidic.cs

I think the player no longer jumps in outer space but now i have the completelly opposite problem where the player is superglued to the ground at all times like a snail on a pavement or smth

#

Everything works as intented

#

when I press jump, JumpingForce gets activated, the more I stay on the ground the more it says indeed Is Grounded = True every single second this gets updated and during the start for a few seconds i also get Is Grounded = False, gravity works and then the player just drops on the deck and nothing happens after than, the player's capsule just gets stuck on the ground for eternity like if he had cement shoes on

#

JumpingForce is apparently broken like my hopes of creating a functional game

wintry quarry
whole idol
#

ok so i followed this method of this tutorial, which uses getcomponent<rigidbody> even tho it kind of slows down performance or fps of the game i think...anyway it's good enough but still I think the player has been turned into a snake

#

I changed the Jump() method and did the same thing this guy does on his code with the rb.AddForce method and still the player will not move

#

And since im using the GetButtonDown thing I gotta use this name input key thing he uses

thorn holly
#

Maps[random.Next(0, Maps.Count - 1)]; Shouldn't this code return a random element in the Maps list? Cause I only seem to be getting the first element.

#

I logged Maps.Count - 1 and it returns one, which is intended

#

so I don't understand what the issue is

solid swift
#

shouldn't the random be capitalised?

#

but i guess if it had to be it'd show you an error..

thorn holly
#

maybe it can't include the upper bound

#

lemme try subtracting 0.9

summer stump
#

Oh wait. Not sure with next
Range with ints is max exclusive

opal vortex
#

are you setting a random seed at any point? I forget if you'll still get the same random number sequence otherwise

thorn holly
#

wait no, it takes an int, so i can't subtract 0.9

thorn holly
#

thanks!

wintry quarry
#

you'd have to pick one or the other

whole idol
# wintry quarry You can't just mix CharacterController and Rigidbody motion

    private void CalculateJump()
    {
        jumpingForce = Vector3.SmoothDamp(jumpingForce, Vector3.zero, ref jumpingForceVelocity, playerSettings.JumpingFalloff);
    }

    private void Jump()
    {
        if (isGrounded && Input.GetButtonDown("Jump"))
        {
            rb.AddForce(new Vector3(0, 5, 0), ForceMode.Impulse);
        }

        jumpingForce = Vector3.up * playerSettings.JumpingHeight;
        Debug.Log("Jumping Force: " + jumpingForce.magnitude);


    }
}

so something like this? isGrounded without the characterController?

wintry quarry
#

no i don't really see why you would be changing your jumping force in the Jump function

#

I saw this code earlier

#

when you posted it earlier

#

and it didn't make any sense then

#

and still makes no sense now

#

What you would do in Jump is add some kind of upwards velocity. Maybe that's what you're trying to do with this jumpingForce variable - if that's the case, it's an exceedingly poorly and confusingly named variable

#

last I looked at this code you weren't calling your CalculateJump function anywhere either (and why is it called that anyway???)

supple elbow
#

So i want the code to only play when the play button is clicked, but it works when i click anywehre on the screen for some reason:

#

Is there any way so that i can only click on the button to transition the scene while also playing the animation?

whole idol
wintry quarry
#

Why are we back where we started

#

you need to:

  • follow a tutorial that has jumping with CharacterController
    or
  • start actually debugging your code
whole idol
#

Ok, I have Debug.Log on nearly every method tho

#

and everything works as intented

wintry quarry
# whole idol Ok, I have Debug.Log on nearly every method tho

It's not enough to just put it everywhere. You need to think about how the code is supposed to work and read the logs you're printing and check that things are as you expect
If everything worked as intended you wouldn't be here asking how to make it work

rocky vortex
#

im having an issue with my code where the isFacingRight bool is only changing once the A or D keys are released instead of when pressed. Im using the new input system and curious if there's a way to use it instead of the old input system where I could do on key pressed to do so.

#

current mapping, not sure if the binding properties have anything to do with it

wintry quarry
#

i.e. - where is this function getting called from and what is setting move???

rocky vortex
#

top is where move is

#

i checked in the inspector and when I turn left the move.x is negative 1, when right, its positive one. I was hoping id be as simple as my OnMove() has but evidently not

gray spire
#

So quick question.. how do I make a sprite glide after it finishes moving?

wintry quarry
#

what does "glide" mean exactly?

gray spire
#

Like 0 gravity, after the player stops inputting on the keyboard for directional movements, the sprite continues goes in that direction

wintry quarry
wintry quarry
#

you mean inertia?

gray spire
#

Yeah ig

wintry quarry
#

several options

gray spire
#

Oh great

wintry quarry
#
  1. Use GetAxis - which has smoothing built in
  2. Simulate velocity manually and change it slowly over time
  3. Use Rigidbody physics
wintry quarry
#

get used to it

gray spire
#

very true

wintry quarry
#

everything has different characteristics, pros, and cons

rocky vortex
#

no, tbh im not too familiar with the binding properties, but I think that was the default when I set up an up/left/right/down composite @wintry quarry for the WASD keys

gray spire
rocky vortex
#

not to mention it also does it with the analog stick which doesnt use digital normalized so not sure

wintry quarry
rocky vortex
#

well to my understanding, using the new input system would allow the game to just run a function based off the name, i.e., thats why I called the function OnMove().

wintry quarry
#

that would be a specific mode on the PlayerInput component

#

so you're using PlayerInput in Send Messages mode?

#

that's really confusing - why are you mixing up PlayerInput stuff with the manual reading of values from an action map. You should kinda pick one or the other

steady crown
#

hello guys i need help im a noob. im doing this program where i ask how many routes, then i ask how many meters the routes are, and then i anwser them what the route is in km. the problem im having is dividing every number by 1000 which im trying to do. it just becoms zero. here is the code and how the program looks like when it runs (its in swedish)

rocky vortex
#

when I did my movement in OnMove() instead it would only trigger once, meaning the game would force u to keep pressing the A or D keys, instead of just holding it. Doing so in fixedupdate allowed for this continious movement. Im still new to this but guess im not understanding in total the new input system.

#

is that what U mean by manually reading values ?

wintry quarry
#

they are not the same

#
Vector2 moveInput;

void OnMove(InputValue inputVal) {
  moveInput = inputVal.ReadValue<Vector2>();
}

void FixedUpdate() {
  // your movement here using the moveInput vector
}```
Something like this would be typical @rocky vortex
steady crown
#

oh yeah i know i thought this was just coding in general but i guess not. sorry!.

wintry quarry
#

!cs

eternal falconBOT
wintry quarry
#

There's a general C# server^

steady crown
#

thanks!!'

rocky vortex
wintry quarry
#

is it not working?

rocky vortex
#

ig where is this "manual reading" thing u speak of

#

and yes it works the same exact way as before I had it

#

I changed it just for ur suggestion and practice

wintry quarry
#
Debug.Log($"Move value is {move}");```
Step one of debugging your problem^
wintry quarry
rocky vortex
#

right, initial question aside, there is no change in how the code worked before and after making that change. Back to the question at hand tho, I have been trying to debug it, I have the move values viewable in the inspector, when I click A for left, the x value in the inspector goes to -1, yet the bool remains as isFacingRight = true;

#

I can see it while the game is running, but its not until after I let go of the key that isFacingRight = false

wintry quarry
#

use Debug.Log right before the if statement

#

that will tell you what it actually is when your if statements get ahold of it

#

also make sure Collapse is NOT turned on in your console

rocky vortex
#

I just turned it on, I was gonna also add a debug.log to print the isFacingRight boolean, and I dont want the move.x debug to clog up the inspector

#

why do u suggest not turning it on

wintry quarry
#

let it clog

#

you need to know what it is NOW

rocky vortex
#

its -1 and 1

#

in the console

wintry quarry
#

is it the right values WHEN you expect it?

rocky vortex
#

yes

wintry quarry
#

e.g. while you're holding left

#

and while you're holding right

rocky vortex
#

yes

wintry quarry
#

ok then this part is working fine

#

you likely have other code changing isFacingRight when you don't want it to

#

in fact I'm going to throw a hail mary guess here

#

you probably have if (isFacingRight = true) or something somewhere

#

which would be the source of your problems

#

because it's supposed to be == not =

rocky vortex
#

this is the only code using isFacingRight aside from START() where it sets it to true and the declaration of the variable

wintry quarry
#

otherwise what's the point of it?

#

why don't you share your full script

#

!code

eternal falconBOT
wintry quarry
charred lodge
#

what was the shortcut of editing code (tab,gaps etc.) in visual studio

rocky vortex
# wintry quarry btw to further prove this is working correctly: ```cs Debug.Log($"Move.x is {mov...

not yet, I havent gotten to that part yet because I would think I need the bool to be properly done first before I could even check it. I dont think the code that depends on the bool would work if I know it will remain false. I added that in, and yes its working I believe, both in the console and the inspector. Logistically I think it was ur suggestion of switching the setting of move in OnMove() instead of fixedupdate. Ty

summer stump
gray spire
crimson sinew
rocky vortex
#

im trying to implement a dash mechanic that uses the player's localscale.x to addforce either neg direction or pos. Im setting that localscale to Vector3(1,1,1) and (-1,1,1) for the left direction. Unity says I cant multiply a Vector3 by a float, even tho im using localscale.x, one of the vector 3 components which the docs says is a float. Anyone have any input?

#

the error is on the addForce line, 93

crimson sinew
#

is your !IDE configured correctly?

eternal falconBOT
rocky vortex
#

I dont think so tbh, I have noticed that VSC isnt giving me errors and have been resorting to using unity not working instead lol

#

ty

summer stump
rocky vortex
#

it is a float, yes

summer stump
#

So what is the error then?

rocky vortex
#

it might have to do with the ide thing, ill work on that

#

ty

charred lodge
#

which one should i use for adding delay ? startcoroutine or await task.delay ?

timber tide
#

sure

rocky vortex
#

TY, i got my VSC giving me errors now, but the error I had previously remained.

#

not understanding this part tho, Vector2 and float multiplication

#

would it have something to do with the error mentioning Vector2 and me setting the localscale to a vector3 ? The move.x speed works, and its a vector2 ... 🤔

timber tide
#

dashspeed a float?

rocky vortex
timber tide
#

AddForce requires a vector 2, but you're multiplying a float by a float

#

assuming you just want to add force on the x, you want to make a new vector2 and use that value and assign the y to 0

polar acorn
summer stump
solid swift
#

hji everyone, i think this is the right place to ask, i'm having an issue with my code (https://paste.ofcode.org/cDdQzdUaZuJwDFEmycY79D) , in line 25, when i replace the checkCounter() method with the moveChar() method that's defined in the script, then i open unity and try to interact with the buttons i assigned the script to, unity freezes up and i have to close it manually. when i have checkCounter() (which i've written in another script that displays a message when the number of wrong attempts reaches 3) in the else statement it kind of works (it says any button chosen is wrong but at least the method works right) but if its moveChar() it doesnt work at all

rocky vortex
#

yes ty, this should make debugging easier hopefully. And I think what Mao said was pretty clear so thats what ill be attempting next, im just taking a little break rn, ty !

timber tide
#

stick to forloops as it'll prevent blowing up unity

#

in this case though you could consider a coroutine with a yield

#

actually better off just muliplying by deltatime

#

technically update is already a while loop

solid swift
#

update goes off every frame tho right? how do i make it so that it only calls what's in update when eg i press a button?

timber tide
#

if button is pressed -> call method and translate

#
public float speed = 5f; 

void Update()
{
    if (Input.GetMouseButton(0)) 
    {
        transform.Translate(Vector3.right * speed * Time.deltaTime);
    }
}```
solid swift
#

ohhh, thank you so much!