#💻┃code-beginner

1 messages · Page 303 of 1

ebon yoke
#

I apologize. I tried to post in Unity-talk and was redirected here.

young warren
summer stump
#

Talking to that other person in another server. They are not asking anythikg related to unity, which is why they didn't continue asking

whole idol
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;

public class pipepositions : MonoBehaviour
{
    public float upperExtreme = 3.19f;
    public float lowerExtreme = -3.68f;
    public GameObject PipePair;
    private float timer = 0.0f;
    private int spawnInterval = 5;


    // Start is called before the first frame update
    void Start()
    {

    }
    void Update()
    {
        
        Vector2 moveLeft = transform.position;
        moveLeft.y = -7f;
        
        timer += Time.deltaTime;
        Debug.Log(timer);
        if (timer >= spawnInterval)
        {
            SpawnItem();
            timer -= spawnInterval;
        }
    }
    void SpawnItem()
    {
        Instantiate(PipePair);

    }
}
#

Ok so im at this stage of that Unity tutorial where it sadly stopped providing helpful tutorials about the code or the game and unity's functions etc etc and instead is just showing me how to write a report or whatever on what my game is gonna be, i dont care, the tutorials were good at teaching stuff but the good tutorials ended way too quickly, now its just random crap again

#

anyway so he gives me all the creative freedom to basically do whatever i want at this point to "learn" and i decided to do this

#

its basically a basic flappy bird game but the code gotten kinda complicated here lol

whole idol
# whole idol

also check this out, it is making new obstacles properly but at this stage I want the obstacles to be able to move backwards on a loop, so far i couldnt make this to work yet

#

and also have another problem which is the fact that its instantiating 2 then 4 then 4 becomes 8 then 8 becomes 16 then 16 pipe obstacles become 32 etc etc. This is also another big problem which I dont understand so far why it happens or how to stop it.

languid spire
nimble panther
#

Hi, I'm kinda new to Unity, and I have an error in my code that I can't understand. I'm trying to access another object's velocity from a different object, but it says I can't access the rigidbody due to not having permissions to view it. However, the class and rigidbody are both public, so I don't know what's going on. Any help would be appreciated. Thanks!

#

Also I hope this is the right thread for this

whole idol
#

this isnt supposed to be a multiple scenes type of game

#

i wanted to make the pipe platforms spawn somewhere between those extreme upper lower variables you see on top of my script

#

and i planned on using something similar to python's random.randint()

languid spire
nimble panther
#

wdym

languid spire
nimble panther
#

i have to declare the boat in the camera script?

#

this is all the code up until that point

languid spire
#

if you want to use there, yes. What did you think Boat. did?

nimble panther
#

i thought it accessed the gameobject that i declared in the boat script

languid spire
#

no

nimble panther
#

like here

languid spire
#

your camera script knows nothing about that

nimble panther
#

even though it's public?

#

i thought that's what making it public did: allow everything to see it

languid spire
#

I think you need to follow some basic C# tutorials

young warren
# nimble panther this is all the code up until that point

you should start with configuring your Visual Studio first. and then I'd highly recommend you watch this video. You seem to have a misunderstanding on how to get references to object
https://www.youtube.com/watch?v=dtv7mjj_iog

As a new dev, keeping references to game objects you need can be a little confusing. Learn how to store game objects for later use as well as allowing external scripts access to your goodies.

Instead of trying to find an object, shift your thought pattern a little and ask "should I already know where this object is?".

❤️ Become a Tarobro on ...

▶ Play video
#

the issue is not the access modifier, which is public

#

you're right that it needs to be public, but that's not the problem here

#

!vs

eternal falconBOT
#
Visual Studio guide

If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:

Visual Studio (Installed via Unity Hub)
Visual Studio (Installed manually)

young warren
#

heres the guide to configure your visual studio

#

the reason why we're directing you to tutorials is because you have a misunderstanding of some of the fundamentals, so it'll be hard for you to understand the help that's given at this point

#

and all these links are pinned in this channel for future reference

nimble panther
#

Thanks!

crisp knoll
#

is photon pun outdated? i’ve been following a tutorial on it and don’t want to get too far into it with something not “useful”

#

alternatively, what is a multiplayer game service you would recommend and where would i get that?

young warren
#

check out the pins there too

crisp knoll
#

okie :)

whole idol
languid spire
whole idol
#

then the same thing will happen if i make a nested object inside of another object i think

#

so do i still need to get the old gameobject?

#

or use the parent?

languid spire
#

yes, your spawner should be completely separate from your pipes

whole idol
#

PipeSpawner is empty

#

ok, is the Pipe Pair okay?

#

as you can see here I still have the old pipe prefab object attached inside of that reference

languid spire
#

you don't need a prefab there at all

whole idol
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;

public class pipepositions : MonoBehaviour
{
    public float upperExtreme = 3.19f;
    public float lowerExtreme = -3.68f;
    public GameObject PipePair; // should I remove this?
    private float timer = 0.0f;
    private int spawnInterval = 5;


    // Start is called before the first frame update
    void Start()
    {

    }
    void Update()
    {
        
        Vector2 moveLeft = transform.position;
        moveLeft.y = -7f;
        
        timer += Time.deltaTime;
        Debug.Log(timer);
        if (timer >= spawnInterval)
        {
            SpawnItem();
            timer -= spawnInterval;
        }
    }
    void SpawnItem()
    {
        Instantiate(PipePair);

    }
}

whole idol
languid spire
#

did you not understand what I said? You need to move the whole spawning code to a new script and put that on a separate object. It should not be in a script attached to a pipe

whole idol
#

in fact

#

right now it works perfectly

#

well almost

#

Its no longer spawning exponentially

languid spire
#

if it is not attached to a pipe what is it supposed to be moving?

whole idol
# languid spire if it is not attached to a pipe what is it supposed to be moving?

it is attached to the child pipe object containing 2 pipes, the thing is, its not doing anything right now because I haven't given it any logic for what I wanna do with it but im not sure if i should keep it or not, so basically my next step is to ensure that all these pipes move on the position.x axis in a negative way multiplied by speed and time.delta time and then destroy them after a while once they get off the screen

languid spire
#

This script should be attached to the PipeSpawner object. you will then need another script to attach to the pipe objects to make them move

whole idol
#

I tried that just now

#

and I got the same exponential duplication problem

#

so I attached the public GameObject to child object again and it got away

#

so this is what was causing the problem

#

anyway is there a way that a script can reference the object it is using without needing to use these serealized fields to communicate to a gameobject from the hierarchy?

#

if this script is in my inspector of PipeSpawner

#

then it makes sense that I could use PipeSpawner and push that shit back and forth and create the illusion that they are moving

#

in fact PipeSpawner is a name i might need to change rn

languid spire
#

yes but if you can directly reference the objects via the inspector you should

#

Look your setup is very simple
Pipespawner - has pipeposition script which spawns PipePair
-> PipePair - has a script which moves the pipes

spice ravine
#

Hello, I am a new beginner to unity, and I made some UI

#

now, I don't know how do I check when something is clicked

#

I tried using ai, but it didn't help ```csharp
using UnityEngine;

public class ClickableNextImage : MonoBehaviour
{
// Update is called once per frame
void Update()
{
// Check if the mouse button is pressed
if (Input.GetMouseButtonDown(0))
{
// Cast a ray from the mouse position into the scene
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction);

        // Check if the ray hits the object named 'nextImage'
        if (hit.collider != null && hit.collider.gameObject.name == "NextImage")
        {
            // Handle the click event
            OnNextImageClick();
        }
    }
}

void OnNextImageClick()
{
    // This method will be called when the 'nextImage' is clicked
    Debug.Log("Next image clicked!");
    // You can put any code here that you want to execute when the 'nextImage' is clicked
}

}

