#💻┃code-beginner

1 messages · Page 216 of 1

quartz grove
#

And godot ?

rich adder
#

so you think thats an essential feature to have ?

summer stump
#

Pretty sure it's FOSS though?

#

All of this is very googleable though

rich adder
#

Still unclear what you're asking on what the problem is tbh

summer stump
#

The themes are what the editor looks like. Like themes for Google Chrome or Firefox, where the background and buttons looks slightly different.

It's a big nothing-burger

polar acorn
#
  1. The position of the transform
  2. How many elements the vector has
#

Oh, I was scroll locked and we've all moved on, nevermind

cosmic dagger
#

happens to me all the time, i hate it . . .

quartz grove
crisp token
#

does .equals in java for two objects not just compare their members? It seems like its doing something else

rich adder
#

java?

crisp token
#

yeah, for a server

cosmic dagger
#

wrong server?

rich adder
#

perhaps ask in java server lol

rare basin
crisp token
#

well its for unity kind of

rich adder
#

Im using Microsoft's version of Java

rare basin
#

you dont programm in Java in Unity

crisp token
#

I have a database server for my unity pvp game

rare basin
#

still not related to unity

#

your server code != unity code

crisp token
#

its a simple question iwas looking for a quick answer thats all

rich adder
#

then ask in a java server?

polar acorn
#

There's not too many people who know java here

crisp token
#

oh ok, thanks

rare basin
#

in google

#

in 10 seconds

polar acorn
#

But I'm pretty sure it's a full reference-equality unless you override it

#

it'll return true if two objects are literally the same object

crisp token
#

I looked that up but they all say that .equals compares contents vs == compares reference but I dont think thats true

#

i mean i proved its not true

cosmic dagger
pallid nymph
#

equals is a custom implementation, it can compare whatever

#

== does a ref equals

#

or so I'd assume

crisp token
#

loading two small classes into pastebin ill show

polar acorn
rich adder
#

why not just make your server in c#..

polar acorn
#

if it's going to require looking at code

crisp token
#

ik some people sounded curious thats all

quartz grove
#

u know what i ll just go with unity

#

i like the icon

crisp token
short hazel
#

== compares by reference in Java. For strings, you use .equals() to compare the value. C# has no such restrictions because, unlike with Java, operator overloading is allowed

#

So each type could implement its own behavior for most operators

crisp token
#

So are you saying when you call .equals() on two objects it's using the == operator on each member indiviudally?

frosty hound
#

@crisp token Make a thread, this topic isn't related to this channel.

rich adder
#

why not just make the server in c# lols

buoyant knot
#

i’m prettt sure C# lets you == with strings pretty well

#

strings are not a reference type in C#

hearty trout
#

I found a tutorial that explains the system in great detail but ima need to still learn alot other stuth so thank you for all the feedback and I am going to reconsider jumping straight into my dream game @rich adder

rich adder
short hazel
#

They are

rich adder
#

are they not just arrays of char

#

oh ok

scarlet skiff
buoyant knot
#

what. i thought they were value type jn C#

rich adder
#

negative

static bay
#

Nah they're immutable reference types.

rich adder
#

immutable types

static bay
#

Trust you do NOT want value type strings.

crisp token
#

what's an immutable type?

static bay
crisp token
#

so what would be a mutable type

static bay
#

As opposed to Mutable, wich can be changed.

queen adder
#

Let's check the docs

rich adder
shell sorrel
#

you can'd modify the string in place only replace it, but its a reference

queen adder
crisp token
#

what do you mean when u say changing a type. Like reassigning their value vs replacing w/ new object?

buoyant knot
#

i feel like i’ve been lied to

shell sorrel
#

string can't be a value because well that would be a lot to pass around, and also its length is not knowen

queen adder
#

Strings are normally allocated on the heap in most languages?

shell sorrel
#

like a int we know is always 4 bytes

#

a string who knows

rich adder
#

example you cannot do this

static bay
# buoyant knot i feel like i’ve been lied to

Nah. Imagine how bad that'd be if they were a value type. Every time you'd pass it into a function you'd generate a copy. Considering how MASSIVE strings can get, it's asking for trouble.

rich adder
#

you have to replace the whole string

short hazel
#

Equality check for strings in C# does the following, in order:

  1. Do they point to the same area in memory?
  2. Is either of them null, or do they have a different length?
  3. Each character is converted to a byte and efficiently compared with SpanHelpers.SequenceEquals() (which does not allocate)
    Source
buoyant knot
rich adder
#

still good practice to do so

static bay
#

Agreed

queen adder
#

Yeah everyone says use StringBuilder or the Span<> type

shell sorrel
#

stringbuilder for building larger strings is mostly about allocations

#

but yeah would use it if building a large string out over time

buoyant knot
#

ref type does make more sense. i just thought the people who made C# had the same stroke of genius as the guy who made Mathf a struct

static bay
#

Actually stringbuilder is for babies. Real men don't need some so called "builder" and just do raw +.

rich adder
#

lol

polar acorn
shell sorrel
#

not that it matters, think it only has constants and methods

buoyant knot
#

and also decided it would be okay for arrays to implement IList, despite arrays lacking the major things that make a list not an array lol

rich adder
queen adder
#

Mathf has a lot of static methods and fields I wonder why it isn't a static class?

quick edge
#

I'm gonna ask again my question, because I think I explained it the wrong way. What I want is to be able to do something over x amounts of time. Example, over 10 seconds I want to be able to move, during these 10 seconds I can move but after the 10 seconds I can't. How can I achieve that ?

buoyant knot
quaint crystal
#

hello. does doing this only remove the reference from the array? so if i want to delete a dog i should use Destroy()?

dogArray.RemoveAt(0)
shell sorrel
static bay
#

Waaaat?

rich adder
#

this only removes it from list not destroy it ( the item)

buoyant knot
#

he envisioned a world where you want to have a couple of different instances of Mathf angerjoy

quaint crystal
buoyant knot
#

yeah, Mathf is a struct

rich adder
polar acorn
rich adder
#

otherwise you have no reference valid

static bay
quaint crystal
#

thank you

buoyant knot
#

System.Random is not static

static bay
queen adder
#

The Unity namespace has a Random class to

cosmic dagger
#

the Unity version . . .

queen adder
#

I get that fucking conflict all the time

buoyant knot
#

idk, I only use System.Random lol

queen adder
#

Are they not the exact same thing?

shell sorrel
#

i like the system one when i need to control the seed

#

but the unity one has very useful stuff for games on it

#

like unit vector values

edgy prism
#

Hello ChatGPT has assured me that this function will loop until fishCaught is true based off of coroutine functionality, but its not working for me rn so I just wanted to double check cause im doubtful

