#💻┃code-beginner

1 messages · Page 57 of 1

buoyant knot
#

does this make sense, prototype?

#

so transform.up gives up. (-y,x) gives that vector rotated by 90 degrees

#

(-x, -y) gives it backwards, and (y,-x) gives it rotated by 270 degrees

final kestrel
#
 private void OnCollisionEnter(Collision collision)
 {
     if(collision.gameObject.tag == "Obstacle")
     {
         Destroy(rb);
         Vector3 jumpPosition = new Vector3(transform.localPosition.x + 8f, transform.localPosition.y - 12, transform.localPosition.z);      
         transform.DOLocalJump(jumpPosition, 13, 1, .8f).SetEase(Ease.InSine);
         transform.DORotate(new Vector3(0f, 0f, -90f), 1f, RotateMode.LocalAxisAdd);
     }
 }

Rotate works just fine. But I cannot seem to get the jumping correct. It somehow uses the world transform.

#

It should jump towards its right but instead it jumps backwards and through the platform.

heady nimbus
# buoyant knot does this make sense, prototype?

I appreciate all of this. I do not fully understand, but you've given me some pieces to work with and I'll see what I can do from there. I'm utter garbage at math so that rotation matrix stuff is way over my head, but I think I can figure something out with what you've given

buoyant knot
#

you should learn

heady nimbus
#

Yup, probably.

buoyant knot
#

2 things you should really learn well if you do this sort of physics: 1) law of sines/cosines, 2) basic vector math (like dot products and angles)

#

rotation matrices are extremely simple. you know how to multiply matrices, right?

heady nimbus
#

I remember vaguely that it was something they tried to teach me in school several decades ago, but not how to actually do it anymore. Lmao

buoyant knot
#

learn again. matrix multiplication is not complicated

#

this is a 2D rotation matrix. You can calculate the value of each of the 4 cells by plugging in the angle you want to rotate by

#

when you have that answer, you multiply it by the vector, and that outputs a vector that has been rotated by the angle you plugged in

heady nimbus
#

I appreciate the effort, but this isn't going to click for me right now. I was just doing some unity stuff on my lunch break today, and I've got to get back to real work at this point

buoyant knot
#

for theta = 90 degrees, sin theta = 1, cos theta = 0. So the whole matrix is just
[0 -1, 1 0]

heady nimbus
#

I don't want you to waste too much time or effort putting all this out right now if I don't have time to consume it, but thank you regardless

dapper lava
#

when i have 2D character andi use transform position to move him should i use rigidbody and box colision to not allow him to move throught walls

#

or is there better option because when i do it the character i lagging in wall

merry spade
#

when you randomly generate obstacles for an endless runner, do you just take random X and Z Values and place it down or what is the strategy with this kind of generation?

woven crater
#

hi, im a beginner, and been worrying about trying to find the best way to do thing. does it matter?

#

like just trying to make a character move i think there are some like very hidden medthod that i should learn instead of just translate the spite 1 pixel every frame

dapper lava
merry spade
#

yeah im doing that but i feel dumb generating hundreds of random numbers

dapper lava
#

what

merry spade
#

ok hundreds is too much but 4 or 5 every spawn wave

merry spade
#

its getting pretty long because the reference of these objects need to get saved to destroy them if theyre out of reach

merry spade
heady nimbus
#

You shouldn't need a reference to the objects you want to destroy, let the object clean itself up when it's out of range

dapper lava
#

do you reference spawned object and destroy them from somewhere else when they leave screen?

merry spade
#

how can i do this?

dapper lava
heady nimbus
#

I was playing around with an "Idle slayer" clone not too long ago, off screen I had a trigger zone that if/when objects reached this zone, they would destroy themselves

merry spade
merry spade
dapper lava
#

and the script deleting the obstacles is in the obstacle

merry spade
#

no i have a generation object that deals with everything

heady nimbus
#

Yea, if that's how you have your world set up.

merry spade
#

when i generate trees and stones how do i know if in the spot i want to generate the tree in is no stone

heady nimbus
#

Clean up zone is just off camera, a set distance

dawn sparrow
#

Is it fine to ask hlsl questions in here?

dapper lava
#

i think so

dapper lava
dawn sparrow
#

Gotcha, thanks

#

So.. i'm confused

SV_ in front of a semantic indicates System Value, which is basically what the system will use to draw the final image,

SV_POSITION grabs the vertex position from the mesh, but why does color get routed with the semantic "COLOR" instead of "SV_COLOR" ??

buoyant knot
#

is there a way to make it so every time a builtin component of type X is added to the scene, i call a certain method?

solid verge
#

How can i find multiple scripts with findgameobjectswithtag

solemn fractal
#

Hey guys, in my mini game, I need enemies to be spawning all the time non stop. I am using this method and so far working good. cs InvokeRepeating("SpawnEnemy", _spawnAfterXSeconds, _spawnEveryXSeconds); But I need to have more control over it as I need that some enemies spawn only at first 2m and after that other type of enemies will spawn, and even tho in the min 5 i want again the same mobs from the begining to start spawning too, and so on. So i need to have control always when they are going to spawn. and when I determine they will spawn they need to keep spawning until I say stop, they dont just spawn 1 time. Coroutines might not work as they spawn just 1 time right? any tips on that?

rich adder
# buoyant knot is there a way to make it so every time a builtin component of type X is added t...
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
public class EScript 
{
    static EScript()
    {
        CleanupSub(); 
        ObjectFactory.componentWasAdded += ComponentWasAdded;
        EditorApplication.quitting += OnEditorQuiting;
    }
    private static void ComponentWasAdded(Component component)
    {
        Debug.Log($"{component.name} added {component}");

        if(component is TestScript)
        {
            Debug.Log($"My Component {component} is what I wanted");
        }
    }
    private static void CleanupSub()
    {
        ObjectFactory.componentWasAdded -= ComponentWasAdded;// cleanup
        EditorApplication.quitting -= OnEditorQuiting;// cleanup
    }
    private static void OnEditorQuiting()
    {
        CleanupSub();
    }
}
brittle isle
#

My ground detection detects walls

rich adder
#

var myObjects = GameObject.FindGameObjectsWithTag(c_myTag);

glossy eagle
#

Hi. Does anyone know the reason why in the editor the game works okay but in the build I get a bunch of errors please?

solid verge
#

falling = GameObject.FindGameObjectsWithTag("FallingThing");

solid verge
dapper lava
#

what will happen if i use normalized twice
new Vector2(1f, 1f).normalized.normalized
will the 0.71 chaange to something like 0.6 to normalize

solid verge
#

what is an array

#

i did assing it

rich adder
solid verge
#

FallingThingScript falling; like this