#

I am very confused, and I would really apreciate some help

#

(I put the script inside of the 'NextImage' object)

ruby python
spice ravine
#

they are just normal images

languid spire
ruby python
#

Okay, Make them buttons (it's far simpler and easier), remove all the raycasting stuff from your code (you don't need it if you use buttons)

whole idol
spice ravine
#

can I add a component to define them as buttons?

#

is there any vcs here?

whole idol
gaunt ice
#

then add an button, other components cant be turned into a button

ruby python
#

But it is a lot simpler to just create a new button if honest.

whole idol
# whole idol

yo guys why are these clone objects spawning in the middle of the screen instead of copying the position of their prototype original object position which they are cloning after?

spice ravine
#

Thank you!, now, is there any VCs here? because I feel like talking is much easier then texting

whole idol
#

thats the most idiotic thing ive ever seen in my life

ruby python
spice ravine
#

did it

#

Thank you so much for the help so far

ruby python
#

No probs. Okay, I'm going to assume you haven't done any of what I'm about to say. 🙂

Create a new empty GameObject in your game Hierarchy (reset it's transform) and add your ClickableNextImage to it.

#

ClickableNextImage script I meant

spice ravine
#

can we dm call?, I am getting uncomftarbal that I can't vitualize it, if no, please tell me strait ahead

ruby python
#

I can't talk at the moment (literally, got a cold and no voice. :-/) Give me a moment though.

spice ravine
#

Kk

whole idol
#

Why are these clone objects spawning in the middle of the screen? They are cloning after an object that is standing outside the camera!!!

#

(video incoming)

#

and...... im talking about these shenanigans

#

( video still loading )

#

( almost there )

#

^ this is the video im talking about

static bay
whole idol
#

look at the first object lol

#

they should be sitting outside like that, also how do i change their position?

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

public class pipepositions : MonoBehaviour
{
    public float upperExtreme = 3.19f;
    public float lowerExtreme = -3.68f;
    public GameObject PipePair; 
    private float timer = 0.0f;
    private int spawnInterval = 2;


    // Start is called before the first frame update
    void Start()
    {

    }
    void Update()
    {
        

        Vector2 moveLeft = transform.position;
        
        timer += Time.deltaTime;
        Debug.Log(timer);
        if (timer >= spawnInterval)
        {
            SpawnItem();
            timer -= spawnInterval;
        }
    }
    void SpawnItem()
    {
        Instantiate(PipePair);

    }
    void OnInstantiate()
    {
        PipePair.AddComponent<LeftMove>();

    }

}

#

I try to add xyz but throws an error after I try to create positio

#

wtf

young warren
#

you'll also learn how you can get a reference to the object you just spawned

static bay
# whole idol

Instantiate returns the object it creates. You can use modify the position that way right after it's spawned.

#

Instantiate also has an overload that accepts a position and rotation.

ruby python
static bay
#

So you can do Instantiate(prefab, position, Quaternion.Identity) if you want it to spawn at a specified position with an upright rotation.

whole idol
#

I try to stick a script on them right after these clones get spawned but this apparently is as useful as a screen door on a submarine

static bay
#

Well first off, this is never called.

ruby python
static bay
#

Secondly, you're targeting the prefab, not the spawned instance.

whole idol
static bay
#

Thirdly, why not just have that script on the prefab to start with?

ruby python
#

Also, when you instantiate, you should be doing GameObject newPipePair = Instantiate etc.etc.

whole idol
ruby python
#

And then if you need to do anything else, do it to newPipePair

whole idol
static bay
#

There is no reference to the spawned instance in that script.

ruby python
static bay
ruby python
#

A prefab is literally a collection of everything that the object needs to function, so if you spawn it, it spawns everything attached to it.

whole idol
ruby python
queen adder
#

this is my image, which contains the following children. How do I, in the script, make Player(1) and it's children not be rendered?

I have tried set active, get component and a few other fixes, furthermore when I toggle the eye icon in hierarchy view in editor, the image has it's rendered turned off only in editor, not in game view? Please help.

whole idol
# ruby python You can edit/add/remove things from a prefab, just double click it in your proje...
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;

public class pipepositions : MonoBehaviour
{
    public float upperExtreme = 3.19f;
    public float lowerExtreme = -3.68f;
    public GameObject PipePair; 
    private float timer = 0.0f;
    private int spawnInterval = 2;
    private float rotation = 0;


    // Start is called before the first frame update
    void Start()
    {

    }
    void Update()
    {

        Vector2 moveLeft = transform.position;
        
        timer += Time.deltaTime;
        Debug.Log(timer);
        if (timer >= spawnInterval)
        {
            SpawnItem();
            timer -= spawnInterval;
            
        }
    }
    void SpawnItem()
    {
        GameObject instantiatedObject = Instantiate(PipePair, Vector3(1.8, -5, -0.2), rotation);


    }

}

i fixed the script inheritance part

#

but why is this throwing error?

#

on Vector3

#

or Vector2 too

ruby python
#

"new Vector3"

#

Also, you missed the 'f' s after the numbers. You need to tell the code that decimals are explicitly Floats

whole idol
ruby python
#

lol.

whole idol
#

I think VS is just trolling me at this point

north kiln
#

read the error

whole idol
ruby python
#

Rotation is a Quaternion, not a float.

whole idol
#

tf is a quaternion?

north kiln
#

It's a complex number that represents a rotation

whole idol
#

or, should i say how do i turn it to 'normal' rotation?

ruby python
#

If you want it to match the rotation of the spawner, just do transform.rotation

static bay
north kiln
#

Quaternion.Euler(x, y, z)
Creates a Quaternion out of the angles you'd likely be familiar with

ruby python
#

or if you want no rotation do Quaternion.Identity

north kiln
static bay
#

Quaternion.Identity will get you far enough.

ruby python
#

Quaternions are evil though. lol.

static bay
#

Like I get it

#

something something gimble lock

#

dont care

ruby python
#

lol.

static bay
#

wtf is a w

ruby python
#

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Exactly this

north kiln
#

You don't need to know to use them properly

ruby python
#

I genuinely believe it's named w because Witchcraft

static bay
whole idol
ruby python
languid spire
static bay
ruby python
static bay
#

Sounds like a conspiracy.

languid spire
whole idol
#

I love when these things happen

#

(not)

static bay
whole idol
#
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;

public class pipepositions : MonoBehaviour
{
    public float upperExtreme = 3.19f;
    public float lowerExtreme = -3.68f;
    public GameObject PipePair; 
    private float timer = 0.0f;
    private int spawnInterval = 2;


    // Start is called before the first frame update
    void Start()
    {

    }
    void Update()
    {

        Vector2 moveLeft = transform.position;
        
        timer += Time.deltaTime;
        Debug.Log(timer);
        if (timer >= spawnInterval)
        {
            SpawnItem();
            timer -= spawnInterval;
            
        }
    }
    void SpawnItem()
    {
        GameObject instantiatedObject = Instantiate(PipePair, new Vector3(1.8f, -5, -0.2f), transform.rotation);


    }

}

#

by the way I changed the GameObject instantiatedObject = Instantiate(PipePair, new Vector3(1.8f, -5, -0.2f), transform.rotation);

#

There's no funny squiggly line here

static bay
#

Sorry what is your goal?

whole idol
#

I want those pipes to start from all the way out of the screen and slowly creep in like the morning sun, not just appear in the middle of the screen out of nowhere

static bay
#

The pipes have a script to move left I assume?

whole idol
#

they gotta come in the scene slowly every time

static bay
#

The player themselves stays still?

whole idol
#

yes

#

don't worry about the player

static bay
#

Sure

#

So why do you think the pipes are spawning in the center of the screen?

whole idol
#

will get that fixed later, anyway here's the move left script

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

public class LeftMove : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        transform.Translate(Vector2.left* Time.deltaTime * 10);
    }
}