public IEnumerator StartFishing()
    {
        bool fishCaught = false;

        if (UnityEngine.Random.Range(1, 101) <= 10)
            fishCaught = true;

        while (!fishCaught)
        {
            yield return null;
        }

        GameController.Instance.StartBattle(BattleTrigger.Water);

    }
shell sorrel
#

insideUnitCircle and insideUnitSphere for example

quick edge
rich adder
#

we should have a rule, do not fix broken gpt code 🙄

shell sorrel
queen adder
#

ChatGPT is not the end all of stuff being certain

buoyant knot
edgy prism
#

No

#

I wrote it myself

shell sorrel
#

essentially it tries to catch fish once and if that fails it loops doing nothing forever

buoyant knot
#

then why are you asking ChatGPT a question about something which it does not understand

static bay
frosty hound
#

That code will result in an infinite loop

edgy prism
buoyant knot
#

also, this is definitely an infinite loop

rich adder
shell sorrel
#

you have to learn how to program GPT will not do that for you

low path
#

wasn't there somebody in here before saying how chatgpt was amazing for code comprehension, and good for juniors or s/t?

buoyant knot
rich adder
buoyant knot
#

it cannot explain, as it does not know

shell sorrel
#

anyone with a bit of experience can look at that code and see its broken and not working to intent in half a second

edgy prism
queen adder
#

It's good at explaining things. You can't make an entire game from chatGPT if u don't understand how the unity editor works and C# on a deeper level

rich adder
edgy prism
buoyant knot
#

it’s good at making convincing explanations. as to whether or not the explanation is true, that is a different story

shell sorrel
#

it can be done in many many ways including a coroutine

buoyant knot
polar acorn
rich adder
frosty hound
shell sorrel
#

also whole thing can be simplified if you are just wanting to wait till you catch a fish

#

since then its really just about a random wait duration no loop needed