rich adder
#

thats not an array

rich adder
rich adder
nimble inlet
#

I'm trying to drag and drop a Text GameObject in UI canvas onto DialogueManager at the top of my hierarchy as a variable. And for some reason, it doesn't allow it. There's probably a really simple reason why but.. xd

rich adder
solid verge
#

string myTag = ("FallingThing"); still declares it as invalid

summer stump
glossy eagle
# rich adder depends what the errors are? how can we help with no context

sorry. For example, in the editor I don't get any errors, but in the build I get a bunch of errors saying that an element from a dictionary doesn't exist. I am trying to change some stuff in the scripts because I'm afraid it could be just that in the editor one thing is being called before the other (and so it works fine), but in the build the order is different idk why

rich adder
#

() is not valid string sytntax

nimble inlet
#

hmm. okay. I think it's probably type mismatch then. how would I problemshoot it... I have it declared as follows: "public Text dialogueText;" and that doesn't really leave much to confusion.. and the object is simply created from Create->ui->text.

rich adder
solid verge
rich adder
#

or just Text

nimble inlet
#

let me see

rich adder
nimble inlet
#

ahh, it's textmeshpro by automation. that's different to text, then?

summer stump
rich adder
#

you would need TMP_Text
but also import the namespace its in

solid verge
#

where i put these
public float Health = 100f; public GameObject Player; FallingThingScript falling; public float DamageFromFalling = 25f;

glossy eagle
nimble inlet
#

okayyy! nice nice! ty ty

rich adder
solid verge
polar acorn
glossy eagle
solid verge
#

Assets\Scripts\HealthScript.cs(18,19): error CS0029: Cannot implicitly convert type 'UnityEngine.GameObject[]' to 'FallingThingScript'

rich adder
solid verge
#

yes

glossy eagle
#

okay thank you so much

rich adder
solid verge
#

it's not a gameobject neither an array

rich adder
#

right thats what the error is telling you

solid verge
#

but i do not know the syntax to when reffering to a script

polar acorn
#

You have a list of objects. You need to get components from them

rich adder
nimble inlet
#

ngh. I changed it to textmeshpro+ importing tmpro... but it remains destitute in not allowing the drag and drop :C

rich adder
#

can you show ur exact code

summer stump
# solid verge still error

What I wrote would certainly not give an error. So it's either something else or you changed it. You gotta show code for use to help more

Edit: dang lag. Ok, they are handling it with you! Looks good.

grim stream
#

does GetComponentsInChildren<RigidBody2D>() give me an array for rhe rigidbody component of all the GameObjects Children or just one of the children?

grim stream
#

Including Parent??

rich adder
#

yes if parent has Rigidbody2D it will add it

slender nymph
grim stream
#

okay. Thanks!

rich adder
#

wish there was an overload for skipping parent but hey can't have everything

solid verge
#

wait

#

am i allowed to make it that big

rich adder
nimble inlet
rich adder
#

iirc TextMeshPro is not the GUI version

#

i said earlier TMP_Text 😛

nimble inlet
#

nooo

rich adder
#

thats the baseclass that covers all possibilities

solid verge
#

like that?

rich adder
#

yup

grim stream
#

Tip: you can do full code blocks with 3 ` symbols so for example:
```cs
(code)
```

rich adder
#

sholdn't for an entire long class tho

solid verge
#

i've done messed up

#

this is so much pressure

rich adder
solid verge
#

i did but i did not understand

rich adder
solid verge
#

i guess everything

rich adder
solid verge
#

what doe the [] do

solid verge
#

array?

rich adder
#

yup

solid verge
#

but how could it.

grim stream
rich adder
#

because thats what the syntax is

#

its very common usually

solid verge
#

and array is a string?

#

wait

#

no

rich adder
#

no..

grim stream
#

nope

rich adder
#

array is a type

grim stream
#

an array is a list

solid verge
#

oh

solid verge
#

can array contain just one thing?

rich adder
#

or none

#

its a list of stuff

grim stream
rich adder
#

sent that already

grim stream
#

Microsoft is more correct. But w3Schools is easier to understand 🙂

rich adder
#

they're both correct, microsoft one just has more examples (more array types)

solid verge
#

man i'll just try and solve this tommorow

rich adder
#

but yes its easier to understand

grim stream
solid verge
#

cause i am way to dumb for this stuff

#

but i will figure it out

#

i will try to*

rich adder
solid verge
#

it was all just an attempt to make a health thing

#

but ok

rich adder
#

exactly..

solid verge
#

i will come back here

rich adder
#

you're trying to do a health thing without knowing the basic c# you're gonna have a harder time

solid verge
#

i mean't that it started by just a simple thing

rich adder
#

knowing the basic syntax/types is invaluable to doing anything

solid verge
#

and another function that if health is less or equal to zero it is done for

#

with a loop that minuses the health until the health float is less or equal to zero

#

wait reverse the words cause my internet sent the second one first than the first one

rich adder
#

is it just me or discord is taking a big 💩

solid verge
#

ye

#

nothing is loading

#

xd

fast knot
#

Is IEnumerator with yield return new WaitForSeconds(3); a good solution for time based powerups or is there something better?

grim stream
#

is there a function that is called right before switching scene or before the Gameobject is destroyed?

dapper lava
#

what type is Time.deltatime

grim stream
#

Float

eager elm
fast knot
eager elm
summer stump
#

@solid verge One big issue I see is here
FallingThing = FallingThing.GetComponent<FallingThingScript>();

You apparantly have a FallingThing Gameobject reference, and you want to use that to get a reference to the FallingThingScript.

You could just change that variable to FallingThingScript and drag the object into there, then delete the line I copied above

fast knot
summer stump
rich adder
#

ah yeah discord just died there for a bit lol

solemn fractal
#

Is there a way to have control over spawning with coroutine or InvokeRepeating. Like i say start spawning now until i say keep spawning and stop when i want and come back spawning again.. ? Or should i use a mix or other ways?

rich adder
#

you need a while loop inside coroutine for Repeating behavior

solemn fractal
#

hmm ok

#

like that? cs myCoroutine = StartCoroutine(MyCoroutineMethod());

#

and stop like that cs StopCoroutine(myCoroutine); ??

rich adder
#

yup

solemn fractal
#

and inside i would use a while ?

#

hmm ok thank you

rich adder
#

eg

while(true){
//Spawn
yield return new WaitForSeconds(seconds);
}```
solemn fractal
#

Got it, thank you

true pasture
#

having a dumbo moment. what is the proper way to see if a button is being held in new input system. Cant find it online somehow. is it context.started?

solemn fractal
#