whole idol
static bay
#

You have 2 problems.

#
  1. Your pipes are not spawning in the correct location.
#
  1. Your pipes are not moving to the left.
#

Right?

dire tartan
#

im making a fps character and when the player looks around sometimes the camera will freeze for a second then jolt forward im not sure what it is thats wrong ive stripped my character to just its movement and camera and im still having the issue heres the code for the camera https://hatebin.com/lfrwwqckna i can provide more info if needed

hollow slate
dire tartan
#

i dont know how to describe it exactly but it feels like when spinning it skips forwards

#

it happens when not moving

#

too

hollow slate
#

so it has to do with rotation?

dire tartan
#

i think so

hollow slate
#

it could have to do with variable framerate affecting the sensitivity because of multiplication with Time.deltaTime

You could Debug.Log the deltaTime and see if the jolt corresponds to frame-drops.

#

or just remove the multiplication with Time.deltaTime and see if the jolting stops.

dire tartan
#

that seems to have fixed it

#

thanks!

spice ravine
#

I am making a python game, only with inputs and prints, and I wanted to make it visual, here is the py code

#

This game is a RPG with multiple creatures, a market with items, a armory with swords and armor, and 2 secret creatures, one gives you an ending.
you can chose to play hard and normal mode too

hot lily
#
{
    while (context.performed)
    {
        Debug.Log("Flying " + context.phase);
        
    }
}```
is "while" somehow not allowed in unity input system? i used it then it straight up just froze lul
#

yeah it just fucking died

willow scroll
#

Of course it died

hot lily
#

so what now i must put that in a fixed update or something?

#

if i intend it to be "as long as the fly button is held it will fly forever"

willow scroll
#

Well, no? Just don't use the while loop

hot lily
#

if I do it will just only do one hop and that's it

#

it doesn't fly infinitely

willow scroll
#

The Fly method will be called if it's subscribed to the action

#

Just remove the while

hot lily
#

i replaced the while with an if
(since it is a "hold" interaction)

#

but now it does only one hop again, fml

willow scroll
hot lily
#

yeah

willow scroll
#

There is thus no need for the if (context.performed), as it will always return true if the method is called on performed

hot lily
#

brain not computing
would it not trigger while it's cancelled/started if I don't specify if (context.performed)?

willow scroll
hot lily
#

ah i see

willow scroll
# hot lily ah i see

The same as there is no need to check for started or canceled when called on started or canceled respectively

willow scroll
hot lily
#

wasn't it started -> performed -> cancelled?

willow scroll
#
  • started is called when the input starts
  • canceled is called when the input ends
  • performed is called when the input is in the process and the value is changed
#

So subscribing a method to your action in performed will call the method continuously

#

If your method isn't called continuously, your action type might be a Button

hot lily
#

i'm in a bit of a loss
i have playerInputActions.MechControl.Jump.performed += Jump; in awake, which is a button interaction
but in public void Jump where i didn't specify it needs to be context.performed it triggers thrice (hence jumped three times simultaneously)

but in the same time i also have playerInputActions.MechControl.Fly.performed += Fly in awake, but this one responded correctly (only triggers once)

rocky vortex
#

im running into issues creating dictionaries. I was working on an inventory system and was trying to use dictionaries. After looking up online, I found an example and just copied and pasted it as it was in the working online resource but I get an immediate error saying openWith.Add(); doesnt exist in current context. also for some reason using namespace std doesnt work either since during my debugging I decided to add that just in case (its system.generic anyway according to the resource so it shouldnt have mattered anyway), but Im thinking something internally might have messed it up. Because im using ScriptableObjects, I have inherited on other files as ItemDefinition instead of MonoBehaviour, and I was thinking that might be it, but not sure. https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2?view=net-8.0#definition

Represents a collection of keys and values.

willow scroll
#

What is the action's type?

hot lily
#

nvm trying again

gaunt ice
#

using namespace std....

north kiln
willow scroll
#

If it's a Button, you won't be able to continuously detect the value change

hot lily
#

i changed it to value now

#

but i'm sure i did something wrong since it's still not continuously going up

willow scroll
willow scroll
hot lily
willow scroll
hot lily
#

it was a button, but switching to value didn't change anything either

willow scroll
#

Have you saved it?

hot lily
#

yes

willow scroll
#

Alright, now, please, show me how you subscribe it

hot lily
#
{
    playerRigidbody = GetComponent<Rigidbody>();
    playerInput = GetComponent<PlayerInput>();
    playerInputActions = new PlayerInputActions();
    playerInputActions.MechControl.Enable();
    playerInputActions.MechControl.Jump.performed += Jump;
    playerInputActions.MechControl.Move.performed += Move;
    playerInputActions.MechControl.Fly.performed += Fly;

    playerStatsInstance = GetComponent<PlayerStats>();
}
public void Jump(InputAction.CallbackContext context)
{   if (context.performed) 
    {
        if (isGrounded == true)
        {
            Debug.Log("Jumping while grounded " + context.phase);
            playerRigidbody.AddForce(Vector3.up * 5f, ForceMode.Impulse);
        }
        else if (isGrounded == false)
        {
            Debug.Log("Jumping Mid-air " + context.phase);
            playerRigidbody.AddForce(Vector3.up * 3f, ForceMode.Impulse);
        }
    }
        
}

public void Fly(InputAction.CallbackContext context)
{
        Debug.Log("Flying " + context.phase);
        playerRigidbody.AddForce(Vector3.up * 3f, ForceMode.Force);
}
willow scroll
hot lily
#

yeah

#

i didn't call it in fixed update or sth

willow scroll
#

Are you sure the value is being changed?

#

If it's not, the performed will be called just once

#

So if the value is (1, 0) -> (1, 0) -> (1, 0) -> (0, 0), the performed is called twice

hot lily
#

i'm not sure if i understand

#

besides even if that's true, that's being called twice rather than being called continuously

#

if i am understanding correctly that is

willow scroll
gaunt ice
#

why not just Fly() right after it is assigned

willow scroll
hot lily
#

i probably should just put a boolean isFlying = true while it is performed then isFlying = false while cancelled or sth

#

then put an if argument in a fixedUpdate where if isFlying is true then it flies

gaunt ice
#

mb, didnt realize it is new input system

hot lily
#

this is frustrating
for some reason jump doesn't need playerInputActions.MechControl.Jump.performed += Jump; to function
but flying does, would straight up not respond without it

#

even if both are now button with no state check

sly mountain
#

guys why am i getting this error with my code?

using UnityEngine;
using UnityEngine.UI;

public class WaterProgress : MonoBehaviour
{
    private Slider slider;
    private ParticleSystem particleSys;

    public float fillSpeed = 0.5f;
    private float targetProgress = 0;

    private void Awake()
    {
        slider = gameObject.GetComponent<Slider>();
        particleSys = GameObject.Find("ProgressParticles").GetComponent<ParticleSystem>();
    }

    void Update()
    {
        if (slider.value < targetProgress)
        {
            slider.value += fillSpeed * Time.deltaTime;
            if (!particleSys.isPlaying)
                particleSys.Play();
        }
        else
        {
            particleSys.Stop();
        }
        // Check if the slider value has reached 1
        if (slider.value >= 1f)
        {
            // Reset the slider value back to 0
            slider.value = 0f;
            // Optionally, you can reset the target progress as well
            targetProgress = 0f;
        }
    }

    // This method starts the progress
    public void StartProgress()
    {
        IncrementProgress(1f);
    }

    // Determines target incremental progress
    public void IncrementProgress(float newProgress)
    {
        targetProgress = slider.value + newProgress;
    }
}
rich egret
thorn tapir
#

hi guys i litterally started coding an hour ago could someone help me with these simple codes? I only want it to move once but once i press any of these it just dosent stop going to the directions.

rich egret
modest dust
languid spire
ruby python
#

Hey all,

I can't seem to figure this out, would anyone be able to point me in the right direction as to why my 'waveSpawnInterval' WaitForSeconds isn't delaying the next wave in my spawner please?

https://hastebin.com/share/sayidukede.csharp

At the moment, the next wave of enemies spawn as soon as the 'previous' wave has completed doing it's thing. At the minute, the waveSpawnInterval is set to 10 for testing. 😕

languid spire
ruby python
modest dust
ruby python
sly mountain
#

why is it red

languid spire
#

yes, install them in a non Unity project/solution and then copy the dll's to your unity project inside a Plugins folder

willow scroll
golden canyon
#

can anyone help me with this error?

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

public class NewBehaviourScript : MonoBehaviour
{
    private PlayerInput playerInput;
    private PlayerInput.OnFootActions onFoot;

    private PlayerMotor motor;

    // Start is called before the first frame update
    void Awake()
    {
        playerInput = new PlayerInput();
        onFoot = playerInput.onFoot;
        motor = GetComponent<PlayerMotor>();
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        motor.ProcessMove(onFoot.Movement.ReadValue<Vector2>());
    }
    private void OnEnable()
    {
        onFoot.Enable();
    }
    private void OnDisable()
    {
        onFoot.Disable();
    }

}
eternal whale
#

Hello, how can i activate this in Visual Studio code? it's says the diferent possibilities of code

willow scroll
eternal falconBOT
north kiln
#

It's underlined in red, it's configured.

willow scroll
sly mountain
#

why am i getting a null error thing then

willow scroll
sly mountain
willow scroll
eternal needle
north kiln
sly mountain
sly mountain
#

and i couldnt find a variable that was undefined or unused

north kiln
#

Then you should know why it's null

sly mountain
#

let me check this code again

rich egret
#

!code

eternal falconBOT
north kiln
#

Because it goes through everything over multiple pages

thorn tapir
rich egret
willow scroll
eternal falconBOT
#

:teacher: Unity Learn ↗

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

sly mountain
#

well i dont know why but it works now

thorn tapir
willow scroll
sly mountain
#

anyway i have a seperate question now. I have a particle system attached to my slider bar and I want the particles to stay at the end of it and fade when it reaches the end and resets, but right now it does this:

#

How can I

  1. make the particles stay at the end
  2. make the particles show up instantly when clicking again
snow girder
#

anyways i just came here to ask my own question

#

i've got a blend tree and i want to set the x and y values of my 2d free form movement blend tree to inputgetaxisraw horizontal and vertical

#

how could i do this smoothly

willow scroll
sly mountain
willow scroll
snow girder
#

i have a whole rigidbody system already

#

but i have a model that needs animations

#

and im using the blendtree technology

#

to do it

willow scroll
sly mountain
#

oh like dont make it reset

#

alright ill try that

willow scroll
willow scroll
snow girder
lethal bolt
#

Does it make an big diffrence if i use the normal 3d and the tutorial is made in URP?

snow girder
#

im having a code issue

willow scroll
#

If that's an object, which position is to be set, consider doing it in the Update

sly mountain
#

oh ok yeah that works, but i still do have the problem of the particles not showing when i click again

snow girder
#

i don't want to move an object

#

i want to set a slider

willow scroll
snow girder
#

a and d is 1 and -1 right?

willow scroll
#

Do you perhaps want to smoothly move the slider's value in the input direction?

snow girder
willow scroll
#

I see, as I have mentioned before, consider using the Update method

#

The same way as setting the object's position

snow girder
willow scroll
#
float inputDir = Input.GetAxisRaw("Horizontal");

_slider.value += inputDir * sliderSpeed * Time.deltaTime;
willow scroll
#

Oh, no

#

Not with the =, use += instead

snow girder
snow girder
#

input dir is the horizontal axis

#

and assuming the horizontal axis is 1

#

wouldn't the slider just straight up go to 1 without any smoothing?

willow scroll
snow girder
#

i want it to increase to 1 in some amount

willow scroll
#

Assuming the sliderSpeed is .1, it will take the slider 10 seconds to go from 0 to 1

snow girder
#

interesting

sly mountain
willow scroll
snow girder
#

for simplification i have set it to change the value of a float

#

and the value is not changing

willow scroll
snow girder
#

that is what i have done

snow girder
willow scroll
# snow girder that is what i have done

This line of code changes the slider's value from 0 to 1 in 10 seconds when the D key is pressed, assuming the animatory is the property assigning the slider.value to value

snow girder
#

oh wait

#

used the wrong axis 🤦‍♂️

willow scroll
#

No, you haven't

#

If you have assigned animatory to slider.value, it won't work

snow girder
#

the float works

#

but there's an another issue

#

there's no cap to it

#

and that it won't return back to 0

willow scroll
#

What is animatory?

snow girder
languid spire
willow scroll
snow girder
#

im just using a slider example since you haven't used blend trees

snow girder
#

sorry i don't know what property means

willow scroll
snow girder
willow scroll
# snow girder

Does changing the animatory change the slider's value?

snow girder
#

yes

willow scroll
#

Alright, got it, you assign it in the Update

snow girder
#

yes

snow girder
willow scroll
snow girder
snow girder
#

that's why it should go back to zero

willow scroll
snow girder
#

interesting

#

alright wait let me tell you my reasoning behind this

willow scroll
#

Interesting? I said that sliders don't go back to 0 when no key is being pressed

willow scroll
snow girder
snow girder
#

the animatorx. if it is 0 then the player will idle, if it is 1 then he will walk left

#

and same for the animator y

#

if it's 1 he will walk forward

#

-1 he will walk backwards

#

so it is crucial it goes back to 0

#

if it doesn't then the player will keep walking regardless of no keys being pressed

willow scroll
snow girder
eternal whale
snow girder
#

Input.GetAxis smoothing sucks

#

but i guess i could use it as a last resort

willow scroll
#

You'll have to calculate the distance, that's the best way on my opinion

snow girder
willow scroll
snow girder
#

well it really does cause when i press A it smooths to -1 and then if i were to press D fast enough it snaps to 0

#

then it smooths to 1

willow scroll
#

Alright, let's return back to setting the slider's value to 0 when no key is pressed

#

what is your slider's range?

#

is 0 its start?

snow girder
#

the y however

#

-1 and 2

#

since there is running involved

willow scroll
#

Oh, alright, so 0 is the middle of your slider?

snow girder
#

yes

snow girder
#

but it would do some weird stuff when it tried to go back to zero

#

somehow even going to a value called E?

#

sorry brb my mom calling me down

teal viper
#

E is just a part of the scientific number notation(used to represent small numbers usually). It doesn't mean that there's an issue with it, as most numbers can be represented like that.

#

Can't understand that error message. They should really stop translating them to other languages...😅

snow girder
teal viper
snow girder
teal viper
#

Why do you think it's supposed to go to 0?

snow girder
#

it's long gone now

#

but basically the whole thing i was trying to do is make a slider follow the horizontal axis

#

and smoothly go to the value

snow girder
#

instead of lerping it like i did

teal viper
snow girder
#

so you're telling me i did it incorrectly?

teal viper
#

Because you never actually reach the target value.

ivory bobcat
# snow girder but it shouldn't be E it should be 0...

Everything following the E would be the exponent so if you're operating with floats, the value could be some arbitrary small number (negative exponent) - zero is near impossible to acquire unless working with constants or assigned directly.

teal viper
snow girder
teal viper
soft kernel
#

if you use the lerp as moveToward (by giving it constant value) it will get closer and closer but won't reach the value

#

maybe that was what you did

#

why not use moveTowards instead?

snow girder
snow girder
soft kernel
#

if you give lerp a constant value it wont work right

#

the value of the lerp usualy must change

teal viper
soft kernel
#

use MoveToward instead

snow girder
#

sure

soft kernel
#

it moves value a to value b with the t speed

#

lerp is more complex

languid spire
# snow girder

those statements are pointless as you do not capture the return value

ivory bobcat
# snow girder

I don't think that does anything as Lerp is supposed to return a value that you'd assign to some variable.

languid spire
ivory bobcat
snow girder
#

this is getting a bit overwhelming

soft kernel
#

animatory = ...

snow girder
#

oh wait

#

my bad

#

hold on

languid spire
soft kernel
soft kernel
ivory bobcat
#

Example:cs speed = Mathf.Lerp(original, target, progress);

soft kernel
#

why lerp?

snow girder
#

okay so

#

the x value works correcty

#

but the y value doesn't

#

nvm it does

#

i forgot to save

snow girder
#

thank you very much

#

sorry for bothering all of you

#

im not even joking this literally gave me a headache all night

sly mountain
#

guys im having trouble with vscode right now i think?

#

I'm trying to make variables and they don't show up in the intellisense/autocomplete and unity says they dont exist

rocky canyon
#

do u have the needed using statement?

lethal bolt
#

Why does the "SelectByClicking" Become an error

languid spire
#

because it is outside the scope of the class

rocky canyon
#

u need TMPro for TMP_Text

#

and UnityEngine.UI for Slider

lethal bolt
spare umbra
#
public class BallVisual : MonoBehaviour
{
    public float rotationSpeed;
    private Vector2 moveInput;
    private Vector3 moveVector;


    public float maxRollingSpeed = 100f;
    public float acceleration = 10f;
    private float currentRollingSpeed = 0f;
    private bool isRotating = false;
    [SerializeField] private Transform sphere;

    void Update()
    {
        if (moveInput.magnitude != 0)
        {
            if (!isRotating)
            {
                StartCoroutine(AccelerateRotation());
            }
        }
        else
        {
            StopCoroutine(AccelerateRotation());
            currentRollingSpeed = 0f;
            isRotating = false;
        }

        sphere.Rotate(Vector3.right, currentRollingSpeed * Time.deltaTime);
    }

    IEnumerator AccelerateRotation()
    {
        isRotating = true;
        while (currentRollingSpeed < maxRollingSpeed)
        {
            currentRollingSpeed += acceleration * Time.deltaTime;
            yield return null;
        }
        currentRollingSpeed = maxRollingSpeed;
    }

    void FixedUpdate()
    {
        RotateInDirectionOfInput();
    }

    private void RotateInDirectionOfInput()
    {
        moveInput = InputManager.Instance.moveInput;
        moveVector = new Vector3(moveInput.x, 0, moveInput.y);

        if (moveVector != Vector3.zero)
        {
            Quaternion targetRotation = Quaternion.LookRotation(moveVector, Vector3.up);
            transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime);
        }
    }
}```
lethal bolt
rocky canyon
lethal bolt
lethal bolt
languid spire
#