edgy prism
rich adder
#
var time = new WaitForSecondss(timeBetweenChecks);
while (!fishCaught)
        {
          if (Random.Range(1, 101) <= 10)
            fishCaught = true;
            yield return time;
        }```
buoyant knot
#

yeah, you just generate a random wait time, and yield return new WaitForSeconds(thatTime);

#

no while loop involved

shell sorrel
#

yield return new WaitForSeconds(Random.Range(minWait, maxWait));

frosty hound
rich adder
#

much better for gameplay with some rng

edgy prism
#

Ok thanks for your help everyone

acoustic crow
#

I have make a RocketGame , i can move up and i can move down , the problem is i dont have collider for the map and i can go out of map, do you can help me how i can make a collider for my window in android

acoustic crow
#

No... pls read again

static bay
rich adder
acoustic crow
#

you not a smart peopel

rich adder
#

no sorry 😔

acoustic crow
#

i mean a collider for my window on my phone that i can not go out of map

wintry quarry
wintry quarry
cosmic dagger
rich adder
#

teach me oh great one

acoustic crow
#

@wintry quarry thanks for the script do you have a tutorial for me that i can see what i must do

wintry quarry
#

no I don't have a tutorial

edgy prism
#

Hes chosen a smart man

wintry quarry
#

just my recommendation and simple example code

summer stump
quaint crystal
#

if i .RemoveAt(0) an array will a .Add insert into 0?

low path
#

no

shell sorrel
#

Add goes on the end

#

if you want to insert into a spot there is a method for that

low path
#

the docs tells you how add works

rich adder
#

Insert()

cosmic dagger
shell sorrel
#

also assuming you mean List

cosmic dagger
#

if you add to a list, it goes on the end . . .

quaint crystal
#

thank you

cosmic dagger
# quaint crystal thank you

you can google the method name and the language to get the documentation that gives you a description and an example . . .

glossy sierra
#

if (other.CompareTag("GreenObjectCapsule"))
{
IncreaseScore();
Destroy(other.gameObject); // Remove the green object upon collision
PlaySound(capsuleSound);
}
else if (other.CompareTag("RedObjectCapsule"))
{
DecreaseScore();
Destroy(other.gameObject); // Remove the red object upon collision
PlaySound(capsuleSound);
}
}

private void IncreaseScore()
{
    score += 1;
    UpdateScoreUI();
}

private void DecreaseScore()
{
    score -= 1;
    UpdateScoreUI();
}

private void UpdateScoreUI()
{
    scoreText.text = "Score: " + score.ToString();
    // Update UI to display the current score
    // You can use UI Text component or any other UI element to display the score
}
private void PlaySound(AudioClip clip)
{
     audioSource.PlayOneShot(clip);
}

Getting this;-
ArgumentNullException: Value cannot be null.
Parameter name: source
already assign clip in inspector..any suggestions?

rich adder
#

how do you assign capsuleSound

eternal falconBOT
glossy sierra
rich adder
#

use link site and post the entire class

glossy sierra
summer stump
#

Is the audio source on the SAME object as that script?

#

If not, it is returning null

rich adder
#

you might be passing null to the AudioSource, if issue was with AudiSource it would give NRE (or log the error from awake actually)

uncut dune
#

grab layer is a layer mask and I aint sure why it always gets my playwer which is on the default layer

short hazel
#

The error is a bit misleading for this one, it's the audio source that's null. In other conditions this would report a NullReferenceException, but due to how AudioSource is made internally, it's the ArgumentNullException that is thrown.

glossy sierra
summer stump
rich adder
glossy sierra
short hazel
uncut dune
#

it made no sense

rich adder
#

wait they have another audiosource

#

nvm

summer stump
#

But your layer == grabLayer makes no sense if it is a layermask

summer stump
#

Or uncollapse it, or whatever

uncut dune
#

like this it used to get the player

#

as w ell

craggy oxide
uncut dune
short hazel
# uncut dune

The arguments are not correct. You're passing the mask in lieu of the distance. It's origin, direction, distance, mask

rich adder
summer stump
# uncut dune

I don't see an overload where layermask is third
Edit: ah yeah, as spr2 said

glossy sierra
#

NullReferenceException: Object reference not set to an instance of an object
StarterAssets.ThirdPersonController.PlaySound (UnityEngine.AudioClip clip) (at Assets/StarterAssets/ThirdPersonController/Scripts/ThirdPersonController.cs:477)
removed get component still getting this

uncut dune
summer stump
uncut dune
#

its Mathf.Infinity

short hazel
summer stump
rich adder
summer stump
#

Unless- yep spr2 beat me to it

uncut dune
#

never knew that

rich adder
#

if you dont care about order, use named parameters

short hazel
#

.Raycast(transform.position, Vector2.right, layerMask: grabLayer)

summer stump
uncut dune
#

thank you guys!

rich adder
uncut dune
#

appreciate it

rich adder
crude flume
#

how to get assenbly CSharp?

rich adder
eternal falconBOT
polar ermine
trail heart
polar ermine
#

Graphics on this texture is buggy

polar acorn
#

Buggy how

#

it looks pretty normal to me

polar ermine
#

Graphics is a bit jagged when player move

timber comet
polar ermine
#

On a larger screen its more visible

swift crag
#

Video compression will mangle it pretty badly.

#

Are you talking about the patterns towards the end of the walkway?

trail heart
#

@polar ermine Enable mip map generation on the texture, with trilinear filtering if it still looks bad

swift crag
#

yeah, trilinear filtering will blend between mipmaps

north kiln
#

Weird code question

polar ermine
#

Trilinear filtring is on ill try with mip mapping

swift crag
#

it is, indeed, a weird code question!

north scroll
#

In unity, is one Canvas gameobj usually how UI/images are added, or should I have multiple canvas for each item, examples: Timer, Boss Health bar, player mana bar, etc

polar acorn
#

If you can find decent ways to compartmentalize it, go for it. Just don't go nuts

south fjord
#

@near wadi

near wadi
# south fjord

no need to ping me personally, i was just showing you the correct room. also !code

eternal falconBOT
south fjord
# south fjord
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BallWallx20Mover : MonoBehaviour
{
    public Transform Ball;
    public float Orientation = 0;
    public int Speed = 10;
    float Mover = 0;

    void Start()
    {
        Ball.transform.Rotate(0, Orientation, 0);
    }
    void Update()
    {
        Mover = Speed * Time.deltaTime;
        Ball.transform.Translate(Mover, 0, 0);
    }
    void OnCollisionEnter()
    {
        for (int counter = 0; counter < 40; counter++)
        {
            Orientation = Orientation + 180;
            Ball.transform.Rotate(0, Orientation, 0);
            Debug.Log(counter);
        }
    }
}
summer stump
#

Or the wall?

south fjord
#

The object does

summer stump
#

Wait

#

Each time it collides you do that for ENTIRE loop

short hazel
#

Also why the for loop? It's going to be executed in one go so you won't see anything happening

#

Frame gets rendered -> 40 loop iterations execute -> next frame gets rendered

quick pollen
#

How can I move something towards a position without verticality?

south fjord
summer stump
#

Remove the for loop

short hazel
#

That's not how it works yeah

summer stump
#

Increment a class variable

short hazel
#

You need to keep track of the count in some variable

south fjord
#

I see

#

I'll give it a shot, thanks

summer stump
#

private counter = 40

OnCollisionEnter()
if (--counter > 0)
Your orientation thing
Else { end }

limber narwhal
#

is there a different type i can use instead of float because for 0.10 I get Subtracting 0.09999999 from score when I use Debug.Log

rich adder
#

int

limber narwhal
#

int will work with 0.10 ? 🤔

rich adder
#

no

#

decimal would

#

but why that for score instead of int, curious

short hazel
#

You'll most likely want to keep the value as a float, but format it if you plan on displaying it to the user

#

eg. Debug.Log($"Subtracting {score:F2} from score") - "F2": format string for a float with 2 decimals. Adjust the number after the "F" to show more or less. The number is automatically rounded.

#

eg.2 someText.text = score.ToString("F2")

limber narwhal
#

it's because when i subtract .10 its actually subtracting 0.0999999999 or w/e i think

short hazel
#

Yes because of floating point precision errors. In that case you can subtract the two numbers and compare them to some other small value to see if they're roughly identical

#

if (Mathf.Abs(a - b) < 0.01)

rich adder
#

isnt there also mathf.approx

limber narwhal
#

oh that's pretty smart thanks i didn't know about that

north kiln
south fjord
wintry quarry
limber narwhal
quartz grove
#

Hello

#

Why i have error on the first var

polar acorn
#

What's the error

#

Also, !ide

eternal falconBOT
rich adder
quartz grove
#

why it accept the second one

#

and not the first one

rich adder
#

different symbols do different things

quartz grove
#

I thought its like python

rich adder
#

this aint js

polar acorn
rich adder
#

or py lol

polar acorn
#

The first one isn't

quartz grove
north kiln
#

Make sure your IDE is configured before you go down any other python-esque rabbitholes

quartz grove
#

ok ok we starting i ll make snake game UnityChanThumbsUp

quartz grove
potent glen
#

should i learn C# and unity at the same time or should i start learning C# first

#

and if the latter, to what extent should i know C# before starting unity

frosty hound
#

You can do both

#

If you want to do C# specific learning, just start with the basics really.

rich adder
limber narwhal
#

i ended up making a little helper method like this based on some more google searching:

    private float RoundedFloat(float value)
    {
        return Mathf.Round(value * 100f) / 100f;
    }
polar acorn
#

I'm not sure what you're hoping to accomplish with this

#

that's probably just gonna introduce more imprecision

limber narwhal
#

so far it works , but now i'm paranoid from your comment and gonna keep testing it until it doesnt lol

polar acorn
#

It's important to realize that something like 0.01 isn't becoming 0.00999999, it is 0.00999999. That's just how that particular value is represented in floating point. If a value can't be represented exactly in float, then you're not going to "trick" the code into being able to represent it

limber narwhal
#

i kind of understand what you mean

#

so the 0.099999999 is the correct number

naive lion
#

Hey guys half AI half general coding question here
How would I approach a system where if you alert one enemy, all enemy classes/types also become alert of the player

limber narwhal
#

so the other one that isn't 9367.701 is wrong 🤔

polar acorn
polar acorn
naive lion
polar acorn
tender stag
#

how can i increase the gap which the header attribute makes in the editor

#

is it possible through like preferences in the editor?

timber tide
#

if I'm trying to sync rotation with another object but with a offset is adding that rotation directly workable or should I grab the axis information the first object rotated on

rich adder
#

[Header("Hello"), Space(30)]

tender stag
#

i mean yeah but i was wondering if i can change the amount of space header makes

summer stump
#

@old ibex
!code

eternal falconBOT
summer stump
rich adder
old ibex
#
void LateUpdate () {
    transform.position = new Vector3(target.position.x, target.position.y, transform.position.z); //this is line 37

    //keep the camera inside the bounds
    transform.position = new Vector3(Mathf.Clamp(transform.position.x, bottomLeftLimit.x, topRightLimit.x), Mathf.Clamp(transform.position.y, bottomLeftLimit.y, topRightLimit.y), transform.position.z);

    if(!musicStarted)
    {
        musicStarted = true;
        AudioManager.instance.PlayBGM(musicToPlay);
    }
}
tender stag
#

alright thanks

old ibex
old ibex
#

although I doubt it will help

summer stump
old ibex
summer stump
rich adder
#

oops just seen comment 😅

#

yeah you could just put a null check

old ibex
rich adder
#

your code must be running while obj got destroyed for scene change

old ibex
#

yeah and I tried DontDestroyOnLoad(gameObject); but it didnt work

rich adder
#

top of the LateUpdate
if(target == null) return;

old ibex
winter frost
#

Hello everyone! Please, can someone tell me why there is a error in the array? Thank you.

rich adder
rich adder
#

ever heard of an array

#

oh you did since you're using it on the line that errors..

#

thats not how you init an array

winter frost
rich adder
old ibex
winter frost
rich adder
timber tide
#

Can just serialize the array and add more entries on the inspector

old ibex
# rich adder I can't guess , you have to provide proper context like the code and setup

so basically I have an image in the canvas and its alpha value changes via a script I made:

        if (shouldFadeToBlack)
        {
            fadeScreen.color = new Color(fadeScreen.color.r, fadeScreen.color.g, fadeScreen.color.b, Mathf.MoveTowards(fadeScreen.color.a, 1f, fadeSpeed * Time.deltaTime));

            if(fadeScreen.color.a == 1f)
            {
                shouldFadeToBlack = false;
            }
        }

        if (shouldFadeFromBlack)
        {
            fadeScreen.color = new Color(fadeScreen.color.r, fadeScreen.color.g, fadeScreen.color.b, Mathf.MoveTowards(fadeScreen.color.a, 0f, fadeSpeed * Time.deltaTime));

            if (fadeScreen.color.a == 0f)
            {
                shouldFadeFromBlack = false;
            }
        }
    }

    public void FadeToBlack()
    {
        shouldFadeToBlack = true;
        shouldFadeFromBlack = false;

    }

    public void FadeFromBlack()
    {
        shouldFadeToBlack = false;
        shouldFadeFromBlack = true;
    }
#

The script is called whenever there is a scene change

#

so now when the scene changes, it fades to black, but doesnt fade back from black

#

I have an area entrance and exit system

#

In which I manage the scene changes and which scene to change to etc

#

Area Exit:

    void Update () {
        if(shouldLoadAfterFade)
        {
            waitToLoad -= Time.deltaTime;
            if(waitToLoad <= 0)
            {
                shouldLoadAfterFade = false;
                SceneManager.LoadScene(areaToLoad);
            }
        }
    }

    private void OnTriggerEnter2D(Collider2D other)
    {
        if(other.tag == "Player")
        {
            //SceneManager.LoadScene(areaToLoad);
            shouldLoadAfterFade = true;
            GameManager.instance.fadingBetweenAreas = true;

            UIFade.instance.FadeToBlack();

            PlayerController.instance.areaTransitionName = areaTransitionName;
        }
    }

Area Entrance:

    void Start () {
        if(transitionName == PlayerController.instance.areaTransitionName)
        {
            PlayerController.instance.transform.position = transform.position;
        }

        UIFade.instance.FadeFromBlack();
        GameManager.instance.fadingBetweenAreas = false;
    }
rich adder
old ibex
#

I have tested it out before and it works, nothing breaking

#

Now its giving me an issue for some reason

rich adder
#

before what ?

old ibex
#

Before I had the other issue of the Transform being destroyed

lusty flax
#

i'm trying to make it so my spikes in my game are placed in a grid-like way (easily). can I achieve this using a gridmap? whenever I try to set the pixels per unit, it doesn't work as the image's x and y scale isn't the same. how can i do this?

rich adder
old ibex
#

im not sure how to fix it, and its probably why everything else is not working

rich adder
#

ur probably referencing a different screen then

#

not sure

rich adder
# old ibex

dont think this warning would affect the code you have

#

but still you should fix it, delete one of them

#

you mention DDOL somewhere earlier, its probably causing multiple issue if you have no disposed the other properly

old ibex
#

Oh my bad sorry

#

I just realized it is one of my prefabs

heady wyvern
#

Can anyone assist me

#

so heres my issue

#

im creating a 3d game but using some 2D Sprites as char and monsters ect..

#

im following a guide and so i had everything all good

#

but now when i move "WASD"

#

i get these errors

#

and i added so when i click to attack it would target specific monsters

old ibex
heady wyvern
#

i get this when i click my target

old ibex
rich adder
#

I would suggest first debugging make sure the code is running there

#

put Debug.log inside your FadeOut method

old ibex
#

Ok I will try that out

heady wyvern
#

me ? @rich adder

#

lol

polar acorn
# heady wyvern

Something on that line is null but you're trying to use it anyway

rich adder
polar acorn
#

Find out what's null and make it not be that

heady wyvern
#

this is for clicking the target

rich adder
#

config your editor first

polar acorn
#

Also, !ide

eternal falconBOT
heady wyvern
#

do i download that

#

what you sent just now

#

im like a very beginner with this

polar acorn
#

So it shows errors and highlights syntax

quick pollen
#

Hey! Is this script okay for rotating towards an object on the y axis?

quick pollen
#

how can I fix it?

rich adder
#

also why are you making a quaternion like that

quick pollen
polar acorn
quick pollen
#

if I rotate on other axises, this happens

polar acorn
rich adder
#

I would go for the Coroutine option for lerp

summer stump
tribal axle
#

sorry for screenshot, but how do i acces this exact line of code in a different script?

quick pollen
quick pollen
#

most probably make an instance

north scroll
#

hey im having some issue here: Im trying to get the health var thats in the healthBar Script to match the bosses script health var, so im trying to get 2 files to access each other. This is how im trying to instantiate this and the Debug.Log prints out the Canvas name. This is how im trying to do the health reduction per hit on the oncollision (which has worked so far btw except without a UI),

if (other.gameObject.CompareTag("Bullet"))
{
    health--;
    healthScript.UpdateHealth(1);
    healthScript.currentHealth = health;

but i keep getting the error object reference not set on the UpdateHealth(1); line.

lost anvil
#

I have a door here that i want to play sounds when it starts moving and stop playing when it stops however im getting that reference error in the console and im not sure what to do.

polar acorn
tribal axle
polar acorn
#

The components are called x, y, z, w purely out of convention

polar acorn
lost anvil
# lost anvil I have a door here that i want to play sounds when it starts moving and stop pla...
public class DragDoor : MonoBehaviour
{
    AudioSource doorSound;
    public AudioClip[] doorClips;

    [SerializeField] Transform playerCamera;
    [SerializeField] Transform distanceCheck;
    [SerializeField] Transform hinge;

    [SerializeField] float moveSpeed;
    [SerializeField] Vector2 rotationContraints;

    bool movingDoor;
    float rotation;
    Vector3 targetPosition;

    // Start is called before the first frame update
    void Start()
    {
        targetPosition = distanceCheck.position;
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (Physics.Raycast(playerCamera.position, playerCamera.forward, out RaycastHit hit, 3f))
            {
                Debug.Log("pressed at door");
                if (hit.collider.CompareTag("Door"))
                {
                    movingDoor = true;
                }
            }

            if (movingDoor = true)
            {
                doorSound.Play();

                if (movingDoor = false)
                {
                    doorSound.Pause();
                }
            }
        }

        if (movingDoor)
        {
            if (Input.GetMouseButtonUp(0))
            {
                movingDoor = false;
            }
            targetPosition = playerCamera.position + playerCamera.forward * 2f;
        }

        rotation += Mathf.Clamp(-GetRotation() * 5000 * Time.deltaTime, -moveSpeed, moveSpeed);
        rotation = Mathf.Clamp(rotation, rotationContraints.x, rotationContraints.y);
        hinge.localRotation = Quaternion.Euler(0, rotation, 0);
    }
    float GetRotation()
    {
        float firstDistance = (distanceCheck.position - targetPosition).sqrMagnitude;
        hinge.Rotate(Vector3.up);
        float secondDistance = (distanceCheck.position - targetPosition).sqrMagnitude;
        hinge.Rotate(-Vector3.up);
        return secondDistance - firstDistance;
    }
}

quick pollen
polar acorn
quick pollen
#

tutorials tell you to use this hacky solution

#

like I looked into 4

#

and all 4 told me the same thing

#

to use this

#

I realized that the lerp approaches a value but never reaches it

polar acorn
quick pollen
#

but I never found a specific issue with that

polar acorn
#

Then you can just Slerp between them

polar acorn
tribal axle
polar acorn
#

Reference the instance of whatever script this variable is on

quick pollen
polar acorn
polar acorn
quick pollen
#

I meant like a constraint monobehaviour

polar acorn
quick pollen
tribal axle
north scroll
heady wyvern
#

@rich adder

north scroll
#

the global healthScript was not the one being set to during start

heady wyvern
#

im on #3 i dont see add button

summer stump
rich adder
quick pollen
#

I knew that im just stupid

#

its for bypassing the gimbal lock

#

right?

summer stump
#

No

quick pollen
#

I thought thats why quaternions are used

sage thunder
#

I am trying to run a script on a mesh, but am getting the error that the mesh isReadable is false. It says to enable Read/Write on the import settings. I can do this, but then I have to redo a bunch of other stuff. Is there a way to enable Read/Write other than at import?

quick pollen
#

to fix gimbal lock issues

summer stump
quick pollen
#

ig its not for bypassing the gimbal lock it just helps with it while doing other stuff

#

while messing around with constructing that quaternion I did stumble upon some atrocities

summer stump
#

It's just a mathematical concept. You should not use it directly at all

quick pollen
#

and it usually was because of the w axis

summer stump
#

Again, w is not an axis. But I get what you mean

quick pollen
rich adder
# heady wyvern

it says its Under Add Modules
but you already have VS you have to check if you have the workload

quick pollen
summer stump
quick pollen
#

im just used to calling everything axis at this point

#

like its stupid how Vector3s already use xyz

#

even if you dont use it only for coordinates

#

tho tbf you do the same in maths soo

#

but when I think of a Vector I think of an Array kinda

#

i know its not the same but it heavily reminds me of it

#

I suppose I can try using MoveTowards

#

I just don't quite get how it works yet

teal viper
#

Must be having a C++ mindset...

quick pollen
#

in school we do c++

#

and it can mess me up so bad

#

also, if I set maxDistanceDelta to 0, does that mean that the object would rotate to target without moving?

tulip hill
#

i am completely new to unity, is transform written as a class? i see it like transform.rotate and im wondering if it has the same capabilities as a normal class

quick pollen
#

its the situational values of something

#

i cant say position actually

#

more like coordinates and such

tulip hill
#

oh alr

quick pollen
#

where it is, how its rotated, what scale it has

#

wait

#

are we talking about Transform or transform

heady wyvern
#

is this right now

quick pollen
#

sorry ill shut up

#

im being stupid

lost anvil
# lost anvil ``` public class DragDoor : MonoBehaviour { AudioSource doorSound; publi...

^ updated code, still doesnt work

{
    AudioSource doorSound;
    public AudioClip[] doorClips;

    [SerializeField] Transform playerCamera;
    [SerializeField] Transform distanceCheck;
    [SerializeField] Transform hinge;

    [SerializeField] float moveSpeed;
    [SerializeField] Vector2 rotationContraints;

    bool movingDoor;
    float rotation;
    Vector3 targetPosition;

    void Start()
    {
        targetPosition = distanceCheck.position;
    }

    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (Physics.Raycast(playerCamera.position, playerCamera.forward, out RaycastHit hit, 3f))
            {
                Debug.Log("pressed at door");
                if (hit.collider.CompareTag("Door"))
                {
                    movingDoor = true;
                    PlaySound();
                }
            }
        }

        if (movingDoor)
        {
            if (Input.GetMouseButtonUp(0))
            {
                movingDoor = false;
            }
            targetPosition = playerCamera.position + playerCamera.forward * 2f;
        }

        rotation += Mathf.Clamp(-GetRotation() * 5000 * Time.deltaTime, -moveSpeed, moveSpeed);
        rotation = Mathf.Clamp(rotation, rotationContraints.x, rotationContraints.y);
        hinge.localRotation = Quaternion.Euler(0, rotation, 0);
    }
    float GetRotation()
    {
        float firstDistance = (distanceCheck.position - targetPosition).sqrMagnitude;
        hinge.Rotate(Vector3.up);
        float secondDistance = (distanceCheck.position - targetPosition).sqrMagnitude;
        hinge.Rotate(-Vector3.up);
        return secondDistance - firstDistance;
    }

    void PlaySound()
    {
        if (movingDoor = true)
        {
            doorSound.Play();

            if (movingDoor = false)
            {
                doorSound.Pause();
            }
        }
    }
}