Also another question, is there a feature in unity to put a watch in the screen couting down the time? like 15minutes counting down to zero? Or it need to be done 100% hardcoded?

eternal needle
#

You can stop a coroutine yes. you can just have some bool keep track if you should be spawning at this moment and change the bool based on your logic. Then you can do your work in update instead of starting and stopping coroutines if you wanted

fast knot
true pasture
#

like theres this but I don't understand how those are related to hold inputs.

fast knot
nimble inlet
#

okay, this works again. xd so I was trying to search data on that tmp_text workings, but all indicators tell me to use something else, like something specific to canvasUI texts. But then referring to those I get a type mismatch. I also tried the TMP somewhere, but it didn't work.

#

(alhtough I maybe did it poorly. google nor gpt was helpful finding that. the unity forums are down/infinitely refresh too)

strange shale
#

so... trying to make a simple double jump... (I was using add force, but I guess I need to do something else first...)

I'm trying to make the midair jump ignore the character's current Y velocity and always make the midair jump uses the same up speed

short hazel
slender nymph
strange shale
#

do I just type reset Y and done?

short hazel
rich adder
#

can you show which component you're trying to drag in the field ? and the screenshot for entire object inspector @nimble inlet

short hazel
#

So if your hold is about "tell me when I start pressing down, and stop pressing down", then you want the started and canceled events

true pasture
nimble inlet
rich adder
nimble inlet
#

what the f- is an object inspector. that's an object. it's the inspector. XD

rich adder
#

you not know what inspector is in unity I suggest you start from the basics 😛

true pasture
#

the inspector window. thats the hierarchy that you posted

nimble inlet
#

there's also inspefctor window. multi image.

nimble inlet
#

hu?

polar acorn
#

Show the object's inspector

#

Not the hierarchy window

rich adder
#

idk discord is lagging i only see 1 image

nimble inlet
#

it sure is

#

there's 3

true pasture
#

you have to click on the image and press over,

#

they did post the inspector

grim stream
#

is there an attribute to hide a public field in the editor/inspector?

slender nymph
#

HideInInspector
it will still be serialized though

rich adder
#

Oh..there's no thumbnails but you can click through it

wintry quarry
#

But - probably best not to use a public field in the first place if that's what you want

polar acorn
slender nymph
rich adder
nimble inlet
#

let's see..

rich adder
#

yeah discord is dying rn

nimble inlet
grim stream
#

Its just for aestetic purposes. Variables that should not be set by human but still need to be accesed by other classes

polar acorn
rich adder
nimble inlet
#

okay how is that possible. :C it's literally defined as "TextMeshProUGUI" atm...

rich adder
#

did you save

grim stream
nimble inlet
#

100%

rich adder
polar acorn
rich adder
#

TMP_Text is better imo cause its shorter to type

#

and covers more components

nimble inlet
#

there's some new ones...

polar acorn
nimble inlet
#

the compile errors make no sense. But these weren't here before I think, when things still didn't work.

#

I think it's saying I have a duplicate script of the same name...

polar acorn
nimble inlet
#

yep. I don't know when that got created. xd I deleted one and there's tons of errors now from that. good stuff :C

true pasture
strange shale
#

alright... got it

true pasture
short hazel
#

The Hold processor converts the button into a "raise no performed event until the button has been held down for X seconds"

true pasture
#

so why would I need to add cancelled

short hazel
#

To know when to stop adding force

scarlet skiff
#

can u make a parent inside a parent?

true pasture
#

but how does that work with the if statement?

nimble inlet
#

okay. there's only one error left and that's the type or namespace "image" is not found. code being " public Image textboxImage; in the previously sent code.

nimble inlet
#

Image

scarlet skiff
true pasture
#

if context.started (addforce)

#

then what triggers the context.cancel (is it just if context.cancelled) empty block

polar acorn
nimble inlet
#

no. added it. good thinking.

polar acorn
nimble inlet
#

wow unity is so friendly. xd new errors only hiding behind old errors.

short hazel
# true pasture but how does that work with the if statement?

It doesn't. Here it'll only add force once, when you start pressing the button. Take what's in the if statement out and store it for later. Set a bool to true in that if statement. Add another if statement for canceled in which you set the bool to false.
Then paste your code in FixedUpdate, and only apply force if the bool is true

nimble inlet
#

I have managed to remove all the errors in compiler+vscode... I cannot still drag and drop the object onto that script.

short hazel
rich adder
polar acorn
short hazel
#

Ensure that it's the case

polar acorn
#

How about send a screenshot of your full unity window with:

  1. This object visible
  2. The console tab open and visible
nimble inlet
polar acorn
nimble inlet
#

behold my beautiful game

short hazel
#

Warnings!

#

Read them

nimble inlet
#

they don't matter no?

short hazel
#

The one in the Inspector does

polar acorn
#

This is an empty script

rich adder
#

🫠

nimble inlet
#

oh snap, it got removed when I removed the duplicat.e

short hazel
true pasture
#

yeah

nimble inlet
#

it WORKS!!

#

thank yuuu!

solemn fractal
#

hey guys doing some coroutine tests, but it seems I cant do like that. any ideas?

rich adder
#

||switch IEnumerator to Coroutine|| 🥣

solemn fractal
solemn fractal
#

but on stopcoroutine still got the error

polar acorn
# solemn fractal

The first error says you cannot assign a Coroutine to a variable of type IEnumerator.
The second says you can't call StopCoroutine on an IEnumerator.

rich adder
#

StopCorotuine(coroutineVar)

solemn fractal
#

omg

#

yes

#

i am so dumb.. 21h haha thank you !!

#

worked

rich adder
#

the errors tell you exactly whats wrong usually xD

solemn fractal
#

I did a reserach and said I had to use private Ienumerator myCoroutine;

solemn fractal
rich adder
rich adder
#

StopCoroutine has 3 types as params btw

#

Coroutine is the return here

#

for stop you can pass IEnum but you already stored as Coroutine

solemn fractal
#

oh wow

#

interesting..

#

For now I will stick to the simple method as I am starting, but already took not of those to check it out later. thank you a lot

#

Another question, to create a count down timer like 15m showing on the screen 15:00 until it gets 00:00. need to be hardcoded or there is a feature on unity for that?

rich adder
solemn fractal
#

ok thank you

rich adder
#

update the UI text

solemn fractal
#

with time.time or something like that?

scarlet skiff
#

ok hear me out
i have 2 scripts

A: For the boulder, which tells it how it can move n whatnot, boulder is now a prefab as well
B: boulder spawner, if u press space it will run a method in script B that spawns a boulder

however i am having a bit of trouble with this, im not quit sure how to build the spawner method

Currently, i just have

rich adder
#

what you can do is put it in the same while loop if you want if its related to that previous coroutine