!ide

eternal falconBOT
sly mountain
#

oh

#

i have using unity engine and unityengine.ui

soft kernel
rocky canyon
#

TMP_Text requires the TMPro; using statement

sly mountain
#

ohohh

#

thanx

rocky canyon
# lethal bolt No

well thats why... ur IDE is telling u that class doesn't exist .. so its impossible to grab it from any game object

languid spire
#

then you are not doing it correctly or fully

spare umbra
#

@lethal bolt the stick is just showing us where the ball is going towards

spare umbra
languid spire
#

It's quite simple really, if you were doing it correctly and fully it would work therefore. qed, you are not

#

nothing other than follow the steps shown

rocky canyon
#

theres not an alternative.. we'd just suggest going back and trying it again. each and every step

lethal bolt
rocky canyon
#

when its successfully setup where it says Miscellaneous Files will say Assembly-CSharp

rocky canyon
ivory bobcat
rocky canyon
#

public class UnitMovement : MonoBehaviour {

lethal bolt
#

This is the script

#

And it dosent Say "UnitMovement" before MonoBehaviour

rocky canyon
#

well thats why.. ur class name should probably match ur scripts filename..

languid spire
ivory bobcat
rocky canyon
#

^ thats what you'd need for ur current circumstance

#

b.c u named the class Script

lethal bolt
#

Oh

#

I see

queen adder
#

guys how to detect click in text mesh pro using c#

lethal bolt
#

Thanks!

ivory bobcat
#

It'll provide immediate satisfaction but the actual solution would be to change the class name to something relevant.

queen adder
#

i want to create a property system in my wild west game if a user clicks on the purchase button he should get the property

rocky canyon
#

i agree, its much easier to see ur filename MyScript.cs and know that the class is named MyScript w/o having to open it up and look

queen adder
#

this bool should change to PropertyOwned=true

#

and the property should unlock

lethal bolt
willow scroll
# snow girder yes

I am sorry, urgent stuff happened so I couldn't continue sending the solution I wanted.
You should calculate the offset between the current and desired positions.
I am writing from the phone, so I hope there are no miscalculations. Slider's value is smoothly moved to 0 when no key is being held.

float inputDir = Input.GetAxisRaw("Horizontal");

float offset = slider.minValue + (slider.maxValue - slider.minValue) * .5f * (inputDir + 1) - slider.value;

slider.value += MathF.Sign(offset) * speed * 100f * Time.deltaTime;
earnest atlas
queen adder
earnest atlas
#

Google singleton implementation

rocky canyon
#

singleton is like a gamemanager for example.. only a single instance of it exists.. so its easy to access via anywhere thru-out ur code

earnest atlas
#

You can hold some global variables in it to pass to next scenes, quite convinient

rocky canyon
#

both are worth learning.. singleton more than delegates for now

earnest atlas
#

yeah delegates can be left for later.

queen adder
#

so meaning it can't be typed twice ? like int x; x=2;

earnest atlas
#

It means only one instance of it exists ever.

rocky canyon
#

well there wont be two versions of it anywher

#

like u could have an enemy class and spawn it 10 times. (each version is its own instance)

#

a singleton would only ever exist once.. and a singleton is more of the entire class..

#

a static variable is similar

earnest atlas
#

Well in unity its a static instance inside the class.

#

So singleton is mostly about class

raw aspen
#

any idea how i can set this to read/write enabled true?

queen adder
#

btw do scripts run in the background if the object is cull my game is open world and it will have probably 100+ scripts

earnest atlas
#

if object is gone it wont run any scripts.

rocky canyon
earnest atlas
#

beware that if you link any functions (new unity input system per example) you will have to unlink them on destruct.

raw aspen
rocky canyon
#

selecting the FBX in the project panel

raw aspen
#

found it

#

i was looking at the mesh

ivory bobcat
# queen adder collider on button ?

If it's a button just use the button event system from the inspector. I had thought you were using some of the other tmpro ui object (text and whatnot)

raw aspen
#

ty @rocky canyon

#

so i built my game and although it runs 150+ fps (it feels like) in the editor, in the actual build it starts with a lot of framedrops and then it goes to like 5fps and lags out comepletely

#

i removed all grass and flowers in case that was the culprite

#

but i still have the issue

#

the game is very small i dont think it should have issues

night raptor
unique idol
#

Hey, I have little problem - I changed Tile type to custom, extended TileBase and now colliders don't work, like they don't exists.

raw aspen
#

ill watch a tutorial on that

unique idol
#

Okay - next question - I already changed collider type to sprite but it made another problem - game is lagging as hell.
Is there any option to set tile data globally without using tilebase?

green island
#

my player slides too much and if i make the drag higher the player falls to slow im not using colliders for collisions but a script that changes the velocity when on the ground and turning gravety off mybe thats a problem the drag is 1 and in another project the player doesnt slide that much

forest saddle
#

Hello! (I'm new to Unity)

I'm making a game for a school final project and I've been trying to work on this piece of code for a while.

It's a doodle jump style game and I have a box following my character as it moves upwards through the game. I want this box to collide and destroy my platforms once hitting them so that when my character falls down the level it doesn't hit one of the platforms.

young warren
forest saddle
#

I've tried lots of different code off of the internet, and none of them are destroying my platforms.

I'm really unsure what I'm supposed to attach my script to really.

young warren
#

have you written any code on your own? any prior programming experience?

#

you could start by googling "how to detect collision between objects unity"

#

then go from there

forest saddle
#

The programming experience I have is based around school exams, so sadly it's not very useful to game creation. I've mainly used Python too, so my knowledge of C# has been off of creating this game and a small amount of previous knowledge.

young warren
#

you at least understand variables, data types, functions, if statements and for loops?

forest saddle
# young warren then go from there

That's the problem, Ive tried tutorials, forumns etc... and none seen to work.

Let me try another tutorial and copy and paste my code and I can see if you can spot anything wrong with it?

young warren
#

it's not working because you probably don't understand what you're doing

#

try this one

forest saddle
#

Well yes as I mentioned above I am new to Unity, this is my first project ever on it, and I've been trying to find code related online but are not working and I'm following the steps exactly.

forest saddle
young warren
forest saddle
#

Oh awesome, thanks man :)

young warren
#

they're pinned in this channel

#

good luck

scarlet skiff
#

the 321 Animation UI gameobject has an animation with an animation event, in that event i wanna run a method but the method is in the script on the Game Manager, what is the best way to tell 321 Animation about the script that the Game Manager has?

pine bone
#

Hello, im making a building system but i encountered a problem. How can i make a gameobject only visual and not have any scripts or rigidbodies enabled. Should i create a "enabled" bool value inside every object and disable it when they are placed?

ivory bobcat
pine bone
slender nymph
#

or have a separate prefab just for the building visuals where it's just the mesh and the material that probably makes it transparent (since that's common for building mechanics)
then when the building is placed it spawns the real one with the working components on it