heady wyvern
#

im confused as hell

#

lol

rich adder
quick pollen
#

also @teal viper what if I use LookAt?

heady wyvern
teal viper
heady wyvern
#

yeah i did for VS

#

when i first downloaded it

rich adder
#

setup unity external tools, click regen project files there if you have set it already

teal viper
quick pollen
quick pollen
#

okay

#

I misunderstood it

rich adder
quick pollen
#

its Vector3 not transform

buoyant knot
#

then I can instance a second Mathf

static bay
buoyant knot
#

and then I can check if the first Mathf .Equals the second

#

and then put them in a big List<Mathf>

teal viper
static bay
quick pollen
#

but not quite

buoyant knot
#

And then define extension methods as
public static Mathf CombineMath(this Mathf first, Mathf second)

quick pollen
#

ill try using movetowards

teal viper
buoyant knot
#

then at some point, I can make a List<Tuple<Mathf, float>>, so i can effectively store a list of floats, with the relevant Mathf instance I should use for it

#

i can make the most cursed code ever

quick pollen
# teal viper Well, that I don't know. Share the new code.

public class RotateToPlayer : MonoBehaviour
{
    public Transform target;
    public float RotationSpeed;
    private Vector3 _direction;
    void Update()
    {
        _direction = (target.position - transform.position).normalized;
        transform.rotation = Vector3.MoveTowards(transform.rotation, _direction, RotationSpeed);
    }
}```
I wanted something like this
#

but idk how to turn transform.rotation into a vector3

teal viper
rocky canyon
#

it is a vector

#

ohh euler

quick pollen
#

MoveTowards is a vector3

rocky canyon
#

Euler angles is what ur wanting i think

teal viper
quick pollen
#

i thought of it but it doesnt work

quick pollen
teal viper
#

It's a method in Vector3. But there is a similar method in quaternion too

#

Check the docs.

quick pollen
#

ah

#

theres Quaternion.LookRotation

#

which I know of

teal viper
#

Not that

quick pollen
#

then?

teal viper
#

Read through the available methods

quick pollen
#

FromToRotation?

teal viper
#

Specifically the static ones

#

No

quick pollen
#

I was thinking slerp but thats not it either

#

RotateTowards?

teal viper
#

Yes

quick pollen
#

but that doesnt have-

#

oh it does

#

wtf

tulip hill
#

how do i detect inputs on unity code

quartz grove
#

.ide

#

-ide

#

!ide

eternal falconBOT
rich adder
quick pollen
tulip hill
#

idk

quick pollen
#
public class RotateToPlayer : MonoBehaviour
{
    public Transform target;
    public float RotationSpeed;
    private Vector3 _direction;
    void Update()
    {
        _direction = (target.position - transform.position).normalized;
        transform.rotation = Quaternion.RotateTowards(transform.rotation, _direction, RotationSpeed);
    }
}```
soft steppe
#