slender nymph
solemn fractal
#

hmm ok, will check it out doing a research on it. thank you

slender nymph
scarlet skiff
#

used to working with monogame

fierce shuttle
# solemn fractal with time.time or something like that?

For a timer, I often use a variable of seconds representing the total time I want (for example 60 * 5 would give 300 seconds), then you can tick those seconds down with navarone's suggestions, and display those seconds as detailed as youd like to some text object (days, hours, minutes, seconds, milliseconds, etc) - though for this approach, you may need to do some math on the seconds and possibly ToString formatting, as the math will result in decimals more often than not

scarlet skiff
#

same name..

polar acorn
summer stump
# scarlet skiff

It takes a variable, not the string name of a prefab
You have no variable named Catapult_boulder

gray crest
#

Im using object pooling of two different objects, when the game starts the its objects pools 8 of the first object and when i press a button it then switches to objects pooling the second item, but the transition of making the 2nd active and 1st inactive causes lag spikes on android. There are some scripts on the objects but when i check the profiler there is no certain script thats causing the lag drop, what can i do here?

buoyant knot
#

i think you need to check profiler to see what the program IS doing during the lag spike

#

if the cost is being distributed very evenly, check for things that shoukd only be called once to see if they are called multiple times

eternal needle
gray crest
eternal needle
gray crest
eternal needle
#

This sounds more like additive scene loading, but with prefabs

gray crest
#

hold on discord limit

eternal needle
#

!code

eternal falconBOT
scarlet skiff
gray crest
summer stump
gray crest
eternal needle
scarlet skiff
summer stump
gray crest
# eternal needle honestly i got no idea what part im supposed to be looking at, but u can profile...

yeah i get it but this is the object pool

    private void Awake()
{
        coinSpawner = FindObjectOfType<CoinSpawner>();
        objectPool = new List<GameObject>();

        // Fill the object pool with all objects from the prefabs list
        foreach (var prefab in prefabs)
        {
            for (int i = 0; i < maxObjects; i++)
            {
                obj = Instantiate(prefab, new Vector3(currentX, 57.41f, 25.19f), Quaternion.Euler(0f, 180f, 0f));
                objectPool.Add(obj);
                obj.SetActive(true);

                // Activate only the object at index 0
                if (prefab == prefabs[0])
                {
                    activeObject = obj;
                    currentX += spawnOffset;
                    obj.SetActive(true);
                }
            }
        }

        // Find all SpawnerScript instances and add them to the list
        SpawnerScript[] foundSpawners = FindObjectsOfType<SpawnerScript>();
        spawners.AddRange(foundSpawners);
}
eternal needle
#

this still looks more like additive scene loading but using prefabs, instead of an actual object pool.
Also for some reason you've now changed it to set every object to true on awake, while in the hastebin it was obj.SetActive(false);

eternal needle
#

If these prefabs are massive, then yea its gonna take time to set them active/inactive. Your solution in that case is to make them smaller

#

can you show the hierarchy of this prefab

gray crest
scarlet skiff
#

btw this is for rotation, right?

#

if so whats W for

eternal needle
summer stump
# scarlet skiff btw this is for rotation, right?

Quaternions represent a rotation. You really don't need to know what W means. But if you want you can look up the incredibly complex math of quaternions.

In game dev you should just work with euler angles though. The x y and z will NOT be what you see in the inspector

sage mirage
#

Hey, guys! I have a question. Can I pause and unpause my game on IEnumerator? On my game, I have made pause menu screen to be enabled and disabled with a time delay. That's why I made everything on IEnumerator. So, I want to freeze the game and unfreeze after unpausing. Can I do something like that insdie IEnumerator?

#

Check my code

#
{
    if (Input.GetKeyDown(KeyCode.Escape) && pauseIsActive == false)
    {
        yield return new WaitForSeconds(pauseDelay);
        pauseIsActive = true;
        pauseMenuScreen.SetActive(true);
        Time.timeScale = 0;
        Debug.Log("Pause menu screen is active!");
    }


    else if (Input.GetKeyDown(KeyCode.Escape) && pauseIsActive == true)
    {
        yield return new WaitForSeconds(pauseDelay);
        pauseIsActive = false;
        pauseMenuScreen.SetActive(false);
        Time.timeScale = 1;
        Debug.Log("Pause menu screen is not active!");
    }
}```
gray crest
rich adder
#

bad

sage mirage
#

I have a problem with Time.timescale

slender nymph
rich adder
slender nymph
#

yeah also shouldn't be getting input in there

wintry quarry
eternal needle
sage mirage
#

I thought, I could use input inside it and write StartCorountine on Update() that's what I did

#

Anyway, I will fix it

rich adder
sage mirage
scarlet skiff
#

how come?

wintry quarry
#

so you can't call FireProjectile on a GameObject reference

#

you're also trying to call it on a prefab which is sus

scarlet skiff
#

but i put the perfab in the gameObject field

#

dragged it into it

wintry quarry
rich adder
# sage mirage Oh, true!
bool isGamePaused = false;
    Coroutine pauseRoutine = null;
    void Update()
    {
        if(Input.GetKeyDown(KeyCode.Escape))
        {
            if (pauseRoutine != null) return;
            pauseRoutine = StartCoroutine(PauseGame());
        }
    }
    IEnumerator PauseGame()
    {
        isGamePaused = !isGamePaused;
        if (isGamePaused)
        {
            //dostuff paused
        }
        else
        {
            //dostuff not paused
        }
        yield return new WaitForSecondsRealtime(wahetevr);

        pauseRoutine = null;
    }```
scarlet skiff
#

the prefab had a script which had it

slender nymph
ivory bobcat
#

Well, you're referring to it as a Game Object only

wintry quarry
ivory bobcat
#

Refer to it as the specific script, if needed.

scarlet skiff
#

but it makes it green, so it refers to the class

wintry quarry
#

GameObject is a class too you know