undone harbor
#

Do you guys use euler integration for movement? Or is it recommended to go the verlet route?

ivory bobcat
pine bone
#

Okay i will just disable all components when placing and reenable again after starting the game, thanks

young warren
#

@sour yew what's this Setup method you're talking about?

sour yew
#

hey guys. i have this script:

public class ToggleInventoryCanvas : MonoBehaviour
{
    public GameObject inventoryCanvas;
    // Start is called before the first frame update
    void Start()
    {
        inventoryCanvas.SetActive(false);
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Tab))
        { 
            inventoryCanvas.SetActive(true);
            Debug.Log("AAA");
        }
    }
}```
but when i press TAB, it doesnt make the canvas appear. can smb help me out? thx
sour yew
wintry quarry
sour yew
#

if Start method is empty, it does, but nothing happens to canvas. if Start method isnt empty, nothing happens at all

willow scroll
#

Can it be disabling itself?

slender nymph
#

or if this is still a child of the object being disabled, then of course it won't log anything when tab is pressed because it is still being disabled too

modest dust
#

It does log it if Start is empty because he doesn't disable the object

slender nymph
#

animation events will only call methods on the same object. so you need a method on that object that will listen for the event and call the relevant method on that other object

scarlet skiff
#

so there is no way around it, i have to give it a script

slender nymph
#

yes because the animation event cannot call a method on a completely separate object

sour yew
weary tulip
#

Does anyone know what would caused the player to not be able to hit enemies?
I have a Collider on the Enemy, a polygon collider on the sword animation for the player, the polygon collider is a trigger, and the knight enemy is not invincible. What else should I look at?

willow scroll
slender nymph
slender nymph
sour yew
#

ok. when the game starts, theres no canvas, when i press TAB, it appears, but when i press the TAB again, it doesnt go away. i was thinking about smth like this:

public class ToggleInventoryCanvas : MonoBehaviour
{
    public GameObject inventoryCanvas;
    public bool isIntentoryCanvasEnabled = false;

    // Start is called before the first frame update
    void Start()
    {
        inventoryCanvas.SetActive(false);
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Tab))
        {
            isIntentoryCanvasEnabled = !isIntentoryCanvasEnabled;
            inventoryCanvas.SetActive(isIntentoryCanvasEnabled);
            Debug.Log("AAA");
        }
    }
}

it works. TAB enables and disables the canvas. but the last thing im worried about is accessing field var directly. shouldnt i be using setter?

modest dust
slender nymph
#

the bool isn't necessary at all btw, you can just access the activeSelf property on the inventoryCanvas gameObject

sour yew
tough lagoon
slender nymph
modest dust
ivory bobcat
#

...SetActive(!...activeSelf)

modest dust
slender nymph
hot palm
ivory bobcat
willow scroll
sour yew
slender nymph
#

make them private and also serialize them
use properties to expose those private fields to other objects

rich egret
#
        {
            if (Input.GetButtonDown("Jump") && canMove && characterController.isGrounded)
            {
                moveDirection.y = jumpPower;
                Debug.Log("Jumping!");
            }
            else
            {
                moveDirection.y = -gravityForce * Time.deltaTime;
            }
        }
        else
        {
            moveDirection.y -= gravityForce * Time.deltaTime;
        }```