Hi, so currently im following brackey's first Person Movement tutorial and i hit a problem when trying to implement camera rotation on the x axis it simply blocks rotation on y axis ( the problem may be due to me using the Input System and the tutorial using the legacy input system but i am not sure )
here is the code im using:

public void look(InputAction.CallbackContext context)
{
    if (CanMoveCamera)
    {
        xRot -= context.ReadValue<Vector2>().y * mouseSensitivity * Time.deltaTime;

        xRot = Mathf.Clamp(xRot, -90f, 90f);

        transform.localRotation = Quaternion.Euler(xRot, 0f, 0f);


        transform.Rotate(Vector3.up * context.ReadValue<Vector2>().x * mouseSensitivity * Time.deltaTime);
    }
}

note: context.ReadValue<Vector2>() returns current pointer delta movement.

quick pollen
#

the problem is _direction

#

I need to turn it into a rotation/quaternion

#

Quaternion.Euler maybe?

tulip hill
#

is mouse1 lmb?

rich adder
#

also take beginner course instead of guessing

tulip hill
#

im looking at a tutorial

#

also it doesnt let me take the new to unity thing

summer stump
tulip hill
#

i dont see it anywhere

summer stump
quartz grove
#

Guys did everything here but still ide doesn't work

tulip hill
quartz grove
tulip hill
summer stump
tulip hill
#