ivory bobcat
#
public SpecificScript ss;```
scarlet skiff
#

or no it says this

scarlet skiff
wintry quarry
#

notice how you did myBoulder.FireProjectile()

#

not GameObject.FireProjectile()

ivory bobcat
#

Maybe lookup some basic C# tutorials UnityChanThink

wintry quarry
#

you're confusing the type of a field with the field itself.

rich adder
scarlet skiff
#

otherwsie id have capitalized class names

rich adder
#

ctrl + r twice tho

scarlet skiff
#

i see

polar acorn
rich adder
#

see it says Rename symbol's file

#

not sure why its called symbol but wahetv lol

scarlet skiff
polar acorn
rich adder
#

xD

polar acorn
#

Variables, properties, classes, methods, and structs all have "Symbols", so you can use that when you don't know or care which one you're talking about

rich adder
#

ir right click + rename

scarlet skiff
#

box was already ticked

polar acorn
rich adder
#

yup that means it should rename the file too

scarlet skiff
#

when is it suppsoed to change the files names?

#

the symbols name, i mean

summer stump
timber urchin
rich adder
#

thats weird isn't raycast hit a struct

slender nymph
#

just use else for that second block instead of checking if hit.collider is null

timber urchin
#

Im getting the following error, I know it is probably simple to fix but for the life of me I cant seem to fix this

polar acorn
summer stump
slender nymph
polar acorn
# timber urchin

if (hit.collider == null)
What is this checking if the raycast hits nothing

scarlet skiff
#

and uhmm is there a chance or something that could contribute to it not working?

polar acorn
#

hit doesn't exist

scarlet skiff
#

if it DOESNT change the symbols name

#

after enter

#

also i clicked on something n it looks like this now

summer stump
scarlet skiff
#

the boxes r gone 😔

rich adder
#

that would still make no sense though cause nothing is assigned to it

slender nymph
#

not even necessary though. they can just use else instead of that second if statement. since checking if hit.collider == null is the same as checking that the raycast didn't hit anything

rich adder
#

yea makes sense

slender nymph
#

but yeah assigning either default or new() would technically solve their error

summer stump
rich adder
#

is this rayhit even supposed to be local?

summer stump
scarlet skiff
#

yall am i a game dev? 🙏

wintry quarry
#

technically

scarlet skiff
#

im making it out the hood

rich adder
slender nymph
polar acorn
rich adder
#

yeah that GameObject is useless here

timber urchin
scarlet skiff
rich adder
#

also you would change GameObject to Boulder in the instantiate

scarlet skiff
#

dont i need it to be GameObject to Instantiate

#

ohhgh yee yee

#

what happens if i replace Boulder spawnedObject with boulder

polar acorn
slender nymph
#

yeah ideally you'd have a second variable of that type (probably one that is not public) that holds the reference to the instantiated object. assuming you'd want to be able to instantiate a boulder more than once with this class

scarlet skiff
#

hmm i think i get it

#

its like taking the balue print and making an object out of it and assigning it to a variable, if i assign it to the blue print then the blue print is gone and i just have one instance?

timber urchin
slender nymph
#

do you know how to pass an object as a parameter to a method?

timber urchin
#

I think so yea

slender nymph
#

so then what part of what i suggested are you not understanding?

scarlet skiff
#

soo.. i dont really get this

#

i want rockSpawner to be a part of the catapult_1 parent

true pasture
#

can I not access this value onEnable? its giving object ref error

summer stump
slender nymph
wintry quarry
timber urchin
true pasture
#

ah i see TY

scarlet skiff
slender nymph
scarlet skiff
#

however, evenm if i wanna move rockSpawner to that parent it still gives same error, even tho it is not a prefab

rich adder
#

then you can modify it

scarlet skiff
#

hmm hmm

rich adder
#

unity treats model files as prefabs its weird

summer stump
rich adder
#

yeah lol they should've really made it a diff color

timber urchin
scarlet skiff
#

ok so i unpacked the prefab, added the rock spawner, then made it a prefab again, but the movement script doesnt make the rockSpawner follow

rich adder
#

btw always keep ur console window docked somewhere where its fully shown

scarlet skiff
#

the parent has this script

polar acorn
#

Don't create any unity components with new

rich adder
slender nymph
#

what you really want there is just a reference to the Rigidbody by dragging it in the inspector

rich adder
#

^this also swap from translate to rigidbody based movement

scarlet skiff
#

cleaned up the script i didnt need the rest

slender nymph
#

just so you know, your movement does not respect colliders

#

so the object will not collide with anything

scarlet skiff
#

wait nvm i do need hte rigbibody so i can use rigidbody based movement

viral hemlock
#

quick question how can I spawn the same object at 2 points

rich adder
slender nymph
#

call Instantiate twice where you provide one of the relevant points each time

polar acorn
viral hemlock
slender nymph
#

you're gonna need to elaborate because that can be interpreted in a number of ways

polar acorn
austere monolith
#

who is the best youtuber for tuts

#

in opinions

viral hemlock
scarlet skiff
#

aight less go gang

rich adder
austere monolith
#

whats the best way to learn?

rich adder
slender nymph
# scarlet skiff aight less go gang

you should also not be applying physics like AddForce inside of update, do that in FixedUpdate. also when you make that change remove the deltaTime multiplication. and you'll likely want to use ForceMode.Impulse rather than the default forcemode

slender nymph
#

and the pathways on the unity !learn site are good

eternal falconBOT
#

:teacher: Unity Learn ↗

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

scarlet skiff
#

nope, rotation is too slow then

#

but then.. should i just buff the speed or put it in Update? 🤔

#

i have a feeling that Update has to be blue

rich adder
#

rotation you want rb.MoveRotation

#

also nesting Update inside FixedUpdate is wrong

#

Update never gets called there

#

Vector3.forward should be transform.forward

scarlet skiff
scarlet skiff
#

i did think about it

#

that it had to be based on rb

rich adder
#

you technically can still use transform.rotate but the inaccuracy might be significant enough

scarlet skiff
rich adder
#

you should probably show updated code

#

also don't use screenshots

#

!code

eternal falconBOT
scarlet skiff
#

what does the last arguemtn for Quaternion do tho, i understand the first 3 are the rotation around the 3 axis

scarlet skiff
rich adder
#

wdym Quaternion has 4 values (x,y,z,w)

scarlet skiff
#

like myRigidody.MoveRotation(new Quaternion(rotationSpeed,0 ,0 ,0));

rich adder
#

you should never have to use new Quaternion

#

like ever

#

work with Euler angles

scarlet skiff
#

it is asking for Quaternion

summer stump
summer stump
#

Or whatever it is

rich adder
#

yup that one

scarlet skiff
summer stump
scarlet skiff
#

its not rly rotaiton speed, but how much it should rotate with

#

maybe my naming is bad

rich adder
#

so it would never work

summer stump
#

Each value of a quaternion is the TWIST around an axis. I guarantee it is not what you think it is

scarlet skiff
rich adder
#

The reason it worked before is because transform.Rotate can take in a Vector3 as arguement, if you want to use eulers

#

it has different signatures

#

moverotation doesn't have Euler (only accepts Quaternion)

summer stump
scarlet skiff
#

uhhh wdym by inspector for rotation

summer stump
#

Which part is throwing you?

scarlet skiff
summer stump
# scarlet skiff not exactly

It's the window on the right be default, with the word inspector above it. It has all the values of a game object. Like position and rotation right at the top.
I recommend taking the Unity Essentials path at learn.unity.com before proceding further

rich adder
#

same rotation in quaterion

scarlet skiff
#

oooo

#

its called inspector

#

i just call it right side

wintry quarry
#

but you can move it to the left side!

rich adder
#

and/or have many popups of them!

scarlet skiff
#

ah... damn bro..

#

shoulda peeped game n locked in in class

modest dust
#

Or you can turn it into oblivion and not have any inspector tab at all

#

Who needs it anyways

rich adder
#

make custom inspector, win

modest dust
#

Or just make your own game engine

rich adder
#

I want my fields to have analog guages

scarlet skiff
#

bro i just wanted to make a catapult shoot boulders

#

i am not making it outta hood

rich adder
scarlet skiff
#

cuz it had an error

#

which i was trying to look up

#

but the explanation to it dont really sit with me

rich adder
#

why are you using new

modest dust
#

Quaternion.Euler returns a Quaternion

rich adder
#

and are u sure X is what you want to rotate instead of Y

modest dust
#

It's not a constructor, it's a static method, no need for new

scarlet skiff
#

..?

rich adder
#

like a airplane

scarlet skiff
#

😭

slender nymph
#

always. because it rotates around that axis

scarlet skiff
#

dam

#

i see

#

thats...

#

uh.. okey

static cedar
#

Where the pic of yaw, something?

#

🍵

scarlet skiff
#

yaw?

rich adder
#

Y rotation in unity is yaw

polar acorn
slender nymph
#

this should also be helpful where head is the yaw in this image

rich adder
#

i dig it

scarlet skiff
#

i c

#

this is in degrees, right?

slender nymph
#

yes. though you won't be correctly accumulating your rotation there if you're using MoveRotation

#

unless this is in FixedUpdate where it won't really matter if you accumulate it or not

wintry quarry
#

it should be * Time.fixedDeltaTime if in FixedUpdate to be degrees per second, and is just incorrect if in Update

scarlet skiff
#

maaaann..

#

cant even say bro

#

anyways, it no longer knows where forward is

#

its movement is no longer based on the rotation

#

and its 12:14

#

i have yet to do things

#

that i needa do

#

😔
this has been a lil humbling and wee bit disapointing

rich adder
#

bro speaking in riddles

polar acorn
timber urchin
rich adder
scarlet skiff
#

how is this is even possible 😭

rich adder
scarlet skiff
#

its just an exercise, we just gotta make a catapult shoots balls

#

and add more stuff if we have time

rich adder
#

no sane teacher would say any gamedev would neeed only 15 min

#

its possible but why, would you

viral hemlock
#

this is a stupid question but is there an opposite of the random class

frosty hound
#

Sounds more like a 15 minute assignment after a whole class/classes and someone slacked off.

slender nymph
scarlet skiff
slender nymph
scarlet skiff
rich adder
scarlet skiff
#

i did learn... some things..

frosty hound
#

Well then, to answer your question: it is possible.

scarlet skiff
#

i dont think anyone managed in 15min

frosty hound
#

Using AddForce to launch a rigidbody is only a few lines of code. It really is the basics of Unity.

viral hemlock
scarlet skiff
#

but most of em were almost finished after like 2 - 2.5h

rich adder
#

yeah but they're doing like rotating a catapult and all that

rich adder
#

not sure if thats part of the assigment or what

slender nymph
polar acorn
timber urchin
scarlet skiff
viral hemlock
#

but what class would i use

wintry quarry
rich adder
#

pass specific values?

wintry quarry
#

what do you want?

slender nymph
slender nymph
polar acorn
rich adder
viral hemlock
#

alright what function or class could I use to use fixed data

polar acorn
#

If you don't wnat random... don't use random

#

use the value you want

scarlet skiff
polar acorn
slender nymph
polar acorn
#

use that

rich adder
slender nymph
eternal falconBOT
rich adder
scarlet skiff
rich adder
#

fix ^^

scarlet skiff
#

i see

slender nymph
#

just use AddRelativeForce or that fix

timber urchin
scarlet skiff
rich adder
scarlet skiff
#

wait

#

i see

wintry quarry
slender nymph
# timber urchin

now use the already populated hit variable rather than constructing a new RaycastHit

timber urchin
summer stump
viral hemlock
#

alright guys sorry for the difficulties i figured it out

rich adder
# scarlet skiff i see

the vector3.forward is World dir
transform.forward is local dir

or what Boxfriend said instead

scarlet skiff
#

👍

timber urchin
scarlet skiff
#

dam why it slides so much

#

dam there is so much wrong still

#

makes sense now how game devs be staying up til 3

#

what did i get myself into...

#

anyways ill have to hit the hay now, thanks everyone for your pateince today

slender nymph
#

ah was the AddForce supposed to move the catapult rather than launch the boulder? because if so you should remove the ForceMode.Impulse parameter from that call

#

oh and you'll want to make sure that your rigidbody has drag and friction otherwise it will just slide forever

trail gull
#
    private void OnCollisionEnter(Collision collision)
    {
        if (other.TryGetComponent<Walls>(out Walls walls))
        {
            Debug.Log("Hit wall")
        }
    }

this is my code, I have an empty object called 'Walls' with the children as all of the walls of my map, why am i getting this error?

The type or namespace name 'Walls' could not be found (are you missing a using directive or an assembly reference?)
summer stump
trail gull
summer stump
slender nymph
trail gull
#

Oh

#
using UnityEngine;

public class Walls : MonoBehaviour
{
  
}
#

would I just do that?

summer stump
trail gull
polar acorn
#

Tags

summer stump
polar acorn
#

But you only get one of those

lofty sequoia
#

like maybe use the OnCollisionEnter on Walls

topaz gorge
#

How would i access the Unity Transport Bool Allow Remote Conneciton through a script cant seem to find it anywhere

mystic oxide
#

Can someone explains to me what is Wwwform class? I still dont get it, is it creating an temporary form or generate form data to a server

wintry quarry
mystic oxide
#

Gotcha, thanks! UnityChanThumbsUp

full iris
wintry quarry
full iris
#

😌 Oooooh thank you so much! @wintry quarry

deft quarry
#

I have a basic player movement script going so far and I aim to incorporate a double jump. I believe i've set up my logic correctly yet I can still jump infinitely. Can someone help me and point out where I went wrong?

buoyant knot
#

you should really avoid variable names like dJ. it makes it like impossible to understand

deft quarry
#

Sorry, kinda forgot other people might be seeing this so I just used variable names that made sense to me

buoyant knot
#

you should also use better variable names for yourself

#

the most likely person to read your code is yourself several months/years in future, when you no longer remember wtf you were doing

deft quarry
#

You're probably right, i'll work on it.

buoyant knot
#

i recommend splitting jump check from executing jump

#

jump function should just be in charge of executing a jump. not checking logic to see if a jump should be possible

#

single responsibility principle, especially since those responsibilities might become more involved

deft quarry
#

Good point, should I just keep them in the update function instead?

buoyant knot
#

your isJ bool isn’t being changed when you call jump

buoyant knot
#

Update in movement scripts tend to get really busy, so you want to be super organized

deft quarry
rich bluff
#

it is copied

#

you send a copy of it into the ground check method

#

you change that copy

#

original stays unchanged

deft quarry
#

Oh shoot, i forgot about that

#

That explains so much

teal viper
#

*value type to be precise

buoyant knot
#

i cannot stress enough how much 1-2 letter variable names are cancer

rich bluff
#

public struct Boolean

deft quarry
#

Is there any way I can pass the isJ variable into the function and have the actual variable be updated and not just the copy?

rich bluff
#

yes

#

ref modifier on the parameter

#

or just return

#

return j;

buoyant knot
#

don’t use ref

#

GroundCheck should return a bool.

#

isJumping = GroundCheck();

#

which also makes it obvious why that line is wrong

#

because you should not be setting isJumping to a value depending on ground when you know you just jumped

#

player state should also be an enum

#

i think he’s gone now

deft quarry
#

im not

#

just thonking with my below average noggin

deft quarry
static cedar
deft quarry
#

That sounds like aids

static cedar
#

It's a code from a flash game when he was pretty new to it.

deft quarry
#

Im actually curious now. Do you have it? I'd love to see it

silk night
static cedar
#

I'm on phone rn but I sent the file here.

#

Lemme just search it.

#

@deft quarry

deft quarry
#

Thank you!

#

holy hell thats eye bleach worthy

static cedar
#

ActionScript, TypeScript but the safety isn't imaginary guardrails, it actually exists. UnityChanThink

full iris
silk night
static cedar
silk night
#

Please tell me that is autogenerated and somebody didnt lock their dev into their basement until that was written

static cedar
#

But I'm not sure why the loops turned into a while loop with the index outside.

#

I'm not perfectly sure if it's actually built like that to begin with.

buoyant knot
silk night
#

Yeah thats why i understand the variable names, but the nesting doesnt suddenly pop into existence when decompiling something 😄

buoyant knot
#

this way you don’t handle a bunch of bools that should be mutually exclusive

static cedar
#

I'm sure with the nested ifs though.
He definitely didn't want to use AND since he used both AND and OR sparsely around so it's not just the decompiler.

buoyant knot
#

my issue was that we didn’t understand the math since we didn’t understand wtf the variables represented, nor their units

#

if we knew the units, we could try to infer what they meant, but no dice

static cedar
#

Also they bought that reason?

buoyant knot
#

it was true

#

i was the most computer saavy guy in the lab. if I say “it’s not happenning”, then it is simply not happenning

static cedar
#

Seems legit.

buoyant knot
#

in the land of the blind, the cyclops is king

rich bluff
#

the enjoyment of the biggest fish in the pond

deft quarry
#

Sorry to be back here, but how would I check to see if I can double jump or not? I've tried almost everything I can think of, and I cant seem to get it.
Updated Code: https://gdl.space/eluzexegel.cpp

gaunt ice
#

Do you know that you can modify class properties in method?

deft quarry
#

Yeah, is the answer simple and im just on the spectrum?

summer stump
deft quarry
#

I thought of that, but thought it would just add more variables to my code when what I had would suffice.

summer stump
#

So use that?

#

You have a doublejump method too?

#

I feel like this is way more convoluted than an int

deft quarry
summer stump
#

Make it much more simple and clean

deft quarry
#

That

#

is a good point

rich adder
#

so many bools

#

this hella messy

deft quarry
#

Yeah, im not the most experienced

summer stump
#

Wait, also do you have compile erros? Your Jump method has an isJump bool (why?) but checks isJ

#

Why does the GroundCheck method have a bool passed IN?

deft quarry
#

No, I changed that before posting to try and make variables more clear and guess I missed one

deft quarry
#

very inefficient though

true pasture
#

how do you check if callbackcontext is null basically? I cant do context.cancelled for reasons.

#

(couldnt find anything online that worked)

wintry quarry
#

What are you trying to do

#

btw it's a struct so no it can never be null

true pasture
#

so im jumping and when I let go of jump, I was trying to check for when it was let go (or no input). but I cant use context.cancelled because they are on different scripts. the jump is actually started from onenable but what enables the jump state is the jump input on another script

wintry quarry
true pasture
#

lol im sorry

wintry quarry
#

do your input handling as needed, using canceled to detect when the button is released

#

communicating that with another script is a separate concern

summer stump
#

I feel like you just... want ctx.canceled.
When the one script gets that callback, send that information to the other script

true pasture
#

only 1 script is enabled at a time

#

how would I send context to another script

summer stump
#

And a disabled script can still accept and run code. Just not run Update and (unfortunately to this situation) receive input callbacks

true pasture
#

im sorry what

#

thats news to me

wintry quarry
true pasture
#

apparently nothing

wintry quarry
#

enabled only determines when Unity callbacks are run on your script. You can call functions as you please regardless of the enabled status

true pasture
#

unity events for input wont run from a disabled object though right?

#

hopefully that made sense

wintry quarry
#

If you're using the PlayerInput component I don't see why the object it's attached to should/would ever be disabled

#

PlayerInput is 1:1 with a human player

true pasture
#

yeah i mean the object you plug into the events

wintry quarry
#

It will still run functions on a disabled object

true pasture
#

that ruins my state machine then? (not asking like you know)

wintry quarry
#

Is that a question or a statement?

true pasture
#

all these objects have scipts that do stuff on the playerinput component. youre saying they are always running the callback context in their functions?

wintry quarry
#

wdym by "running the callback context"?

true pasture
#

they each have functions that accept callback context

#

and theyre running while the opbject is disabled according to you?

wintry quarry
#

If you mean that you've assigned functions on them from the PlayerInput component inspector unity events, then yes

#

they will run

#

assuming the PlayerInput itself is enabled / active

summer stump
# wintry quarry they will run

Are you sure? I thought that they would no longer receive the callback event if the script was disabled. Someone said they tested it, but I did not yet

wintry quarry
#

Well now you're all making me question it haha

#

But C# events definitely don't care

#

I guess its possible UnityEvent checks but I'd be surprised

#

naturally the docs are silent on the matter

true pasture
#

trying to test rn lol

slender nymph
#

considering objects can be enabled from unity events, i don't think them being disabled is going to prevent anything from happening when the unity events are invoked

#

and you can still call methods on disabled objects, it's just certain unity messages are prevented like Start, Update, and FixedUpdate

true pasture
#

yeah looks like it runs while disabled fml

sour fulcrum
#

you can just check if its enabled

true pasture
#

u right that will prob be easiest ty

true pasture
#

ty for the help Im still not sure on the context for my first question but I need to fix this right now

#

so for this why cant I use gameObject.isActiveandEnabled. it only lets me do this.

#

in the docs they say it checks a GameObject

wintry quarry
#

not sure why you would want to use gameObject

true pasture
#

oh good point im not supposed to be using the current object (wait yeah I am lol)

#

whoops

gaunt ice
#

I didnt know anything about new input system, but why the fsm is in forms of gameobject

true pasture
#

my medicines worn off dont flame me😭

rich bluff
#

its fine, convenient way to represent and work with fsm

#

only problem is that if the hierarchy with it is moving you are adding pressure to the scene graph

gaunt ice
#

adding a debug panel is easier for me…..less gameobject needed but your scene will be mess

quiet eagle
#

how do i reference classes defined in separate scripts?

#

do i have to have a reference to it or something>?

rich bluff
#

check pins

wintry quarry
quiet eagle
#

unity.huh.how LMAO

#

i love that

hexed valve
#

Text is a legacy type of component you

quiet eagle
wary sable
#

How would I grab a refrence to an asset from its path?

rich bluff
#

AssetDatabase

#

get guid from path

#

get asset from guid

wary sable
#

tyty

#

when using CreateInstance for a scriptable object, does unity actually create an asset?
or will it get GC'd after runtime?

rich bluff
#

it creates it in memory

#

you have to write it with AssetDatabase

wary sable
#

ok cool, so I can use createInstance and createasset separately without issue

rich bluff
#

it can be a way to leak, because any unity object represents native resource which may not be cleaned up until you call Destroy on it

wary sable
#

would calling destroy on the reference to the SO after its been created as an asset destroy the asset?

rich bluff
#

all my code uses AssetDatabase.DeleteAsset for that i guess it will just throw if you try

#

i imagine i would be like - destroy instance in memory, see it still serialized on disk, reimport, instance created again but ref invalidated, invalid state

wary sable
#

gotcha, I was only asking since you said that it could cause a memory leak, that if it was because there was a version of the SO in memory and in storage that I would possibly need to clear the one in memory to prevent any problems

rich bluff
#

any SO that has backing asset is in essence bound to that asset, unbound instances are "unmanaged" by unity, so their lifetime control is on you

wary sable
rich bluff
#

bound

wary sable
#

wonderful

rich bluff
#

unity will associate now this instance with the .asset

#

people use SOs for runtime representation as well, cloning or creating in place for various use, so i mentioned the general leak possibility

wary sable
#

I was able to get it working, thanks so much for all the help you are a life saver

#

actually one more thing, I tried to use CC's like you suggested and wanted to make sure I'm using them correctly, does this look good?

#

||I know "no screenshots"||

rich bluff
#

yep

#

another one to know is DEVELOPMENT_BUILD

rich bluff
wary sable
#

DEV_Build is actually super nice to know tyty

wary sable
rich bluff
#

you dont need but you can and should

#

it will automatically compile everything in it into editor assembly

wary sable
#

I definity will add that rn

rich bluff
#

folder can be anywhere and you can have any number of them

#

same as Resources and Plugins

queen adder
#

How do you usually handle NRE's that happens when you stop playmode, is it good to be ignored?

#

does that NRE's even happen in the actual game?

wintry quarry
#

Generally you shouldn't have any NREs in any circumstances

rich bluff
queen adder
#

yea that thing

wintry quarry
#

check for null before accessing references which may be null (or destroyed in this case)
that means if (thing != null) checks in your OnDestroy and OnDisable code

rich bluff
#
        public static bool IsNullOrDestroyedSilent(this object uobject)
        {
            try
            {
                return !(uobject as UnityEngine.Object);
            }
            catch
            {
                // swallow the exception
            }
            return true;
        }
``` hacky way to get around that
queen adder
#