Why doesn't gravity work?
hot palm
willow scroll
hot palm
modest dust
hot palm
willow scroll
# sour yew so what should i use then? make fields private and use setters/getters? or keep ...

When choosing the access modifier for a field, use

  • private if it should just be accessed within the class
  • protected if it should also be accessed in the derived classes
  • public if it should also be accessed in all the other classes and serialized in the Inspector
  • [SerializeField] private if it should be serialized and just accessed within the class
  • [SerializeField] protected if it should be serialized and accessed within the class and its derived classes
  • [HideInInspector] public if it should be accessed from anywhere, but not serialized
hot palm
modest dust
willow scroll
hot palm
#

Yeah now it makes sense

main karma
#

hey so for level design purposes I need to know how much distance my character travels per second. I use a 3D vector and a character controller to move my character and I debugged the vector I used, the max value obtained on 1 axis being 10, now I want to know how to convert this information to actual distance/second and idk how

hot lily
#

is it better to do everything in a single script whenever possible (such as statuses, cooldowns combined with control script as one), or it is better to do everything separately?

hot palm
#

I like to keep it easy to read and do different behaviour in different scripts. I think it is generally seen as better to do so

main karma
#

per second I mean

modest dust
hot palm
hot palm
hot palm
modest dust
#

Divide the distance traversed by the time elapsed and you get velocity

main karma
#

yeah but idk how do I measure the distance traversed

willow scroll
modest dust
hot palm
#

I mean it's kinda the same what you move, if you do _Controller.Move(_Speed * Time.fixedDeltaTime * _MoveVector), with _MoveVector being normalized, then you move "_Speed" units per second

willow scroll
#

If the distance is 10 km and the time is 5 hours, the velocity is, obviously, 10 / 5 = 2 km/h

weary tulip
# slender nymph you've not really provided enough context to actually know what isn't working, b...

