#💻┃code-beginner

1 messages · Page 554 of 1

cosmic dagger
thorn tree
#

thanks

polar acorn
#

A kinematic rigid body exerts forces but does not respond to them. A kinematic rigid body moving through a field of boxes with normal rigidbodies will push them aside, but not be slowed down by them. This makes it useful for characters that are being directly controlled so you can interact with your environment without losing any sense of control over the character.

junior ether
#

How to set GameObject variable the "GameObject" that the script is in?

eternal sierra
#

thanks bro

tight latch
#

i need help with a attack script on a dummy

eternal sierra
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour {

    [SerializeField] private float moveSpeed = 7f;

    private void Update() {
        Vector2 inputVector = new Vector2(0, 0);

        if (Input.GetKey(KeyCode.W)) {
            inputVector.y = +1;
        }
        if (Input.GetKey(KeyCode.S)) {
            inputVector.y = -1;
        }
        if (Input.GetKey(KeyCode.A)) {
            inputVector.x = -1;
        }
        if (Input.GetKey(KeyCode.D)) {
            inputVector.x = +1;
        }



        inputVector = inputVector.normalized;

        Vector3 moveDir = new Vector3(inputVector.x, 0f, inputVector.y);
        Debug.Log(moveDir);
        Debug.Log(inputVector);
        transform.position += moveDir * moveSpeed * Time.deltaTime;
        float rotateSpeed = 10f;
        //transform.forward = moveDir;
        transform.forward = Vector3.Slerp(transform.forward, moveDir, Time.deltaTime * rotateSpeed);
        Debug.Log(transform.forward);

    }

}

I have Doubt in this code , When i use
transform.forward = moveDir;
it reverts back to (0,0,0)
but when i use
transform.forward = Vector3.Slerp(transform.forward, moveDir, Time.deltaTime * rotateSpeed);
it does not revert back to (0,0,0)

cosmic dagger
junior ether
#

im just a little confuse and trying to ge the hang of it but i get it now

cosmic dagger
junior ether
#

thx man

swift crag
#

You can find all of the members of MonoBehaviour here!

#

notably, this section

junior ether
#

How to use a method from a script to another script?

frail hawk
#

make your method public and inside the script you want to access the method you simply create a reference to the script that holds your method.

junior ether
#

how to creat that reference?

frail hawk
#

[SerializeField] Scriptname scriptname; //assing the script via inspector and you can acces the method with
scriptname.yourmethod()

junior ether
#

thxxx

rancid badger
#

hello, i am trying to add a pause menu using dotween

public void OnPauseButtonPressed()
    {
        isPaused = !isPaused;
        Time.timeScale = isPaused ? 0f : 1f;

        if (isPaused)
        {
            pausePanel.SetActive(true);
            blockingPanel.SetActive(true);
            pausePanelRect.DOScale(originalScale, animationDuration)
                .SetEase(Ease.OutBack)
                .SetUpdate(true);
        }
        else
        {
            pausePanelRect.DOScale(Vector3.zero, animationDuration)
                .SetEase(Ease.InBack)
                .SetUpdate(true)
                .OnComplete(() =>
                {
                    pausePanel.SetActive(false);
                    blockingPanel.SetActive(false);
                });
        }
    }

the pause works, when i unpause animation plays but then panels are not deactivated and timescale doesnt change, any idea what im doing wrong?

frail hawk
#

see if it behaves as intended. you could also use debug log inside the if statements to see if these are being reached

shy kite
#

How can i make it so in a 2d game, the camera smoothly follows the player. When i directly change the x and y position of the cam to the one of the player, it's shakey, even when using SmoothDamp. When in the scene, i set the camera to inherit and follow the player, it doesn't shake but i cannot control the lag the camera moves to follow the player

How would i go about it?

naive pawn
shy kite
cosmic dagger
cosmic dagger
# shy kite yup, that was the saving grace not the offset, thanks

you're trying to set the camera during the same frame the player is moving. there is no way to determine if the camera or the player Update runs first. LateUpdate runs after every Update, ensuring the player has finished moving before updating the camera . . .

midnight jolt
#

Hello everyone.

While my code does work, I'm seeking a more elegant solution.
My code thus far:

initialPanel.transform.GetChild(1).GetChild(0).GetComponent<Button>().interactable = hover;
initialPanel.transform.GetChild(1).GetChild(1).GetComponent<Button>().interactable = hover;
add.transform.GetChild(1).GetChild(0).GetComponent<Button>().interactable = hover;
add.transform.GetChild(1).GetChild(1).GetComponent<Button>().interactable = hover;```

Sure, I could add separate GameObjects to each button but it's worth mentioning that I'm also performing operations on the button's (gameobject's) parent:

```cs
infoPanel.SetActive(true);
initialPanel.SetActive(true);
add.SetActive(false);```

So I would have 5 seperate GameObjects. Surely there must be a better way?
#

(the first .GetChild(1) fetches the parent of the button)

swift crag
#

Oh noooooooooooooooooo

midnight jolt
#

ik im sorry 😭

swift crag
#

hey I used to do this too

#

It looks like have two buttons you need to modify

midnight jolt
#

Indeed

swift crag
#

You should just refer to them directly

#
[SerializeField] private Button fooButton;
#

As an example: if you're making a little popup dialog window, you might have this

#
public class PopupWindow : MonoBehaviour {
  [SerializeField] private Button okButton;

  void Awake() {
    okButton.onClick.AddListener(Close);
  }

  void Close() {
    Destroy(gameObject);
  }
}
#

the window would also have methods to actually..show text to the player, of course

naive pawn
languid spire
#

So why would you advise only doing half the job via the inspector? What's wrong with setting the onclick event there as well?

swift crag
#

But then there would be no need for a Button reference at all 😉

#

and the example vanishes in a puff of logic

midnight jolt
swift crag
cosmic dagger
midnight jolt
#

Anyhow, thanks. I'm trying to keep my code clean before it's too late 😆

swift crag
#

In general, you should prefer explicit references

#

If you're instantiating a prefab, give it a component that holds the references you need

#

and reference the prefab as that type, rather than as a GameObject

#

You'll often start out with a dumb "bag of references" that later gains its own functionality

cosmic dagger
burnt vapor
#

On top of that, using LateUpdate in general is bad design

#

The whole point of LateUpdate was actually for the camera, but imagine if something else now requires to be executed after the camera

#

It's strict and cumbersome to work with. Better to make your own system of invokations if you need to invoke in order

swift crag
#

It is useful as a "post-animator" step

burnt vapor
#

I suppose I do think way ahead with the whole "don't use LateUpdate" remark but I really dislike when something is limiting my code like that

swift crag
#

I run stuff there (with a very late script execution order) so that I can access the positions of objects once animation and IK have been applied

frail hawk
#

tbh i never had any case where i had to use LateUpdate

swift crag
#

I only really run a "ticker" component whose sole job is to tell other components to run

#

I also have to make sure Cinemachine updates after this, because I need to move some targets into their final positions

#

it's a dependency graph!

#

game logic <- animator updates <- IK <- spline manipulations (i have splines whose knots are parented to things that are animated) <- camera update

#

I am working to get rid of evil stuff, like embedding packages solely so I can edit their script execution orders

#

(and replacing that with manual execution)

midnight jolt
#

So uh, @swift crag , is this better? 😭

[SerializeField] private GameObject infoPanel;
[SerializeField] private GameObject initialPanel;
[SerializeField] private GameObject add;
[SerializeField] private Button properties;
[SerializeField] private Button delete;
[SerializeField] private Button element;
[SerializeField] private Button compound;
[SerializeField] private TextMeshProUGUI title;```
#

instead of accessing each child

swift crag
#

Ideally "infoPanel" and "initialPanel" would have custom component types on them that hold more references

midnight jolt
swift crag
#

it's just one of the "templates" you can add through the GameObject menu

midnight jolt
swift crag
#