alr

summer stump
eternal falconBOT
#

:teacher: Unity Learn ↗

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

rich adder
summer stump
#

Yeah, it's right here

quick pollen
quartz grove
#

!ide

eternal falconBOT
rich adder
quick pollen
#

ok not exactly Lua but some extension of it counts from 1 instead of 0

summer stump
# quick pollen Lua >.>

Yeah, I have made myself stop saying that is only a scripting language, but it IS still an obfuscation of what the computer is doing

quick pollen
#
using UnityEngine;

public class RotateToPlayer : MonoBehaviour
{
    public Transform target;
    public float RotationSpeed;
    private Vector3 _direction;
    void Update()
    {
        _direction = (target.position - transform.position).normalized;
        transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(_direction), RotationSpeed);
    }
}```
quartz grove
quick pollen
#

still doesnt work

#

idk how to

rich adder
#

you did not follow the guide

summer stump
rich adder
#

also I dont have time for this rn sorry

quartz grove
quartz grove
summer stump
teal viper
rich adder
# quartz grove : )

if its showing Internal A. you did not remove the VSCode editor package and B. did not update Visual Studio Editor package

teal viper
#

No. That's from an angle not a direction@quick pollen

heady wyvern
#

!ide

eternal falconBOT
teal viper
quartz grove
#

!ide

eternal falconBOT
quick pollen
#

LookRotation maybe?

rich adder
rocky canyon
#

its a quaternion, and it uses a direction.

#

will it work for ur use-case?

teal viper
quick pollen
# rocky canyon

except FromToRotation says this Usually you use this to rotate a transform so that one of its axes eg. the y-axis - follows a target direction toDirection in world space.

heady wyvern
#

is Visual Studio Editor what i needed? for !ide

eternal falconBOT
summer stump
summer stump
rich adder
#

jesus christ people today

summer stump
quartz grove
rich adder
quick pollen
heady wyvern
summer stump
#

Ah, Yeah I miswrote it earlier. Sorry

quick pollen
#

now I need to find a way to lock the rotation to the y axis

heady wyvern
#

after i delete that code one

summer stump
heady wyvern
#

lol

quick pollen
#

maybe I can create a new direction which is just _direction without the x and z?

heady wyvern
#

this guide is poop tbh

#

or im just stupid

quick pollen
summer stump
#

What have you done so far?

rich adder
teal viper
quick pollen
heady wyvern
#

😞

quick pollen
#

its rotated wrong

#

like its facing the ground

#

not me

quartz grove
quick pollen
teal viper
summer stump
rich adder
quick pollen
# teal viper Share code
public class RotateToPlayer : MonoBehaviour
{
    public Transform target;
    public float RotationSpeed;
    private Vector3 _direction;
    private Quaternion _rotation;
    void Update()
    {
        _direction = (target.position - transform.position).normalized;
        _rotation = Quaternion.LookRotation(new Vector3(0f, _direction.y, 0f));
        transform.rotation = Quaternion.RotateTowards(transform.rotation, _rotation, RotationSpeed);
    }
}```
#