What do you do if you aren't receiving either message? They're both Dynamic body types, they both have rigidbody's, I've verified my OnTriggerEnter2D and OnTriggerExit2D are correct, there's a high likelihood my functions are correctly formatted because they work for the enemy, my Physics 2D is correct and they should only be able to attack the enemy hitbox (I have it set as "PlayerHitbox"), I'm not using a transform.position, and I'm not sure Continuous collision will matter as they aren't moving that fast, and there are no errors.

What else is there, I've looked over most of this stuff and it seems to be all correct?

main karma
slender nymph
weary tulip
main karma
#

worst part is that my character has acceleration too, so I need to reach maximum velocity before I start to measure the distance

#

anyways thanks for the help yall, gave me some cool ideas

modest dust
hot palm
willow scroll
weary tulip
willow scroll
hot palm
weary tulip
#

I'm not sure what to do then, as i'm fairly sure everything on the website boxfriend sent is correct

hollow dawn
#

how can I make the texture look high quality? it always comes out blurred like this

main karma
hot palm
# willow scroll Well, how do you reach the maximum velocity before measuring the distance, if, i...

This is how I set up a controller yesterday. currentSpeed is the units/per second I move (horizontally)

// Check if running
_IsRunning = IA_Controller.FPS.Run.ReadValue<float>() != 0f;

// Calculate the current speed
float currentSpeed = (_IsRunning) ? _Speed * _RunMult : _Speed;
currentSpeed += _SpeedBoostAmount;

// Set the movement Vector
Vector3 moveVector = (_InputVector.x * transform.right + _InputVector.y * transform.forward).normalized;

// Set the gravity Vector
Vector3 gravityVector = transform.up * _YVelocity;

// Move the character controller
_Controller.Move(currentSpeed * Time.fixedDeltaTime * moveVector + gravityVector);
main karma
#

one way to do this is just debug the value itself, wait for it to reach max value, and then just do a checkpoint there, and another one second later, then get the distance between them which is what I'm gonna do

#

@modest dust thanks for the suggestion

willow scroll
#

neither do you need the distance nor time in your case

#

Just multiply the distance with the speed and you get the static velocity

hot palm
#

Also you need to check your fixed timesteps, I think the default is 50fps

main karma
#

from my tests so far that checks out too

hot palm
#

Just the interval in seconds from last to current frame

#

If you call it in FixedUpdate, it retuns fixedDeltaTime tho

willow scroll
hot palm
#

"deltaTime inside MonoBehaviour.OnGUI is not reliable, because Unity might call it multiple times per frame."

sly mountain
#

Hey guys, i have some scrolling set up on my game screen, but i want it to work when my mouse is anywhere, not just over the buttons/gameobjects in my scene.

#

you can see in the video it scrolls when my mouse is over the gameobjects, but not the background

hot palm
#

Use a parent object with raycast hitbox

willow scroll
hot palm
#

Well apparently Time.deltaTime returns Time.fixedDeltaTime when used in FixedUpdate

sly mountain
hot palm
#

UI Elements have raycast padding. Boxes that check if your mouse is in them and behave accordingly. If you want to enable the full screen to drag, you can just put a big UI element such as a panel with transparent color as parent to all other UI elements

willow scroll
hot palm
#

Np, me too

willow scroll
#

I thought the Update's deltaTime being returned when using in the FixedUpdate

hot palm
#

Yeah me too

willow scroll
#

So it makes no difference whether to use fixedDeltaTime or deltaTime in the FixedUpdate

hot palm
#

Yep

#

Only question is when to use Update or FixedUpdate. For movement I do everything in FixedUpdate, for input reading I use Update and if I need to check values every second, I just use an IEnumerator

willow scroll
hot palm
#

Well yea, only I use cinemachine so I don't code camera movement

#

It's such a bliss

#

Free camera behaviour, one of the best packages imo

#

Works great with POV using a little workaround I came up with

willow scroll
#

I, honestly, hate using Cinemachine. I always love to code everything on my own and doing stuff with Cinemachine just makes it more complicated for me

charred spoke
#

Booh

#

Cinemachine is life. Cinemachine is love.

hot palm
#

Well I do code some stuff, such as camera speed and changing active virtual cameras

ivory bobcat
willow scroll
hot palm
#

Well then use it right xD

charred spoke
#

Everything will produce a bunch of bugs when used wrong that is true

sly mountain
hot palm
#

Try adding a new gameobject UI > Panel

#

Size it up to fit screen with width and height (probably 1920x1080)

willow scroll
willow scroll
sly mountain
willow scroll
sly mountain
#

oh

#

Tonks 👍

hot palm
#

btw careful with disabling Imagecomponents, it has a raycast target

ivory bobcat
#

Personally, I'd only use delta time unless I'm needing to read the fixed value of the physics delta time in Update or changing the value of fixed delta time - delta time is read only whereas you can make assignments to fixed delta time.

hot palm
#

Well fixed delta time scales with Time.timescale. So if you want to control stuff with one simple value it's easier to implement

willow scroll
#