it's just annoying to have to check them when they are meant to be like always active :<

wintry quarry
#

all objects in the scene are destroyed when the scene is unloaded

#

disabled first, then destroyed

queen adder
#

they're like permanent thing, but closing the game breaks the rule

queen adder
ruby python
#

!code

eternal falconBOT
ruby python
#

Mornin' all. More adventures in gravity.

Would someone be willing to take a quick look at this and give me any pointers please?

https://pastebin.com/SFVvj4rr

I'm basically changing the gravity vector on the fly to simulate planetary gravity (spherical world etc)

I'm using a rover as an experiment, I have the driving around the planet etc. all sorted and working.

The part i'm interested in is.....

    roverMass = roverRigidBody.mass;
    float gravityForceOnObject = roverMass * gravityForce;
    roverRigidBody.AddForce(-gravityVector * gravityForceOnObject);

what I'm now trying to do (that will be applied to a ship object later when it's working), is to counteract the gravity, so that my eventual ship will 'hover' automagically. I think I have my gravityForceOnObject calculation wrong because currently instead of hovering, the rover just flies straight up (although in the correct direction).

wintry quarry
#

Once in the first gravityVector calculation and again in the gravityForceOnObject calculation

ruby python
#

Oh....of course I am. So the gravityForceOnObject is completely redundant? lol.

wintry quarry
#

Note that in a game with custom gravity directions using Physics.gravity is probably not going to work out for you since it's global

ruby python
#

Aaaah, okay. Yeah that makes sense. Sorry, tend to glass over a bit when it comes to physics stuff. lol.

wintry quarry
#

Usually custom gravity through AddForce is in the cards

tepid cobalt
#

Can you add a seperate artifical gravity to your objects to countteract?

spring hemlock
#

How do I pass stuff like GameObjects into FSM scripts?

ruby python
#

I haven't implemented it on this specific script yet, but the gravity 'range' is limited for each planet (ie, big ass trigger that turns it on and off for each planet with their own vectors and strengths.

wintry quarry
tepid cobalt
#

cool

ruby python
ruby python
#
void Update()
    {
        gravityDirection = currentPlanet.position - transform.position;
        gravityVector = gravityDirection.normalized * gravityForce;
        Physics.gravity = gravityVector;
        roverRigidBody.AddForce(-Physics.gravity, ForceMode.Acceleration);
    }
wintry quarry
#

AddForce should only be called in FixedUpdate

ruby python
#

ah, bugger. lol. Thank you.

#

Yeah that works, thank you. Thinking about it, would it be better to put all of that gravity code in FixedUpdate?