I used to think panels were somehow special :p

midnight jolt
#

Ok yeah got it to work now

#

Thanks again

#

Alright. It's Christmas Dinner time. I wish you merry christmas and no bugs in your games!!

sterile radish
#

hi, im making a doodle jump clone and i want to add spring and jetpacks on certain platforms. i want the jetpacks to be rarer than the springs, so i made their chances to spawn 2.5% and 5% respectively. however when i roll a random number to spawn them, if i roll a jetpack, it's already smaller than the spring's chance so it will spawn both of them on the platform. how can i fix this?

https://hastebin.skyra.pw/ukiqulewis.pgsql

swift crag
#

If all of the odds add up to less than 100% (as one would hope), you can subtract each one from the result and see if your random value is now less <= 0

#

so, for example: if your random value is 0.06 and the first chance is 0.025, you subtract that to get 0.035

#

this is more than zero, so that event doesn't happen

#

then you subtract 0.05 for a 5%-chance event, giving you -0.015

#

this is <= 0, so this event happens and you stop

naive pawn
#

(in your case, you could say you have a 92.5% chance to not get anything)

#

this is if you are choosing a random choice

#

if instead, they are separate events, you would use 2 random values for each event, leading to a 0.125% chance to get both

frank sigil
# sterile radish hi, im making a doodle jump clone and i want to add spring and jetpacks on certa...

There's more than one way to make this happen, and some cleaner approaches, for a quick an dirty fix you can approach it like this without changing much of your initial code. But there's a mathematical problem with this.

public void AddGoodies(GameObject spawnedPlatform)
{
        float random = Random.value;

        GameObject thingToSpawn = null;
        Vector3 spawnPosition = Vector3.zero;

        if (random < (springChance / 100))
        {
                spawnPosition = spawnedPlatform.transform.position + new Vector3(Random.Range(-spawnedPlatform.GetComponent<SpriteRenderer>().bounds.size.x / 2 * 0.8f, spawnedPlatform.GetComponent<SpriteRenderer>().bounds.size.x / 2 * 0.8f), spawnedPlatform.GetComponent<SpriteRenderer>().bounds.size.y / 2, 0);
                thingToSpawn = spring;
        }

        if (random < (jetpackChance / 100))
        {
                spawnPosition = spawnedPlatform.transform.position + new Vector3(Random.Range(-spawnedPlatform.GetComponent<SpriteRenderer>().bounds.size.x / 2 * 0.8f, spawnedPlatform.GetComponent<SpriteRenderer>().bounds.size.x / 2 * 0.8f), spawnedPlatform.GetComponent<SpriteRenderer>().bounds.size.y / 2, 0);
                thingToSpawn = jetpack;

        }
        if (thingToSpawn != null)
        {
                Instantiate(thingToSpawn, spawnPosition, Quaternion.identity);
        }
}

The problem with the approach you have is if spring has 5% and jetpack has 2.5%, but they use the same random number. so 5% of the jetpack is always gonna be result to spring to spawn so it's equal to not spawning the spring which in reality decreases the chance of the spring the spawn by the possibly of the jetpack which will result to 5 - 2.5 = 2.5 so spring will also have 2.5% chance to spawn in reality.

naive pawn
sterile radish
swift crag
#

Even better: spawnedPlatform should be a Platform, not a GameObject

#

you'd create a Platform component that can tell you where a spawned item should go

#

so that this code would never touch a SpriteRenderer at all

frank sigil
trail gulch
#

hi
whats the easiest way to paint on a 3d object?

swift crag
#

are you asking how to do this at runtime (in-game) or while creating assets for your game?

frank sigil
trail gulch
# swift crag are you asking how to do this at runtime (in-game) or while creating assets for ...

at runtime

// Write black pixels onto the GameObject that is located
// by the script. The script is attached to the camera.
// Determine where the collider hits and modify the texture at that point.
//
// Note that the MeshCollider on the GameObject must have Convex turned off. This allows
// concave GameObjects to be included in collision in this example.
//
// Also to allow the texture to be updated by mouse button clicks it must have the Read/Write
// Enabled option set to true in its Advanced import settings.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Camera cam;

    void Start()
    {
        cam = GetComponent<Camera>();
    }

    void Update()
    {
        if (!Input.GetMouseButton(0))
            return;

        RaycastHit hit;
        if (!Physics.Raycast(cam.ScreenPointToRay(Input.mousePosition), out hit))
            return;

        Renderer rend = hit.transform.GetComponent<Renderer>();
        MeshCollider meshCollider = hit.collider as MeshCollider;

        if (rend == null || rend.sharedMaterial == null || rend.sharedMaterial.mainTexture == null || meshCollider == null)
            return;

        Texture2D tex = rend.material.mainTexture as Texture2D;
        Vector2 pixelUV = hit.textureCoord;
        pixelUV.x *= tex.width;
        pixelUV.y *= tex.height;

        tex.SetPixel((int)pixelUV.x, (int)pixelUV.y, Color.black);
        tex.Apply();
    }
}

i tried this from the docs
but is not working, and i checked everything
no errors, but is not painting

eternal falconBOT
frank sigil
swift crag
#

that would tint the entire material

swift crag
#

If the texture isn't read/write enabled then this won't do anything

trail gulch
#

i enabled that

frank sigil
frank sigil
trail gulch
#

hm i dont know, how do i check that?
i only changed the to hurp one because everyhing that i imported was pink

#

i think i need something here

swift crag
#

you may have installed the HDRP package, but that wouldn't do anything on its own

#

(and you should not be trying to switch render pipelines on a whim!)

trail gulch
#

ok, i was about to mess things up

final kestrel
#

Hi all. What is the best way to pass around an object of a plain c# class to modify it from other scripts?

swift crag
#

just...pass a reference as usual?

#

you can't serialize a reference in the inspector because your class is not a kind of unity object, of course

cosmic dagger
#

pass it normally, like an argument in a method . . .

cosmic quail
#

if you want to pass it in the inspector you can make it a scriptable object

cosmic dagger
#