(which still won't give you the desired frame rate when set to 10k)

ivory bobcat
sly mountain
#

:(

hot palm
#

It resets for some reason

#

Try checking the scroll system

sly mountain
#

mmh. Wait i think i may have solved it let me check..

willow scroll
sly mountain
#

yup i had to change the size of scroll area

#

i didnt realise cause the tutorial i was watching skipped that

uncut shoal
#

I'm using Graphics.DrawMesh to draw the meshes of my chunks, but I want to make it so it doesn't draw the chunks that are outside of the camera, how do I do that?

#

do I just assume the camera is a square and check if the camera bounds and the chunk bounds intersect or not?

charred spoke
uncut shoal
#

I think that is for 3D?

charred spoke
#

It should work for a ortho cam as well

#

Then again I have not done 2d so I dont really know

rich egret
#
        {
            if (Input.GetButtonDown("Jump") && canMove && characterController.isGrounded)
            {
                moveDirection.y = jumpPower;
                Debug.Log("Jumping!");
            }
            else if (characterController.isGrounded)
            {
                moveDirection.y = gravityForce * Time.deltaTime;
            }
        }
        else
        {
            moveDirection.y -= gravityForce * Time.deltaTime;
        }```

Anyone know how to do gravity after the character jumps??
hot palm
rich egret
calm hare
#

hello i wwant to make some sprites for my game and i dont know which apps to use

hot palm
#

Grounded and characterController.isGrounded

#

Then you permanentely add gravity, unless you are grounded

rich egret
hot palm
#

You also have to reset y velocity to 0 if you are grounded, and the y velocity is below 0

rich egret
#
        {
            if (Input.GetButtonDown("Jump") && canMove && characterController.isGrounded)
            {
                moveDirection.y = jumpPower;
                Debug.Log("Jumping!");
            }
            else
            {
                moveDirection.y -= gravityForce * Time.deltaTime;
            }
        }```
hot palm
#

bcs if you set it to 0 when grounded, you couldnt jump lol

calm hare
#

can anyone tell me

#

any apps to use

hot palm
calm hare
#

im not planning on making pixel art any time soon

#

but i will prob use this later

hot palm
calm hare
#

alr thanks il see it

hot palm
#

Official page, it's better than MS paint or paint 3D

#

(unless you want to view 3D stuff)

rich egret
#

@hot palm Something like that?

        {
            if (Input.GetButtonDown("Jump") && canMove)
            {
                moveDirection.y = jumpPower;
                Debug.Log("Jumping!");
            }
            else if (moveDirection.y < 0)
            {
                moveDirection.y = 0f; // Reset Y velocity when going down and grounded
            }
        }
        else
        {
            moveDirection.y -= gravityForce * Time.deltaTime;
        }```
hot palm
#

Nice was going to comment xD

#

Well why use canMove

#

Is it for pausing player movement?

#

Or for checking if he can walk on xz plane?

rich egret
hot palm
#

Aight

rich egret
#

No, but ignore it, it doesn't bother you, the log works

rich egret
hot palm
#

Is your ground check working properly?

rich egret
hot palm
#

Add gravity outside this if statement and see if it works

#

Or do you see the moveDirection.y going down or not

#

You can check debug inspector if it's a private vector3

#

How my controller works

// Calculate y velocity
if (!_IsGrounded)
{
    // Add negative y velocity
    _YVelocity += _Gravity * Time.fixedDeltaTime;
}
else if (_YVelocity < 0.0f)
{
    // Reset y velocity
    _YVelocity = 0.0f;

    // Reset jumps
    _JumpsAvailable = _MaxJumps;
    _CanJump = true;
}
rich egret
#

I just changed this line:
if (characterController.isGrounded)
to this:
if (Grounded)

#

Now there is gravity but when I jump, there is no gravity

hot palm
#

How do you check if the controller is grounded?

rich egret
hot palm
#

Hm just copy paste your !code in the player move script to a website here and send the link

eternal falconBOT
hot palm
#

I think we're missing something important

hot palm
#

oh god

#

xD

#

Aight let me see

#

Do you understand your code?

rich egret
hot palm
#

Well firstly please for the love of god use [SerializeField] private and not public

swift elbow
hot palm
willow scroll
#

I don't think there's anything wrong with them using public

hot palm
#

All fields only used in the own class/script should be private

#

Nuhuh 🗣️

#

Well you can do what you want

swift elbow
hot palm
#

But ppl working with you will thank you

rich egret
hot palm
#

Yeah just what I saw

willow scroll
#

Yes, putting [SerializeField] private instead of public won't fix the issue, whatever it is, as I haven't read it yet

hot palm
#

Yeah that not

#

but probably this

rich egret
# hot palm Yeah just what I saw

So for now the code is:

        {
            if (Input.GetButtonDown("Jump") && canMove)
            {
                moveDirection.y = jumpPower;
                Debug.Log("Jumping!");
            }
            else if (moveDirection.y < 0)
            {
                moveDirection.y = 0f; // Reset Y velocity when going down and grounded
            }
        }
        else
        {
            moveDirection.y -= gravityForce * Time.deltaTime;
        }```
#

The problem is that there is no gravity after the character has jumped and it floats

hot palm
#

use debug logs

#

see if the code is executed

#

bcs I don't see any apparent reason it shouldn't

rich egret
hot palm
#
 moveDirection.y -= gravityForce * Time.deltaTime;
``` does?
rich egret
#

I get a notification when I jump

hot palm
#

Your problem is no gravity

#

so check if gravity is changed

willow scroll
hot palm
#
  • if y velocity is changed
rich egret
hot palm
#

Bcs you never call the boolean

rich egret
willow scroll
hot palm
#

Just do this before the if statement

isGrounded = Physics.Raycast(transform.position, -Vector3.up, raycastDistance);
#

You never call IsGrounded(), do you?

hot palm
#

This is a function he uses

hot palm
undone harbor
#
    {
        RaycastHit hit;
        if (Physics.Raycast(transform.position, -transform.up, out hit, 1f))
        {
            return true;
        }
        else
        {
            
            return false;
        }
    }
}```
#

Does this look correct?

#

I am not sure why this return false

hot palm
#

If the transform.position is higher than 1 above the ground, it never collides with it

undone harbor
#

transform's y is 0 btw

willow scroll
hot palm
undone harbor
hot palm
#

Well just do it in one line

#
_IsGrounded = Physics.SphereCast(transform.position, _GroundCheckRadius, -transform.up, out RaycastHit _, _GroundCheckRange);
#

This is what I use

undone harbor
#

Gotcha, let me try this

willow scroll
rich egret
#
    {
        return Physics.Raycast(transform.position, -Vector3.up, raycastDistance);
    }

    private void Update()
    {
        Grounded = IsGrounded();

        if (Grounded)
        {
            if (Input.GetButtonDown("Jump") && canMove)
            {
                moveDirection.y = jumpPower;
                Debug.Log("Jumping!");
            }
            else if (moveDirection.y < 0)
            {
                moveDirection.y = 0f; // Reset Y velocity when going down and grounded
            }
        }
        else
        {
            moveDirection.y -= gravityForce * Time.deltaTime;
            Debug.Log("Hmmmm");
        }
    }```
#

something like that?

hot palm
#

Yeah

willow scroll
#

No

#

Don't forget to use the layer mask!

rich egret
#

yes or no? 😂

hot palm
#

But you can just do it in the line

#

LayerMask is not necessary if you want to walk on everything

#

+with a collider

willow scroll
rich egret
willow scroll
hot palm
undone harbor
willow scroll
hot palm
undone harbor
hot palm
languid spire
hot palm
willow scroll
vagrant fjord
#

i have a bullet script and even though i am trying to make it dissapear when colliding with an object it just phases through. ill link code here: https://gdl.space/tuqulugoqu.cs

rich egret
#

The answer from the logs:
Is Grounded: False

#

Because there is no gravity

willow scroll
vocal marlin
hot palm
vagrant fjord
#

ok ill try

rich egret
hot palm
undone harbor
hot palm
#

then do 0.2f or something

willow scroll
rich egret
#

So obviously there will be no ground

undone harbor
#

The players transform

#

which is at y = 0, initially

willow scroll
#

What is the radius?

undone harbor
#

0.3f

willow scroll
#

And what are you trying to detect?

undone harbor
#

Just a plane with meshCollider

spice ravine
#

can someone who is quite good with unity dm me? please tell me if that's against the rules to ask

vagrant fjord
vocal marlin
#

Only one should be a trigger

rich adder
vagrant fjord
spice ravine
#

you can cntrl+ f and search for my name

graceful lintel
vagrant fjord
#

no

#

im using box collider]

vocal marlin
#

neither?

spice ravine
#

I tried getting help in this chat in the past

graceful lintel
#

there you go. you need atleast 1 to have a rigidbody component for collision to be possible

vagrant fjord
#

ok ill try that

spice ravine
#

is there is post area for 'help' here?

hot palm
graceful lintel
spice ravine
#

it's code wize

graceful lintel
#

just lay it here my guy

#

if I dont reply means I have no clue

vagrant fjord
#

still doesnt work do i have to use gravity

hot palm
#

I think you are better off reading into unity documentation

rich egret
#

@hot palm 👑

spice ravine
queen adder
#

how can i stop these from spawning under the main camera?

hot palm
spice ravine
#

I spent the last 15 hours working on a project, and I know the basics now, but I have several issues,
I would love if someone would take some time to Help me figure up the solution for thsi code (I made the base, then put it serveral times in chat gpt (I started learning Unity TODAY.))

sorry for the chunk of text

if someone is willing to help me, here is the code

rich adder
hot palm
hot palm
trail chasm
#

hello i made a renderer place him behind the button in my canvas but the game still think he is infront of and i cant click the button any idea why?

hot palm
#

Parent

  • Background
  • Button
    You would want it like this
trail chasm
hot palm
#

Yeh wrong order

trail chasm
#

oh thanks

hot palm
#

It may work after that

#

may not

#

There are multiple reasons it couldn't work

spice ravine
#

That's the thing, I am VERY new, I tried figuring out the bugs that it throws at me, but there is
no more bugs,

The main problem is that When I click 'Next' after I go into the part when I need to enter 1,2 or 3 to progress
in the creature fight, I can't choose anything

rich adder
eternal falconBOT
hot palm
#

This is a very specific problem and I recommend redoing all your code to make it readable for yourself and others

#

Or try to send your code and have luck with someone trying to solve it

hot palm