actually

#

do I need to do the exact opposite

#

have x and z but not y

quartz grove
summer stump
rich adder
#

anyway i have no time to bicker with you

#

goodluck to ya

#

reading a step by step guide with screenshots isnt exactly coding or some sort of special science

quick pollen
#

yeah I was stupid

#

I meant to freeze the Y rotation

rocky canyon
#

get ur axis' straight! 😛

quick pollen
#

not unlock the Y rotation

quartz grove
summer stump
quick pollen
rocky canyon
#

it gets ezier

quick pollen
#

like I just cant remember what axis is what

#

especially x and z

summer stump
quick pollen
#

I know z is the forward axis

#

the blue

#

green is y

#

and red is x

heady wyvern
#

@summer stump i followed all the steps how do i know if i got .i.d.e to go correctly

quartz grove
quick pollen
#

but I mess it up so often when I have to rotate around them

summer stump
#

Maybe show a screenshot of the ide

summer stump
teal viper
quick pollen
#

tysm @teal viper @rocky canyon @summer stump and whoever else who helped :)

quartz grove
#

<@&502884371011731486>

quick pollen
#
using UnityEngine;

public class RotateToPlayer : MonoBehaviour
{
    public Transform target;
    public float RotationSpeed;
    private Vector3 _direction;
    private Quaternion _rotation;
    void Update()
    {
        _direction = (target.position - transform.position).normalized;
        _rotation = Quaternion.LookRotation(new Vector3(_direction.x, 0f, _direction.z));
        transform.rotation = Quaternion.RotateTowards(transform.rotation, _rotation, RotationSpeed);
    }
}
#

final thing

#

and thank u @teal viper especially for giving me hints and not an exact solution

#

did take more time but at least I'll (hopefully) make shitty mistakes like this less often

#

its like 3 am

#

its especially hard to think right rn

north kiln
#

@quartz grove Stop yabbering. If someone tells you to stop spamming the command, respond nicely instead of arguing. It's not hard to scroll up or reopen a webpage, and that's all that's being asked of you.

quartz grove
#

I see that there is bias in the administration

quick pollen
#

(i suck at animations pls ignore)

north kiln
#

@rich adder don't swear at people when you want them to stop. You can keep things polite too.

rich adder
#

You're right . My Apologies

shell sorrel
#

because are trying to instigate things, it looks like the kid "yelling i am not touching you" with there hands up in someone's face

quartz grove
heady wyvern
quick pollen
summer stump
quartz grove
quick pollen
#

(i say that but im immature anyway lol)

summer stump
quick pollen
#

but especially when ur receiving help

#

and people are spending their time on u

quartz grove
quick pollen
#

if someone is being impolite with you irl for no reason

#

then yes

quartz grove
quick pollen
#

you have the "right" to be impolite in return, but its better to walk away

quick pollen
robust moss
#

hey y'all

quick pollen
#

hi

robust moss
#

currently working on a couple projects for various beginner level understanding, and I'm wondering if there's any websites for learning unity.
I've already found docs.unity.com and learn.unity.com, but I'm curious about other websites, just to know the different options

summer stump
robust moss
#

sweet, thanks

oak mist
#

Code: https://pastebin.com/EeP4H6Xy, I have a question on positioning. Basically ive almost solved my issue and im almost done. I have a turret which operates on a spaceship, and only moves left and right (well rotates left and right), and it took me a while but i got it running. Which is fine when the ship is moving forward and backwards, or left and right, but for up and down, the ship stays at its rotation and doesnt rotate up, so it glitches into the cockpit and looks a little odd. Any workaround for this?

#

once this is done i can call it a day and finally rest easy.

wintry quarry
#

That will easily let you enforce limitations on the object's rotation relative to the parent (the ship)

oak mist
#

beautiful

#

hold on let me try

wintry quarry
#

It will take some fiddling

oak mist
#

so would i have to also change the Move towards angle also

wintry quarry
#

I mean yeah just do everything in local space

#

Also recommend maintaining your own variable for the rotation rather than reading the euler angles from the transform

oak mist
#

perfect

#

its done

#

finally

#

i can sleep

#

thank you so much ur a lifesaver

heady wyvern
#

If anyone can help i cant get i.d.e because im not sure if i need to buy VS or what but some options are missing. anyways in my game i use WASD to move and when i move i get these errors

#

thats the code on the right it pulls me to when i double click the errors

rich adder
heady wyvern
rich adder
summer stump
summer stump
# heady wyvern

Your error is because the attackRoutine isn't set to anything when you call StopCoroutine

ashen trail
#

IDE setup is not working for me

summer stump
ashen trail
summer stump
ashen trail
#

mb

heady wyvern
#

@summer stump @rich adder sorry for asking so much this is very new to me so again sorry lol

rich adder
#

seems you dont have the SDK but only runtimes

summer stump
rich adder
#

not sure tbh lol but I think so since it kinda code topics

heady wyvern
rich adder
#

well there is your answer

#

Visual Studio isnt even selected!

summer stump
#

It would have been the step in the guide where you set the tool used by unity

rocky canyon
rich adder
#

^ make sure you regen after that

heady wyvern
#

regen

#

ok

#

do i select any other boxes on that?

#

or good to go

rich adder
#

should be fine

rocky canyon
#

double click one of ur scripts

#

ull find out

rich adder
#

make sure u close vs though when u regen

rocky canyon
#

you'll see Assembly-CSharp when its good

heady wyvern
rocky canyon
#

aye 🎉

#

your life is now atleast 3x better

heady wyvern
#

lol

#

ok so i see

#

1 asset referenced 0 refferences

shell sorrel
#

means 0 references in code

#

1 asset with the component on it

rich adder
#

yes You are not referencing this script anywhere

rocky canyon
#

peek-a-boo

rich adder
#

^^ these are runtime errors and do not show up in IDE @heady wyvern

#

btw Update is a Unity callback so it gets autocalled so no References there

shell sorrel
#

yeah the ide will tell you about compile errors

#

NRE is runtime error, not knowen till that code that casues it executes

#

assuming player is null, and not assinged in the inspector

#

but the error in the console will have a stack trace to show you where

heady wyvern
#

so as in a "Refrencing" the script thats like adding a component - script onto a object?

#

like my "Target"

#

or referencing it in the script itself

rocky canyon
#

if you say public GameManager myGameManager; and put that script onto an object