should other scripts modify it, or call method on the enclosing script (where the C# instance exists) to modify it?

final kestrel
#

Like say I have a monster class and create monster1 in a script. I want to access that monster1 instance from another script. I'm asking what is the way to do it.

swift crag
#

what is "another script"?

#

are you talking about components attached to game objects here?

final kestrel
#

MonsterManager to increase or decrease health for example

swift crag
#

I don't understand why you're asking this question. You give the object to whoever needs it

#

Maybe you're trying to figure out how to find the second component..?

#

the one that needs to be given the monster object?

cosmic quail
swift crag
#

Monster is not a kind of unity object

final kestrel
#

yeah nope. Its just a c# class. I got a bit confused here. I'll come back once I figure what got me confused 🙂 thanks

fervent abyss
#

guys can somebody help me with this. i actually have no idea how to stop this flipping effect

surreal zephyr
#

hey how do I make a pause in the middle of a loop

cosmic dagger
#

place everything in a coroutine . . .

#

pause inside the coroutine . . .

surreal zephyr
#

alright thanks

lone barn
#

I'm having issues with MonoBehavior.OnGUI. If I take an snippet from the official documentation, Unity only renders button shapes and complains with "Can't Generate Mesh, No Font Asset has been assigned"

#

I think I'm missing a setting here, but I've searched for a bit and can't seem to find where I could specify a font

swift crag
#

I had a problem with this on my Steam Deck

#

for whatever reason there was just..no font

#

I wound up stuffing this into an OnGUI method

#
if (!fontInitialized)
{
    GUI.skin.font = font;
    GUI.skin.GetStyle("Toggle").font = font;
    GUI.skin.GetStyle("Label").font = font;

    fontInitialized = true;
}

where font is a field holding a Font object

lone barn
#

thanks a lot, this fixes my issue, I wonder why he is not able to reach the default font

swift crag
#

I'm not sure why it happened on my Deck either :p

vocal orchid
#

How can move a gameobject that have a rigibody kinemactic?

surreal zephyr
#

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

public class MovingThings : MonoBehaviour
{
public GameObject Target2;
public float WaitTime;
public GameObject Target;
public float Speed;
// happen at game start
void Start()
{

}

//Constant load
void Update()
{
    {
        {
            //everything that has a wait time
            StartCoroutine(Wait());
        }
        IEnumerator Wait()
        {
            for (int i = 0; i < 10;)
            {
                //moves to point 1
                transform.position = Vector3.MoveTowards(transform.position, Target.transform.position, Speed * Time.deltaTime);
                yield return new WaitForSeconds(WaitTime);
                //moves to point 2
                transform.position = Vector3.MoveTowards(transform.position, Target2.transform.position, Speed * Time.deltaTime);
            }
        }   
        
    }
}

}

#

why isnt it going back and forth between the 2 game objects

slender nymph
#

MoveTowards does not happen over time, you need to call it each frame for the duration of your move. also you're starting the coroutine potentially hundreds of times

swift crag
#

MoveTowards computes a position that's closer to the destination. That's all it does.

rocky canyon
#

PingPong would go back and forth

swift crag
#

It does not, inherently, cause something to slowly move

surreal zephyr
#

what would I replace Move towards with then

swift crag
#

Perhaps you want to repeatedly move towards the target until you're close enough

#

you're only moving once, which doesn't make any sense

rocky canyon
surreal zephyr
#

Yes that is exactly what I wanted thank you

wispy coral
#

is it allowed in the rules to post a snippet of code i dont understand how it works and someone explaining it?

#

because i just followed a tutorial for a fps camera controller and i have no idea how it works

frosty hound
#

You can, but if watching the tutorial it's from wasn't enough to explain it, I'm not sure how anyone can help by reiterating it. But you can try.

wispy coral
#

alright thanks

#
{ 

    lookleftright = Input.GetAxisRaw("Mouse X") * sensX * Time.deltaTime;
    lookUpDown = Input.GetAxisRaw("Mouse Y") * sensY * Time.deltaTime;

    xRotation -= lookUpDown;
    xRotation = Mathf.Clamp(xRotation, -90, 90);

    transform.localRotation = Quaternion.Euler(xRotation, 0, 0);



}```
#

i followed a brackeys tutorial for this and im not really sure whats going on, and also the rotation on the y axis is not working

#

where i get the input?

slender nymph
frail hawk
#

sry it is actually right

slender nymph
#

as for why rotation around the Y axis isn't working, that is likely due to you not actually rotating anything about the Y axis currently

slender nymph
wispy coral
#

so should i add a transform.localRotation = Quaternion.Euler(0 ,xRotation, 0);?

slender nymph
#

no because that would be incorrect

#

why don't you pay attention to the tutorial and find out what the tutorial expects you to do for rotation around the Y axis

wispy coral
#

alright

#

found out the problem, thanks

#

but the single thing i dont understand is why the xRotation -= lookUpDown;

slender nymph
#

because you want to accumulate the rotation so that it can be correctly clamped, so it has a variable that stores that accumulation which you then add or subtract the mouse's up/down movement to actually perform the accumulation

wispy coral
#

ok ok got it

#

thanks

frail hawk
#

if you are only learning it is fine but if you plan to implement it into your game you should probably look into the new input system instead

slender nymph
#

there's documentation pinned in #🖱️┃input-system to learn how to use it. if you are just starting out and following tutorials, then just stick to the tutorials. though you would be much better off by following a structured course rather than random tutorials made by people who barely know what they are doing

stark crown
#

does anybody here code malbolge like me?

slender nymph
#

this is a unity server with no off topic allowed

stark crown
#

just wondering

#

thats not off topic

#

this is a channel about coding and i asked a simple question

slender nymph
#

it's an esoteric language that has nothing to do with unity. it is off topic.

stark crown
#

i mean both of em use code so i dont know the problem

slender nymph
#

has nothing to do with unity

slender nymph
#

no, there are beginner c# courses pinned in this channel

stark crown
#

alright thanks

azure nest
#

ey can someone help me out ? im trying to show the name/tag of every game object. currently im iterating through every gameobject in the scene with a foreach loop and outputting it to the screen with w2s and a gui label, but its EXTREMELY laggy because of how im iterating through every single game object every frame. is there a faster way to do this?

#

idk how else to get every game object without just iterating through every single one

frail hawk
#

you could simply cache the gameobjects in an array or list of gameObjects.

#

what are you trying to achive actually

azure nest
#

idk, im just messing around with this singleplayer game out of curiousity.

#

woulddnt i still have to iterate through it with a foreach loop?

slender nymph
#

modding discussions are not permitted here

azure nest
#

oh

#

sorry ;x

waxen adder
#

I have a base class called "Ability". With my knowledge at the moment, if I were to make a new ability, I would have to create a whole new c# script to define a new ability that extends the "Ability" base class. Sounds alright for now, but what if I wanted to define 5 new abilities? 10? 30? 100? The amount of script spam in my project just for abilities seems like it would be intense. Anyone have a better idea on what to do here?

slender nymph
#

well it depends, if these abilities do the same thing but with different stats, then it's just a matter of reusing the same objects and assigning different stats to them. but if they need different behavior then yes, you will need to write new code for that behavior. this is expected

#

it is also not "script spam" to have many scripts that do different things. that is how it should work

waxen adder
#

Makes sense. I suppose if I were really concerned about my organization, I could put all these abilities into different folders

swift crag
#

you should write new code when you do a fundamentally new thing

#

"Abilities" are a very common pain point -- you want to re-use many aspects (like "shoot a projectile" or "affect an area"), but it can be very difficult to make these behaviors reusable

obsidian plaza
acoustic sequoia
# waxen adder I have a base class called "Ability". With my knowledge at the moment, if I were...

Your mentality about the situation is good, but I don’t think it matters if you have 100 different ability scripts. The only problem with that is probably organizing them. Performance is nothing to worry about with that. Literally makes no difference. But you also could just make your 100 scripts messy and it wouldn’t change anything about your game either.

What we are comparing here is the difference between a well organized project and a not organized project.

One of which will allow you to make changes or add new abilities in a much easier/efficient way subjectively

silk meteor
#

you could create all your abilities in one script, and then reference them from that script

acoustic sequoia
# waxen adder I have a base class called "Ability". With my knowledge at the moment, if I were...

What I would do is categorize all your abilities into notepad find out how many of those abilities are actually performing different actions, which is probably only like 5-10 from the 100 abilities.

Then you can make scriptable objects for each ability with like an enum that points to which “type” of ability it is so it can attach the correct script to it.

But there will always be new code that you will need to write for each ability. So what’s the point or creating only 5 scripts for 100 abilities and scriptable objects? Simply to make “adding” a new ability easier. That’s it

slender nymph
#

and don't crosspost

dire flare
#

Okk

robust condor
#

Anyone use a global EventBus or just rely on C# events?

stark rune
#

the object its supposed to hit has a collider and has the tag fuel onn it

slender nymph
#

have you configured that code is actually running?

#

after you confirm it runs, double check your parameters

stark rune
#

the raycast functrion doesnt work i tried debugging it was showing

slender nymph
#

please re-read my messages again

stark rune
#

i mean wasnt my bad

#

oh yeah it is

stark rune
slender nymph
#

okay so now read the second message

stark rune
#

yea i double checked

slender nymph
#

so you think the parameters are correct then?

stark rune
#

i think probably

slender nymph
slender nymph
#

so based on the documentation and your code, what do you think might be wrong?

stark rune
stark rune
slender nymph
#

alright, you've clearly not bothered actually reading anything that has been said so i'm out. good luck.

slender nymph
#

so then what is wrong with the parameters you've used for the raycast method

swift crag
#

because there is, 100%, a problem with the parameters you've passed to Physics.Raycast

stark rune
slender nymph
#

no

stark rune
slender nymph
#

your Ray and your Physics.Raycast call were entirely separate and had nothing to do with each other

slender nymph
#

if it is working now, then you've changed more than just the parameters for the Ray constructor because, again, that has nothing at all to do with your Physics.Raycast since you weren't using the Ray anywhere

slender nymph
#

yeah, you're actually using the ray now which means the parameters for Physics.Raycast are correct. but you can make the ray a local variable again and just construct it on the line before the Raycast like you were doing before

#

it will work provided you're still using the correct parameters for it

wispy coral
#

could someone explain to me like im 5 what serializing is and what its for?

zenith cypress
# wispy coral could someone explain to me like im 5 what serializing is and what its for?

Serializing is basically saving a piece of information so you can use it later.

Say you want to have a timer on screen that counts up. That's cool, but what if the player turns off the game? Then the timer would be 0 when they open it back up! This is where serialization comes in.

You can take your timer number (typically a float/double for seconds) and save that to a file. Can be JSON, just the raw number, or some other format, PlayerPrefs, it doesn't matter. Then when the player loads up the game again, you can take that file, read it, then turn it back into your timer number (this is deserialization). And voila, the timer starts from where it was!

Unity does this for all of its assets as well. You can open any .asset and view their contents, which are typically in the YAML text format.

tldr;
Serialization: data -> savable format
Deserialization: savable format -> data

wispy coral
#

actually understood pretty well

swift crag
wispy coral
waxen pendant
#

I am trying to raycast a surface to get its slope, but raycast doesnt hit at all
Physics.Raycast(transform.position, Vector3.down, out hit, 1.5f)

#

On drawing a debug line, it does go through the surface Debug.DrawRay(transform.position, Vector3.down*1.5f, Color.red);

swift crag
#

It's probably starting underground.

#

Consider backing the ray up a little

waxen pendant
#

so have a -y in starting position?

timber tide
#

Yeah if it starts inside of the collider it wont detect it at all

swift crag
#

in this case, since you're using Vector3.down, you'd subtract, say, Vector3.down * 0.1f

waxen pendant
#

yup that worked. thanks

#

spent an hour trying to figure what was going wrong lol, and it was this simple thing

#

even chatgpt didnt suggest that

wispy coral
#

anyone know why with the new imput manager you need alot of speed to move something? or is it just me

swift crag
#

e.g. just log the number that the input action is giving you

wispy coral
#

let me try that

cosmic dagger
#

probably a setup issue to retrieve the value. what is your default speed, and are you scaling it?

wispy coral
swift crag
#

show us the code you are using

#

but I'm going to take a wild guess

wispy coral
#

just a sec

#

alright give it a shot

swift crag
#
rb.AddForce(10 * input * Time.deltaTime);

this would be wrong

cosmic dagger
wispy coral
#

ohh

#

i see

swift crag
#

AddForce represents a continuous force

#

You tell it how hard you're pushing

#

(at least, it does in the default force mode!)

cosmic dagger
#

you don't need to use deltaTime with physics movement. it's already implied in the calculation . . .

swift crag
#

This would be more correct if you were doing rb.AddForce(whatever, ForceMode.Impulse) -- in that case, you're telling it how hard you're hitting the object instantaneously

wispy coral
swift crag
#

But at that point, just use the normal force mode and don't try to include deltaTime :p

wispy coral
#

got it

swift crag
#

you don't just use it to make your code correct!

#

It's used to convert a rate into an amount

wispy coral
swift crag
#
transform.position += Vector3.right * Time.deltaTime;

This treats Vector3.right as a velocity. I convert it to a distance by multiplying it by deltaTime

#
rb.velocity = Vector3.right * Time.deltaTime;

This is wrong. A velocity is a velocity.

cosmic dagger
swift crag
#

Multiplying by deltaTime implies we want to turn it into a distance, but that's bogus

night mural
# wispy coral they always make it seem like it, its crazy

this video is a good explainer https://www.youtube.com/watch?v=yGhfUcPjXuE

DeltaTime. This video is all about that mysterious variable that oh so many game developers seem to struggle with. How to use DeltaTime correclty? I got the answers and hope this video will help to deepen your understanding about how to make frame rate independent video games.

0:00 - Intro
0:34 - Creating The Illusion of Motion
1:11 - Simple Li...

▶ Play video
swift crag
#

It's true that FixedUpdate runs at a...fixed rate

#

but forgetting deltaTime in there also produces errors (by making everything 50 times faster than it's supposed to be, by defualt)

#
rb.velocity += Vector3.right;

This is extremely wrong in Update and also very wrong in FixedUpdate

#

In the former, the acceleration is framerate-dependent. In the latter, you're accelerating at 50 m/s^2

cosmic dagger
swift crag
#

(and if you change the physics timestep, then the behavior changes)

#

Similar note: Do not multiply mouse input by deltaTime

#

It's already an absolute amount of change

wispy coral
#

well now i know that delta time isnt the magic solution i once thought it was

cosmic dagger
wispy coral
#

and i now have another issue

#
{
    Vector2 movement0 = inputValue.Get<Vector2>();
    Vector3 movement = new Vector3(movement0.x, 0, movement0.y);
    rb.AddForce(movement * speed);
    Debug.Log(inputValue.Get<Vector2>());
}```
#

i tried making a simple movement script but when i press a key to move the value of the force of the rigid body does not change even when the input is 0

swift crag
#

OnMove is called when the input value changes

wispy coral
#

oh i didnt know that at all

swift crag
#

I presume you're using a PlayerInput component here?

wispy coral
#

yeah

swift crag
#

You can leave that in place, but I'd suggest using an InputActionReference for contiuous values. It makes things very simple

#
[SerializeField] private InputActionReference moveActionRef;
#

assign the appropriate action in the inspector

#

and now you can just

#

moveActionRef.action.ReadValue<Vector2>()

#

wherever you need the value

wispy coral
#

alright

#

so add those two things then?

swift crag
#

the first line is a field to add to your class

wispy coral
#

i see

wispy coral
#

im a little confused here

swift crag
#

No. As I said, OnMove is only called when the value changes.

wispy coral
#

oh yeah my bad

swift crag
#

Just read the value when you need it.

#

At this point it's identical to how you'd use the old Input Manager

#
Input.GetAxisRaw("Florp");
florpRef.action.ReadValue<float>();

same premise

wispy coral
#

alright ok, still a bit bamboozled but ill try that and see where it goes

swift crag
#

I mostly use InputActionReference in my game. I find it to be very convenient

#

Especially if I might need to configure which action is used

#

i can just throw whatever action I want in there

#

I directly reference the action that I care about; there are no magic strings

wispy coral
#

i think im starting to get it

#

moveActionRef.action.ReadValue<Vector2>() to get the input and just in the update function use it basically as the old input system

swift crag
#

Right.

wispy coral
#

nice

swift crag
#

I made a custom processor for sensitivity settings. I don't have to deal with sensitivity at all in my game code

#

the value that comes out of the action is the correct value, always

wispy coral
#

so thats what makes the new input system so customizable

#

i see

swift crag
#

I can also figure out exactly what controls are required to trigger an action, so I can display control hints

#

it's pretty handy

wispy coral
#

well ill have to get adapted to the new one but i think itll definitely be an upgrade

#

thanks btw

#

just tested the code and it worked flawlessly

#

thanks again

robust condor
#

I need an array or list in the inspector that can enforce prefabs of a particular interface, is it possible?

swift crag
#

You can't serialize interface types, unfortunately

robust condor
#

I have Odin, can it do it?

#

What if I use inheritence instead?

swift crag
#

I don't know about Odin

swift crag
robust condor
#

The prefab doesn't remember the references

#

When I drag it from hierarchy to project

cosmic dagger
robust condor
#

It's other prefabs

cosmic dagger
#

are they in the scene?

robust condor
#

Oh the little dot only looks in the scene, I thought it searched the entire project

cosmic dagger
#

prefabs can reference other prefabs, but only in the project folder . . .

wispy coral
#

can you get rid of the automatic comments that unity creates after making a new script?

west radish
#

There's a template in the unity program files directory

wispy coral
#

thanks

west radish
#

On my phone so I can't say where exactly

wispy coral
#

dont worry ill find it

west radish
#

But if you open it up in notepad, and make sure you have admin privileges on the notepad, you can change it to basically anything

#

It's quite useful

wispy coral
#

got it thanks

west radish
#

I wish Unity would make it more obvious that it's something you can actually do

wispy coral
#

same, i got tired of deleting the comments so i just stopped and my code looked like a mess

west radish
#

I feel like a lot of people never realise they can save themselves the time of deleting the prewritten text 😆

#

Same in Blender, you can change the startup project to no longer have that cube

wispy coral
swift crag
#

if i didn't have the cube, how would i delete something before i start working?

wispy coral
#

exactly

#

its the ritual of every new project

#

its like if unity didnt have the light, camera and the volume

west radish
#

One of the first things I ever did was banish the cube

#

What you should do is make a default donut in the startup project

wispy coral
#

thats better actually

#

and kinda funny too

west radish
#

Right??

wispy coral
#

yeahh, honestly the cube has become like a mascot

#

its synonymous with a new project so thats why i always like having it there, then of course delete it afterwards

#

i sometimes just do almost everything based off the cube

silk meteor
#

if i instantiate an object, do all the scripts within it execute the Start() method, or is that during the start of the game

wispy coral
#

if im not mistaken

timber tide
#

Start() runs before update

#

Awake() would happen on instantiation

silk meteor
#

I'm making a script for death and respawning, and on the Start method i have this code, so i was wondering if i instantiate the object as another object, would it rerun the script?

silk meteor
silk meteor
polar acorn
silk meteor
#

ah, thanks

#

so im having another issue i have this death method, alongside a coroutine, however the coroutine won't start because the player isn't active, is there a way around this?

    public void Die()
    {
        if (deathAnimation != null)
        {
            deathAnimation.Play();
        }

        gameObject.SetActive(false);

        IsAlive = false;

        if (shouldRespawn)
        {
            StartCoroutine(RespawnAfterDelay());
        }
    }

    private IEnumerator RespawnAfterDelay()
    {
        yield return new WaitForSecondsRealtime(deadTime);

        transform.position = respawnLocation;
        gameObject.SetActive(true);

        if (respawnAnimation != null)
        {
            respawnAnimation.Play();
        }

        IsAlive = true;
    }```
teal viper
silk meteor
#

how could i do it without a coroutine?

teal viper
#

Async await would work regardless of whether the object is active. Though, I wouldn't recommend it if you haven't dealt with async until now.

silk meteor
#

I have, just not in CS shrug

teal viper
#

Ideally, in this scenario you'd have some kind of manager (gamManager?) take care of this kind of logic.

silk meteor
#

hm, well ill do some research into async await and see what i get

teal viper
#

gameManager.EnqueueRessurect(this) or something. And the GameManager would start a coroutine on itself for example.

#

Or add the player to a queue with a timestamp. And check it in update.

#

There are many ways to implement it, but the key is that it would be managed outside the player.

#

At least the waiting is. After the waiting duration is done, the GameManager could call a Ressurect method on the correct player for it to handle the resurrection correctly.

silk meteor
#

okay i think i made it work with async await, but now im encountering some weird error, i didnt miss a semicolon anywhere, nor a brace

#

oh nvm

nova kite
#

it detects collision with the ground but not the obstacle

cosmic dagger
#

!code

eternal falconBOT
nova kite
#
using UnityEngine;
public class PlayerController : MonoBehaviour
{
    private Rigidbody playerRB;
    public float jumpForce = 10.0f;
    public float gravity = 1.0f;
    public bool isOnGround = true;
    public bool gameOver = false;

    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        playerRB = GetComponent<Rigidbody>();
        Physics.gravity *= gravity;
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space) && isOnGround)
        {
            playerRB.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
            isOnGround = false;
        }
    }
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.CompareTag("Ground"))
        {
            isOnGround = true;
        }
        else if (collision.gameObject.CompareTag("Obstacle"))
        {
            gameOver = true;
            Debug.Log("Game Over!");
            
        }
    }
}
cosmic dagger
cosmic dagger
nova kite
#

oh i just planned to delete that one lol

#

it is

#

the is trigger thingy is checked too

#

and it has the tag

cosmic dagger
#

it's a trigger but you're checking it in OnCollisionEnter . . .

nova kite
#

that's what the guy did in the Unity tutorial lol

cosmic dagger
#

are you sure? can you check again or post it?

nova kite
cosmic dagger
#

where does it tell you how to setup the obstacle?

nova kite
#

over many steps haha

cosmic dagger
#

that part is needed . . .

nova kite
#

ohh wait his "is trigger" is not checked

cosmic dagger
#

exactly . . .

#

i was waiting for that . . .

nova kite
#

wth now the fences are just flying off

#

XD

cosmic dagger
#

a trigger cannot be detected in a OnCollisionXXX method . . .

nova kite
#

how does the on collision detects stuff

#

with the box colission component?

#

like when two of those touch?

wispy coral
#

hey yall, im having problems with locking my cursor, it doesnt seem to work, should it be on the start method or the update method?

wispy coral
nova kite
wispy coral
#

wait no nvm

cosmic dagger
wispy coral
#

ill check my file since i have done that same lesson

nova kite
#

🙏🏻🙏🏻

nova kite
#

Like the components it has?

cosmic dagger
#

not sure; just like we did before, go back and read over the tutorial. you probably missed smth important . . .

nova kite
#

It all worked correctly until I tried detecting collision🥲

wispy coral
#

i have my own prototype here so maybe i can help

nova kite
#

The player colliding with the fence was not detected

#

Oh now it is!

#

But now the fences are flying off lol

#

Fix one bug get another damn that’s real😭

wispy coral
#

how is your rigidbody on your obstacle set up?

nova kite
#

at least it detected the colission now

nova kite
#

the components it has?

wispy coral
nova kite
wispy coral
#

i think i saw the issue

#

try scaling your box collider a bit down on the y axis

#

most likely that your fence is clipping into the ground while spawning

#

maybe thats causing the issue

nova kite
#

i tried with this but it still flies off🥲

wispy coral
#

huh thats strange

cosmic dagger
# nova kite what does set up refer to

in the tutorial, where does it setup (create and configure) the obstacle in the editor? go to that section and start from the beginning. make sure you check everything again . . .

nova kite
#

he starts by putting it in the scene and then makes it a prefab

#

it looks identical

cosmic dagger
#

keep going through the whole section and check with what you have . . .

wispy coral
#

hmm this is quite something

#

you could also try locking the position and rotation of the fence's rigidbody

nova kite
cosmic dagger
#

then continue and see if they change/fix anything . . .

nova kite
#

I’m going over the tutorial again

#

But his works fine

#

At the point where I am

wispy coral
#

its best if you retake it and check everything twice

nova kite
#

I’ll go over it🥲

#

its all the same;-;

#

i even enabled kinematic and it fixed it but now they are falling forward

#

and i constrainst all 6 boxes and they still fall forward

cosmic dagger
#

placing a constraint on the rotation axis that controls its forward and back movement should not allow it to tip over . . .

nova kite
#

Exactly, why does it not behave like that lol

#

It’s all checked

wispy coral
#

yeah it should not be able to do that if all the boxes are checked

nova kite
wispy coral
#

that is quite strange

nova kite
#

Is it related to modifying physics through a script

wispy coral
#

shouldn't be

#

but it is quite strange

#

maybe you could dm me the code from the scripts and compare i could it to mine to see if you have something going on

nova kite
#

It’s only 4 scripts so shouldn’t take too long!

#

I’ll do that😄

undone inlet
#

I am using Unity 2022, and I am trying to use the Init keyword, but I get the error:
"error CS0518: Predefined type 'System.Runtime.CompilerServices.IsExternalInit' is not defined or imported."

Here are the attempts I made to resolve this issue:

  1. I tried modifying the Api Compatibility Level in Player Settings. There are two options: .NET Standard 2.1 and .NET Framework, but neither resolved the issue.
  2. I tried upgrading to Unity 6000, but it seems the issue persists.
  3. I searched for this issue and found that the init keyword is only supported in .NET 5, but I am not sure how to interpret this information.
cosmic dagger
eternal falconBOT
undone inlet
queen adder
#

should i just make the flappy bird game from scrath?

undone inlet
#

And this seems to have the same error as well.
public record Test(int A);

cosmic dagger
queen adder
#

copy it from another vid

#

because idk any code

cosmic dagger
#

if you're learning it from a video, you are making it from scratch . . .

queen adder
#

ohhh

#

idk i just can't realy learn from videos

#

is more like just copying

undone inlet
#

Should I ask in a different channel?

cosmic dagger
#

record has limitations in Unity. init only setters are unsupported (as well as other functions) . . .

north kiln
undone inlet
north kiln
#
namespace System.Runtime.CompilerServices
{
    internal static class IsExternalInit { }
}
undone inlet
north kiln
#

Anywhere

undone inlet
#

ok thanks

undone inlet
nova kite
#

how do i research what i want to do

naive pawn
#

break it into simple parts

nova kite
#

im trying to just for example search how to move a character

#

and i find nothing on google that i was taught in the Unity courses

#

it's all so different

naive pawn
#

of course, there's a ton of different ways to make it

#

get more specific

rich adder
naive pawn
#

2d or 3d? what perspective? etc

nova kite
#
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    public float speed = 10.0f;
    private Rigidbody playerRB;


    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        playerRB = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
        float verticalInput = Input.GetAxis("Vertical");
        float horizontalInput = Input.GetAxis("Horizontal");

        playerRB.AddForce(Vector3.forward * speed * verticalInput);
        playerRB.AddForce(Vector3.right * speed * horizontalInput);
        
    }
}

i wrote this from memory and now im stuck because i forgot the rest

#

3d third prespective

#

so i tried searching but i find nothing that will help me complete the code

rich adder
#

so whats wrong with it ?

nova kite
#

it doesnt work, player doesnt move

rich adder
#

you should combine that into 1 call
should work fine, depends on your rigidbody settings too

naive pawn
#

well if you're just memorizing a specific tutorial then you'd need to refind that specific tutorial
don't do that
understand what each part does, then you can just make everything as you want it

nova kite
#

i understand that it takes the horizontal input from the setting and then detects it and converts it into force applied on the rigid body component that is attached to the object

#

but if i need to search for the syntax how do i do that

#

how do i search for a specific syntax

naive pawn
#

what specific syntax?

rich adder
#

look up what problem you want to solve
code is just the tool to achieve that

nova kite
#

.AddForce(what to put here) for example

naive pawn
#

that's not syntax, that's just what the method takes

nova kite
rich adder
rich adder
#

always consult the !docs

eternal falconBOT
nova kite
#

hold on ill try and see if i can make it jump just from doccumentation

rich adder
#

it explains almost everything

nova kite
#

because i have some problem with that too, i need to get used to that

#

i never find anything in doccumentation because i initially dont know what the function is called

rich adder
#

yeah there is a lot, normally you narrow down the methods in the API thru searching unity discussion/forum, google, stack overflow etc.

#

then use the docs to clarify how it works n all that

nova kite
#

if i want to find an answer in the add force doccumentation for why right now when i press right it goes left what should i look for

rich adder
#

thats something you need to start debugging as it might be unintended behavior

nova kite
#

i tried multiplying by -1 but it still does that

#

and that's all i got lol

rich adder
#

hmm I'm going to assume AddForce isn't local spaced

naive pawn
rich adder
#

so you're applying force to World Vector3.right which is always fixed

naive pawn
rich adder
#

doc always got the answers

nova kite
#

the ball is scaled 1 1 1 and positioned 0 0 0

#

and i set the scene to local

rich adder
#

you want your local right through transform.right or use InverseTransform

naive pawn
#

yeah transform.right should fix that, it converts local coords to world coords

nova kite
#

i multiply by that?

naive pawn
#

transform.forward too

naive pawn
rich adder
#

indeed, transform adapts to your local rotation

cosmic dagger
rich adder
nova kite
#

now when i press right it moves back and forth tf XD

rich adder
nova kite
#
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    public float speed = 10.0f;
    public float jump = 10.0f;
    private Rigidbody playerRB;


    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        playerRB = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
        float verticalInput = Input.GetAxis("Vertical");
        float horizontalInput = Input.GetAxis("Horizontal");

        playerRB.AddForce(transform.forward * speed * verticalInput);
        playerRB.AddForce(transform.right * speed * horizontalInput);
        
    }
}
naive pawn
#

could it perhaps be rolling and changing what direction "right" is

rich adder
#

also combine that into 1 AddForce call

naive pawn
#

if it shouldn't be rolling, make sure to constrain rotation on the rb

cosmic dagger
rich adder
#

also yeah that should be in FixedUpdate

nova kite
#

it was so much easier moving a character in the tutorials

#

is there a simpler way

#

i dont remember doing it like this

rich adder
#

which tutorial?

nova kite
#

the official unity one

#

any of them tbh

rich adder
#

which one

naive pawn
nova kite
#

it was just straight forward

rich adder
#

the unity intro ones use Translate

naive pawn
#

"simple" is kinda subjective

#

if you're thinking simple, maybe it was setting velocity?

rich adder
#

its not using physics and probably not rolling as was pointed out

cosmic dagger
rich adder
#

the ball is indeed rolling and changing local direction

nova kite
#

it didnt use velocity

nova kite
#

that makes sense

rich adder
#

must lock the rigidbody rotation

nova kite
#

he didnt say that in the lab video.. he said "you can just use primitive shapes and then change the model"

#

shouldve warned for unexpected behaviours haha

rich adder
#

send link of tutorial

nova kite
#

which one?

rich adder
#

it probably used translate

nova kite
#

yup

#

translate.transform

untold drift
#

ive been stuck on trying to get a basic rigidbody jump working on unity for days

rich adder
#

translate just teleports the dam thing

nova kite
#

lol

rich adder
#

it doesnt care about walls etc.

nova kite
#

so it's a bad movement system?

naive pawn
#

not necessarily

#

depends on what you're going for

nova kite
rich adder
#

depends, if you dont care about physics solid walls n stuff like that

naive pawn
#

translate doesnt' care about physics

#

rigidbodies handle physics

nova kite
#

ohh so there are movement systems that have built in physics??

#

damn

naive pawn
#

yeah, rigidbody

untold drift
rich adder
#

also Character Controller, its a quasi Physics object

naive pawn
#

gotta start with the details

nova kite
#

how do i make the ball not roll cuz if im gonna change the sprite later it shouldnt roll anyway

naive pawn
nova kite
#

the constraints?

#

ohh

rich adder
#

rotation ones

untold drift
naive pawn
#

define "wont work", and show what you're doing

rich adder
#

start with that, then show components setup

naive pawn
#

"doesn't work" doesn't give us any info to work with
is it not responding at all? is it giving an error message? is it responding, but not doing the thing you want it to?

nova kite
#
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    public float speed = 10.0f;
    public float jump = 10.0f;
    private Rigidbody playerRB;


    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        playerRB = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        float verticalInput = Input.GetAxis("Vertical");
        float horizontalInput = Input.GetAxis("Horizontal");

        playerRB.AddForce(transform.forward * speed * verticalInput);
        playerRB.AddForce(transform.right * speed * horizontalInput);
    }
}

this worked🥲

#

but this is exactly my problem i want to learn how to solve this on my own otherwise id need someone to spoon feed me on every little thing😫

rich adder
nova kite
#

how would i learn what you guys just taught me from documentation

nova kite
naive pawn
#

you would learn from the manual or learn pathways instead

nova kite
#

what is pathways

naive pawn
#

documentation is a reference to supplement primary learning materials

naive pawn
eternal falconBOT
#

:teacher: Unity Learn ↗

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

nova kite
#

oh but they didnt even use that there

naive pawn
#

depends on the pathway

nova kite
#

they used the transform thigny

untold drift
# naive pawn "doesn't work" doesn't give us any info to work with is it not responding at all...

Ok, so i asked chatgpt for help as i do use it for reference (im not a coder lol). I followed the instructions, included the needed code, the ground check in unity, and the rigidbody component in the inspector for the capsule. According to chatgpt this should give me everything i need to "jump" up and down with my capsule, but it simply does nothing when i input space. There's no error message, it's literally just no response. I'll pull up my code

rich adder
# nova kite i tried and it broke haha
void FixedUpdate(){
       float verticalInput = Input.GetAxis("Vertical");
       float horizontalInput = Input.GetAxis("Horizontal");
       Vector3 direction = transform.forward * verticalInput +
       transform.right *  horizontalInput;
       playerRB.AddForce(direction * speed);
}```
rich adder
#

tru

#

was being lazy lol

nova kite
#

what is var

#

oh

#

how did you know that this should be a Vector3

naive pawn
#
Vector3 direction = transform.forward * verticalInput + transform.right * horizontalInput;
direction.Normalize();
playerRB.AddForce(direction * speed);
naive pawn
untold drift
rich adder
naive pawn
#

Vector3 is just a list of 3 floats

#

those 3 floats could represent anything; here, they represent cartesian coordinates

#

var replaces the type in a local variable declaration, for when the type is obvious from the initialization, so you don't have to repeat yourself (whether you prefer it or not is subjective)

nova kite
#

ohh this:?
Declaration
public void AddForce(float x, float y, float z, ForceMode mode = ForceMode.Force);

#

the first one is a vector3

rich adder
#

thats a different signature

naive pawn
#

we're using the first signature here

rich adder
#

but yes you can also use each float here, not all of them have such varied signatures

#

cc.Move() for example has no such signature

nova kite
#

then what tells you on the documentation that it expects a vector3 haha

naive pawn
#

the first signature

#

the one that says Vector3 in the parameter list

rich adder
#

it says force
Force vector in world coordinates.

nova kite
#

Declaration
public void AddForce(Vector3 force, ForceMode mode = ForceMode.Force);

#

yes so like the first is vector3

rich adder
#

yes that would be that signature

nova kite
#

hell yeah

#

okay im starting to get it i think

rich adder
#

= in signature method means it has a default value, here is to Force

nova kite
#

and then if you didnt know what that is youd read about that?

#

forceMode for example i dont know what that is so how do i know what it expects

rich adder
#

they are underlined

naive pawn
#

the second parameter, ForceMode mode, specifies what kind of force to apply, basically what quantity/dimension/unit force is in
the = sets a default, to Force, basically in newtons (though not exactly newtons since unity doesn't use meters/kilograms)

nova kite
#

ohh! and it takes you to that function's page

rich adder
#

ForceMode is not a function

#

wow thats big

nova kite
#

hahah

#

what is that word

#

lol

naive pawn
#

either tiny or massive

rich adder
#

lol i shouldve made it wide af

nova kite
#

XDD

naive pawn
nova kite
#

enumeration

rich adder
naive pawn
#

"enumeration" is like a list of options

rich adder
#

thats basically a standard C# type

nova kite
#

oh enums!

rich adder
#

yes

nova kite
#

nvm i never saw the full word lmao

naive pawn
#

see the "enumerate" -> "numerate" -> "make into numbers"

#

more accurately it's just kinda listing them

rich adder
#

just fancy word for numbers with labels

nova kite
#

wait on the ForceMode page there is a huge block of code, how do you research that code to see what it expects

#

you just read all of it??

naive pawn
#

wdym "research that code"

rich adder
naive pawn
#

it has comments explaining what each part does

nova kite
naive pawn
#

read the description

#

not the example code

wispy coral
#

how do i stop from sticking to walls if im in the air?

naive pawn
#

reduce friction perhaps

nova kite
#

ouu so the enum stores the 4 modes

wispy coral
#

make a material with 0 friction?

naive pawn
#

yeah

#

though if you do want it to have friction in some cases, you'd probably have to do more work

wispy coral
#

and what can i do if i need to stand on that thing ?

rich adder
naive pawn
nova kite
rich adder
#

Ohhh forcemode

nova kite
#

oh 5 and start

naive pawn
rich adder
# nova kite oh 5 and start

yea that enum just has "human readable labels" the computer just sees a number
you can also assign different values but thats topic for another time lol

wispy coral
#

would it be affected?

naive pawn
#

friction wouldn't affect moving, since you aren't literally pushing off of the ground in the game (for most implementations)

nova kite
#

wait so how do i know what it expects like for the force mode

wispy coral
#

got it

nova kite
#

i read the description

rich adder
#

the method just cares about the type in the signature

#

the value is up to you

naive pawn
nova kite
#

and how do i know if it's a float or an int

nova kite
#

like obviously its a float but im asking like in general

naive pawn
rich adder
nova kite
wispy coral
nova kite
#

double

rich adder
nova kite
#

oh lol

naive pawn
rich adder
#

you said "float vs int"
like obviously its a float
so i asked "what is the float"

naive pawn
#

however, vector3 holds floats inside

rich adder
#

click Vector3

#

on addforce

naive pawn
nova kite
#

im so confused hahahah

rich adder
#

float double decimal, we are not the same

nova kite
#

XD

nova kite
naive pawn
#

it's a bit technical, yeah we can get to that later

#

it's along those lines, but a bit more nuanced

rich adder
#

mainly precision thing too

#

decimal being the most precise

#

but heavier

naive pawn
#

do you know how int and float differ semantically?

nova kite
#

on the Rigidbody.AddForce page it says that it needs a vector3 then a ForceMode

#

i got that much

#

but then in the example code it doesnt even include the public void AddForce()

naive pawn
#

or more precisely, how integral types differ from floating-point types

rich adder
#

m_Rigidbody.AddForce(transform.up * m_Thrust);

naive pawn
#

public void AddForce(...) is the creation of the method

#

the example shows how to use the method

rich adder
#

its like the declaring of the method

nova kite
#

so i need to create the method too or does it come with the include unity

rich adder
#

how is this method structured

naive pawn
#

if it had that creation, that'd be the source code of the method, not an example usage

naive pawn
nova kite
#

using not include sorry

#

hahah

rich adder
nova kite
#

i meant like do i need to put that line in th ecode

naive pawn
#

no, unity does

nova kite
#

i see so that's just showing me what it expects

rich adder
#

you just need to "call" the method, you dont declare it

nova kite
#

like what values i need to transfer to that method

rich adder
#

the method is already setup for you. You just "feed it" values

nova kite
#

playerRB.AddForce(transform.right * speed * horizontalInput); how come it's different here then

#

there is no comma

#

so where is the ForceMode

rich adder
#

because its using default forcemode

naive pawn
#

it's defaulted

rich adder
#

i told you what = meant in signature

nova kite
#

yes but i dont have it

rich adder
#

its giving a default value so you can omit it

nova kite
#

so how does it know

naive pawn
#

unity has it

rich adder
#

it has been given it when it was declared

naive pawn
#

you don't have to

nova kite
#

its like another constructor

#

for if i feed it just the vector3?

rich adder
#

its not a constructor

#

its a different signature method

naive pawn
rich adder
#

its still using ForceMode, but the default one

nova kite
#

hmm i see

#

so if i wanted the impulsive one for example i would have to specify

rich adder
#

when you declare a method you can have it default values in params so you dont ever have to pass a value

nova kite
#

ohh

#

so basically in the example code they show me the items i need to make it work

#

i need a rigidbody reference

#

and to connect it to the component of the game object that this script is attached to

rich adder
#

yeah you need a specific rigidbody to access/call the method on

nova kite
#

and then i can do stuff with it

naive pawn
#

you can think of defaults as hidden overloads

void Method(int a, int b = 0) { /* stuff */ }
// is like
void Method(int a) { Method(a, 0); }
void Method(int a, int b) { /* stuff */ }
nova kite
#

yes thats exactly what i had in mind haha

#

like different options depending on what the user passes

#

so by writing ForceMode mode i crete an object or however that's called and then i assign it a certain mode's value

#

and that gets passed to the rigidbody class who has a reference to that ForceMode enum and then it applies the propoer physics

rich adder
nova kite
#

i meant like the "mode" that coems after ForceMode

#

AddForce(float x, float y, float z, ForceMode mode = ForceMode.Force);

#

that's like an object of that enum

rich adder
#

thats how enums work, you preceede it with the enum type

public enum Colors{
       Red, Blue
}
private Color col;
void Foo(){
       col = Colors.Red;
}```
nova kite
#

like that stores what mode i want to use

#

i see okay this all makes much more sense now

#

thank you guys!!

#
Vector3 direction = transform.forward * speed * verticalInput + transform.right * speed * horizontalInput;
playerRB.AddForce(direction);

and for this how does it work even tho you add these two up? wont the numbers just get messed up

nova kite
#

i like when i think of something and it's actually the answer that's when it clicks lol

compact stag
#

hey guys! i dont really know why my character hasnt been being triggered, but i got a player

using UnityEngine;
using System.Collections;

public class Collision : MonoBehaviour

{
    private void onTriggerEnter(Collider other) {
    if (gameObject.tag == "Player") {
        print("Entered hitbox");
        }
    }
}

and a monster, i added this code to the monster's empty gameobject trigger and gave it a box collider, i checked the isTrigger checkbox and made a tag for the player called Player however this still doesnt work, can anyone tell me why?

rich adder
nova kite
#

but how does it not add the resulted numbers of them

nova kite
#

or that wouldnt matter cuz it would be like going sideways?

wispy coral
#

it checks the tag of the other thing, that being the player and does the action

rich adder
nova kite
#

can you even add these hahah

rich adder
#

yes

nova kite
#

then i would assume so yes

compact stag
#

should i add anything into the player?

wispy coral
nova kite
#

i would assume it adds the x y and z seperately

rich adder
#

look carefully

compact stag
#

wait, am i not catching something super obvious?

rich adder
rich adder
#

C# is case sensitive

compact stag
#

OH

#

THE

#

fuuuuuuck

#

the On

nova kite
#

hahaha

#

GameObject

compact stag
#

fuck im sorry guys LMFAO, i have been looking at this for like the past HOUR

rich adder
nova kite
#

wdym no;-;

#

see another example

#

in the documentation it says GameObject

north kiln
nova kite
#
using UnityEngine;

public class Example : MonoBehaviour
{
    private float speed = 2f;

    //Moves this GameObject 2 units a second in the forward direction
    void Update()
    {
        transform.Translate(Vector3.forward * Time.deltaTime * speed);
    }

    //Upon collision with another GameObject, this GameObject will reverse direction
    private void OnTriggerEnter(Collider other)
    {
        speed = speed * -1;
    }
}
rich adder
north kiln
#

Because it warns you if you get the tag wrong and it also doesn't allocate an extra string

nova kite
#

i see so it would move these two simultaneously if two buttons are pressed that's clever

compact stag
north kiln
#

Yes

nova kite
north kiln
#

They make sense in different contexts

nova kite
#

yea but if you didnt have context and relied on the documentation?

#

because that's what im trying to learn haha

#

how to rely on documentation

north kiln
#

The documentation is using things in different contexts, I don't see where a capitalises GameObject is even referenced in what you quoted outside of a comment

rich adder
#

click it, GameObject it explains everything

north kiln
#

where?

#

It doesn't use GameObject or gameObject in this code

nova kite
#

ohh!!

#

GameObject is the class

rich adder
#

its telling its being applied to that Gameobject this script is on

nova kite
#

and that's to get components of game objects

rich adder
#

GameObjects are just containers of Components

nova kite
rich adder
#

when you put a script on a gameobject its a component
Unity is traditionally component based

nova kite
#

of how to use the ontriggerenter

compact stag
#

also, just a final question, i used Destroy(other.GameObject) so the code looks like this

{
    private void OnTriggerEnter(Collider other) {
    if (other.CompareTag("Player")) {
            Destroy(other.gameObject);
        }
    }
}

but i get this error SPAMMED in my console, am I deleting only the camera?

nova kite
#

thats when you use capital G

north kiln
nova kite
#

ohhh

#

so how do you know how to write the code that would be on a trigger detector object

rich adder
nova kite
#

if that example doesnt have it

rich adder
#

GameObject.component doesnt exist
click GameObject, you will see all the properties and methods listed

north kiln
teal viper
north kiln
compact stag
rich adder
wispy coral
#

how can i reset a rigidbody's rotation?

#

in code

rich adder
#

put Quaternion.identity

wispy coral
rich adder
#

or whatever you want to reset to

nova kite
#

is there a tutorial that explains how to understand documentation lol

rich adder
teal viper
rich adder
#

Having traditional C# basics will help you better read the Docs / APIs

wispy coral
compact stag
#

so, question, should i use GetComponent to get a variable in another code? i was thinking of making a isAlive boolean variable

#

or is there a better way?

nova kite
rich adder
#

no garbage collector like c#

teal viper
nova kite
#

i hate pointers lol

rich adder
#

c# ur not typically dealing with pointers directly

nova kite
#

luckily

rich adder
#

if you know c++ , c# will be easier lol

nova kite
#

i know some we are studying it in college

teal viper
#

Though, I feel like there's not much knowledge you'd be able to transfer from C++, seeing how you "hate pointers"😅

rich adder
#

less to deal with, I mean header files? ughhh

nova kite
#

i fucking hate header files

rich adder
#

maintaining 2 files is annoying

nova kite
#

that is the sole reason why i didnt choose unReal

#

lmao

nova kite
nova kite
rancid badger
rich adder
nova kite
#

unity is much easier for sure

#

it all makes sense

static cedar
#

Now you only have to maintain one file.

teal viper
nova kite
#

i have 3 more semesters of C++

#

;-;

rancid badger
#

hey quick question, anyone ever experienced button taps "randomly" not detected on android build? where should i look to find the reason?

cosmic dagger
#

facts. if you hate like pointers, basically, you don't like C++ . . .

rich adder
nova kite
#

i like how the input and output work lol

static cedar
static cedar
#

Just gave us projects and went go work on it urself.

nova kite
#

we are forced to take assembly too😭

rich adder
#

i just use C/C++ for embedded and connecting to unity via interop sometimes

static cedar
rancid badger
wispy coral
#

is there a way to unfreeze a single rigidbody constraint on command?

rich adder
rich adder
#

just unfreeze and assign the specifc one you want

wispy coral
#

alright thanks

cosmic dagger
cosmic dagger
wispy coral
#

i just unfroze all and froze the ones i didnt need

static cedar
rancid badger
wispy coral
static cedar
#

Wanna combine all individual flag?
001 | 010 | 100 = 111

#

Something like that.

wispy coral
#

thats convenient actually

nova kite
#
void Update()
{
    if (Input.GetKeyDown(KeyCode.Space))
    {
        playerRB.AddForce(Vector3.up * jump);
    }
}

why does it not jump😫

rich adder
cosmic dagger
rich adder
#

^ use Impulse for one frame bursts