#

u have to fill in the newly made slot for a GameManager

#

if u go to run that script and its not referenced.. theres ur error

summer stump
rocky canyon
#

^ this would be a reference to Apple.cs

summer stump
#

And the thing you do in the script itself is declare a variable, then you reference it, either with the = sign, or like spawn camp is showing

rich adder
#

You know which book and which page you want to find specific info

rocky canyon
#

think of it like a pointer..

summer stump
#

public GameManager gameManager

^ this is a declaration, NOT a reference until you actually fill the variable with something.
It is "null" by default

rocky canyon
#

to which specific Instance of that class ur trying to reference

rich adder
#

also valid 😛 i tried a simpler more relatable analogy

rocky canyon
#

he may have figured it out by now 😅

summer stump
rocky canyon
#

oh bam, there u go ^

rocky canyon
summer stump
rocky canyon
#

he's already building the menu by now

summer stump
rich adder
#

game already has 20k steam wishlisting

rocky canyon
#

i got whats the coders version of writers block? or it could be just procrastination

#

not sure where to go on my project

heady wyvern
#

lmfao

rich adder
# rocky canyon not sure where to go on my project

i usually try to learn something new and give the mind a break from the same thing
eg if you're constantly working on gameplay features, work on the menus? music? the artwork ? or maybe some unrelated (kinda)

shell sorrel
#

its just procrastination

#

yeah there is always something to do, but games covers alot of domains so its easy to change things up

heady wyvern
#

so wouldnt this be like your apple GIF @rocky canyon

shell sorrel
#

or easy to working on something a little more mindless if your head is not in it

rocky canyon
#

yup, ur private Player.. is visible in the inspector b/c of the [SerializedField] attribute u used..

summer stump
# heady wyvern

You have successfully referenced an instance of the player script

rocky canyon
#

so in that case you pull in the gameobject that has the Player script on it

rich adder
#

step 1/2
step 2# make sure its assigned

rocky canyon
#

and when u run any code referencing that player.. it'll know which gameobject has that player script

#

👍

#

i have lots more faith in you than some i see around here 🙂

summer stump
rich adder
rocky canyon
#

yea, it looks good.. no console errors.. it has a reference.. the player script has a MyTarget variable..

shell sorrel
#

yeah its assigned, though in the code i would null check the collider on the hit, to make sure you got a hit

rich adder
#

btw you I think you could get a null ref if hit.collider is null since you're accessing a tag on collider

rocky canyon
#

if that variable is public (can be accessed in ur GameManager script) ur solid

rich adder
#

Debug.Log just prints the result

summer stump
heady wyvern
heady wyvern
rich adder
heady wyvern
rich adder
#

no not like this lol

#

.tag is trying to access collider and if no collider is found, it will throw NRE anyway. You cannot run .tag on a null object

summer stump
rich adder
#

and for tag checking you should use collider.CompareTag instead of == btw

rocky canyon
#

..and wrap ur raycast in an if statement and then u wont have to worry about null tags when theres no hit variable

rich adder
#

is there a bool version return version?

#

for 2D

rocky canyon
rich adder
#

don't think 2D has it

rocky canyon
#

i meant like this.. but ur right.. i know nothing about 2d raycasts

#

thats odd that u cant

rich adder
rocky canyon
#

weird.. why not i wonder.. im sure its been ticketed/requested

#

or maybe im tripping

heady wyvern
#

im creating 3D

rich adder
heady wyvern
#

i put 3d and it doesnt work lol

rich adder
#

wdym doesn't work

#

are the colliders 3D or 2D?

heady wyvern
#

i tried both 3d and 2d

summer stump
rich adder
summer stump
#

So Physics or Physics2D

rich adder
#

and dont randomly change stuff without knowing why

summer stump
#

Collider or Collider2D

heady wyvern
#

i mean colliders

leaden dove
#

anyone good at c# sharp?

heady wyvern
#

i tried both regular collider and 2d

leaden dove
#

im making a game with some people we need coders lol

rich adder
eternal falconBOT
heady wyvern
#

but if i do raycast3d

summer stump
#

Raycast

leaden dove
summer stump
#

No 3d at the end

rich adder
heady wyvern
#

ah shit

#

i meant

rich adder
#

Physics3D isn't a class

#

dont just randomly guess

summer stump
#

ONLY 2d has it explicitly written

rich adder
summer stump
#

There is nothing that ends in 3d afaik

rich adder
#

first result

#

Unity is a 3D engine, usually everything 2D has suffix

#

Light2D or w/e

#

etc

north kiln
#

Random note, RaycastHit2D has an implicit cast to bool that checks the collider

lusty girder
#

hi, how do you rotate a gameobject to face towards a cube's corner?
(the screenshot shows an invisible capsule outlined in green, which i am trying to rotate to face the corner)
i have script attempting this, but i just want to know how to do it in general:

using System.Collections.Generic;
using UnityEngine;

public class raycastMove : MonoBehaviour
{
    public GameObject bigCube;
    public GameObject playerCapsule;

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

    // Update is called once per frame
    void Update()
    {
            //draw ray in playercapsule's forward direction
            Debug.DrawRay(playerCapsule.transform.position, transform.forward, Color.white);


            //draw ray that collides with the cube's corner
            Debug.DrawRay(bigCube.transform.position - (transform.forward - transform.right).normalized, 
                          (transform.forward - transform.right).normalized, 
                          Color.blue);


            RaycastHit outCornerAngleHit;
            if (Physics.Raycast(bigCube.transform.position - (transform.forward - transform.right).normalized, 
                                (transform.forward - transform.right).normalized, 
                                out outCornerAngleHit, 
                                30f))
            {
                //Move playercapsule to cube's corner
                playerCapsule.transform.position = outCornerAngleHit.point;
                //Rotate playercapsule towards where cube's corner was hit
                playerCapsule.transform.rotation = Quaternion.RotateTowards(playerCapsule.transform.rotation, Quaternion.LookRotation(-outCornerAngleHit.normal), 3600);
            }
    }
}```
rich adder
#

that makes lot of sense, I was gonna say why wouldn't they have a bool option 😂

#

TIL

leaden dove
rich adder
#

oh wellOP is using 3D colliders anyway

rich adder
leaden dove
#

idrc

rich adder
leaden dove
#

i was just asking a question he didnt have to link that

rich adder
#

your question wasn't clear on why you are asking who can code..

#

its perfect fit , did you even read it?

summer stump
leaden dove
#

this server is annoying af

north kiln
rich adder
#

👋

summer stump
rich adder
#

blocked already

north kiln
rich adder
#

Sorry ok

lusty girder