#๐Ÿ’ปโ”ƒcode-beginner

1 messages ยท Page 160 of 1

tepid summit
#

ive tried everyhting

hexed terrace
#

What?

tepid summit
#

oh

hexed terrace
#

Try reading this? ๐Ÿ˜„

tepid summit
#

i misread

#

my bad

#

i thought it said i cant do CoilyBoily =GetComponent

#

sorry

#

ok so the errors are gone,

#

but when i assign this it resets to none on play

rich adder
#

if its not found it sets it to null

#

anything done in inspector gets overwritten by it

tepid summit
#

but it has the script on it

#

so idk why it resets

hexed terrace
#

Showeth

tepid summit
#

showeth what

#

my script

hexed terrace
tepid summit
hexed terrace
tepid summit
#

wdym

hexed terrace
#

I mean what I said, which bit don't you understand?

rich adder
hexed terrace
#

You have 2 game objects.

The component looking for CoillyBoily is on a different game object than CB .. so cannot find it.. which means โ˜๏ธ

tepid summit
#

right

hexed terrace
#

If you're assigning something in the inspector, why do you think you need to do GetComponent<T>() ?
You don't, do you?

#

Do one or the other, not both

tepid summit
#

ok

#

thast good

#

but the script itself isnt working now

#

basically i have an object that moves to the player and i want it so when the player looks at said object, it stops

rich adder
#

that helps nothing

tepid summit
rich adder
tepid summit
#

I did

#

Oh wait

rich adder
#

no

hexed terrace
#

if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity, layerMask))

A raycast is a tiny line, so you'd have to have it directly hit

tepid summit
#

Well I gtg for tonight so Iโ€™ll do it tmr

rich adder
#

I believe CoilyBoily is the one with the movement ?

#

i don't see the ray doing much besides canMove on CoilyBoily

hexed terrace
#

gotta check if the ray is hitting, as well as what's happening in CB

#

But he's gone now , so meh

rich adder
#

yea true

lavish gate
#
        if (otherFruit.fruitType != fruitType)
        {
            if (otherFruit.special_isSticky == true) return;
            if (special_isSticky == true)
            {
                if (numOfSticks > 0) return;
                stickFruitTogether(otherFruit);
                return;
            }
            else return;
        } ``` anyway to refactor this to make it look cleaner?
gaunt ice
#
if (otherFruit.special_isSticky == true){}
else if (special_isSticky == true&&numOfSticks<=0){
  stickFruitTogether(otherFruit);
}
return;
====================>
if (otherFruit.special_isSticky==false&&special_isSticky == true&&numOfSticks<=0){
  stickFruitTogether(otherFruit);
}
return;
fossil drum
slender bridge
#

that is better

gaunt ice
#

you cant early return in first if

#

you dont need if there other codes below it

lavish gate
#

Yeah sorry there is code below

#
void HandleFruitCombination(Collision2D collision)
    {
        if (justSpawned || hasBeenTouched) return;


        FruitCombiner otherFruit = collision.gameObject.GetComponent<FruitCombiner>();

        //fix this mess
        if (otherFruit == null)
        { 
            if(special_isSticky && collision.) numOfSticks= 0;
            return;
        }
        if (otherFruit.fruitType != fruitType)
        {
            if (otherFruit.special_isSticky == true) return;
            if (special_isSticky == true)
            {
                if (numOfSticks > 0) return;
                stickFruitTogether(otherFruit);
                return;
            }
            else return;
        } 

        hasBeenTouched = true;

        Vector2 midPoint = FindMidPoint(transform.position, otherFruit.gameObject.transform.position);

        AddForceToSurroundingFruits(midPoint);

        if (nextFruitPrefab == null) return;

        if (hasSpawnedObject == true)
        {
            hasSpawnedObject = false;
            otherFruit.hasSpawnedObject = false;
            return;
        }

        Combine(midPoint, otherFruit);
    }```
#

heres the whole method

#

most is irrelevant

fossil drum
#

Well then just add a curly brace with an indent on the first if.

#
        if (otherFruit.fruitType != fruitType) {
            if (otherFruit.special_isSticky) return;
            if (special_isSticky && numOfSticks <= 0)
                stickFruitTogether(otherFruit);
            return;
        }

Still seems cleaner then your version.

lavish gate
#

yup

terse osprey
#

Hey I am using an integer for my array called index but it does not let me set it to 0 and tells that int cant be converted into bool

buoyant knot
#

show code

gaunt ice
#

is your array bool[]

terse osprey
gaunt ice
#

ok, then the way of accessing it

terse osprey
#

nvm I was being dumb, I fixed it

faint osprey
#

i have a list of lists of ints public List<List<int>> roomMatrix = new List<List<int>> { new List<int> {-1, -1, -1}, new List<int> {-1, -1, -1}, new List<int> {-1, -1, -1} }; and an array of gameobjects i need to make a loop that will check every index of the list of list of ints and if its 0 or above change that index in the list of list as in the array to something else so for example if the top left index was 0 or above the 0th term in the array would change then if the top middle was 0 or above the 1st element would change and so on but i dont know how i would compute this

timber tide
#

just compare each increment?

faint osprey
timber tide
#

read this, am lost, made coffee and read again, still lost

#

maybe draw something out cause I can't figureout the exact requirements here

#

but unless you need some sort of sorting, you're just doing some comparison on value changes between neighbors

faint osprey
#

I dont need sorting its the point of tho how can i do it without 9 if statements

cursive viper
#

In a multiplayer basketball type game would it make more sense to house the script that handles picking the ball up and throwing it within the player object or a game manager object??

wintry quarry
sweet flume
#

I'm trying to make a sword swing animation play when I press lmb can someone tell me what's wrong?

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

gaunt ice
#

in real life, the ball is picked up by player not by the judge or other audience....

cursive viper
#

so then should I use a reference to pick up the ball or a game event?

terse osprey
#

Hey is there any way to change the index of objects in an array

wintry quarry
wintry quarry
#

You use references for almost everything in some form or another

#

Presumably you'd use a Raycast or other physics interaction or query

sweet flume
wintry quarry
#

Iin order to get a reference

rich adder
sweet flume
wintry quarry
rich adder
wintry quarry
sweet flume
#

I'm getting "๐Ÿฆ—๐Ÿฆ—๐Ÿฆ—"

#

What's happening is when I press lmb the attack trigger doesn't trigger

thorn holly
rich adder
thorn holly
modest dust
cursive viper
#

this is real simple but I forgot how to do it if I have a number inside a vector like new Vector3(0, 0, 1.2) how can I make the 1.2 a double so it works

sweet flume
cursive viper
#

I thought it was double[1.2] or something like that

cursive viper
#

nah thats a float

modest dust
#

Oh yeah

#

I misread that

cursive viper
#

and if you do 1.2d it doesn't work

modest dust
#

1.2 is double

#

1.2f is float

cursive viper
#

apparently not

#

it's saying I can't put 1.2 there because you can't put a float in a vector3

rich adder
modest dust
#

not a double

wintry quarry
cursive viper
#

??? I just tried float and it didn't work

#

let me try again

wintry quarry
#

Prove it

cursive viper
#

nevermind I misread the error lmao

sweet flume
rich adder
cursive viper
#

I thought you could multiply vector3s whats the correct way to add value to a vector3 if you cant add or multiply them? I haven't done this in a while if its not obvious

rich adder
wintry quarry
#

You can also multiply them in 3 different ways

sweet flume
gaunt ice
#

you can add vec3 with vec3 and multiply it with float

cursive viper
#

I swear my vs gotta be tripping cuz i tried to add and it didn't work

#

watch me try it again and it works and I look stupid lol

wintry quarry
#

.Scale, .Dot, and .Cross are all ways to "multiply" vectors

gaunt ice
#

vec3 * vec3 is not defined in mathematics

rich adder
#

also make sure its the UnityEngine class one?

gaunt ice
#

there is no such thing

rich adder
#

assuming your saying the truth about ide @cursive viper

wintry quarry
cursive viper
#

I thought a transform was a vector3

gaunt ice
#

cross product dot (inner) product is not multiplication to me, they have a different name at least

rich adder
wintry quarry
modest dust
# sweet flume Yes but why

Did you put a debug at the beginning of Update() to check if that's running?
Also check your CanAttack bool in the inspector since it's public and might be set to false so it never goes inside if (CanAttack) and thus it doesn't check your lmb

rich adder
#

oh yeah check this ^

rich adder
#

oh nvm thats wrapped inside Input

sweet flume
#

Ok I just realized I'm stupid

#

I forgot to add the c sharp code to my sword ๐Ÿ˜

modest dust
rich adder
#

thats why we said check if its running lol

modest dust
#

I had that possibility in mind but I was like "no way that's the problem.."

rich adder
#

had a confirmation once the debug inside Input Didnt work

#

Input always runs

sweet flume
#

Everything is good now

#

Ty guys

opaque cloak
rare basin
#

then it must be the case

#

you are using the spriteRenderer before getting a reference to it

rich adder
#

also use an array lol

rare basin
#

yes, also this

opaque cloak
#

thanks

rare basin
#

imagine you having 15 sprites

#

new4Sprite, new5Sprite

#

also you can just make it a coroutine

#
    IEnumerator Start()
    {
        spriteRenderer = GetComponent<SpriteRenderer>();
        spriteRenderer.enabled = true;
        spriteRenderer.sprite = newSprite;
        yield return new WaitForSeconds(1);
        spriteRenderer.sprite = new2Sprite;
        yield return new WaitForSeconds(1);
        spriteRenderer.sprite = new3Sprite;
         yield return new WaitForSeconds(1);
        spriteRenderer.enabled = false;
    }
gaunt harbor
#

I don't understand anything at all because when I change the code from Raycast to SphereCast and it gives me errors but according to the page they say that it is the same, I mean it can be linked with another similar cast code


if (Physics.Raycast(Cam.transform.position, Cam.transform.TransformDirection(Vector3.forward), out hit, Range) && hit.transform.tag == "Enemy")
gaunt ice
#

*you dont to new a waitforsecond, you can reuse the instance

rare basin
queen adder
#

what's stopping us from using yaml to save the whole scene thingy?

rich adder
#

the scene file is a yaml wdym?

queen adder
#

save the game progress, using it

queen adder
#

is unity just not giving us the tool to to save the whole scene?

hexed terrace
#

ctrl+s

file -> save

gaunt ice
queen adder
#

yea, if we can do that in runtime,it's an impressive save system already

hexed terrace
#

because what states do you want saving at runtime?
Do you want your player position saved where it is? etc.. That could cause problems?

gaunt ice
#

save scene in play mode?
when you open your editor it is in its run time...

rich adder
# opaque cloak thanks

yeah that Task.Delay doesn't do anything lol since you did not make the method async.
Also awake has async version but not Start

#

but like Xaxup suggested use a Coroutine as Start

queen adder
#

awake can async?

rich adder
#

indeed

gaunt harbor
# rich adder whats error say ?

argument 4 must be passed with the 'out' keyword

argument 3 should not be passed with the 'out' keyword

argument cannot be converted from unityengine.vector3 to float

I don't know what happens but if it is installed with raycast there are no errors, but I want to change to Spherecast and I don't understand why it gives errors if they are the same with raycast :- /

rich adder
#

the direction is passed as third param

#

or make a ray with the 2 you have

#

var ray = new Ray(Cam.transform.position, Cam.transform.forward)

short perch
#

why does my gameobject detect collisions even though I never pressed "Is Trigger" anywhere?

short perch
rich adder
wintry quarry
#

In what specific sense?

short perch
rich adder
#

yeah your question isn't clear

wintry quarry
cursive viper
#
public class BallFondling : MonoBehaviour
{
    public KeyCode grab = KeyCode.E;
    public Transform ball;
    public Transform cam;

    private void FixedUpdate()
    {
        Vector3 fwd = cam.TransformDirection(Vector3.forward);

        if (Physics.Raycast(cam.position, fwd, 5, 30) && Input.GetKeyDown(grab))
        {
            Debug.DrawRay(cam.position, fwd, Color.green, 10);
            ball.position = new Vector3(transform.position.x, transform.position.y, transform.position.z + .5f);
        }
    }
}

anyone know why this code is not doing as intended? it is meant to place the ball in front of you when you look at it and grab it with "e". Tried asking chatgpt which didn't give any helpful info

#

I know there's probably a better way to do this too so if anyone has any input on that itd be appreciated as well

rich adder
#

getkeydown inside physics update ๐Ÿ˜ฌ

#

goodluck catching that

short perch
cursive viper
#

would it be better to store the boolean in update and then use it in fixedupdate if that makes sense?

gaunt ice
#

yes, you need to do that

cursive viper
#

ok bet lemme do that rq

dusty coral
#

how to select this collider?

hexed terrace
#

If you're getting trigger enter, then one of the two colliders is a trigger.

wintry quarry
#

Debug.Log the name of the object you're interacting with, and check the inspectors of both objects

short perch
#

BRUH I used on collision enter instead of on trigger enter

cursive viper
# rich adder yes
public KeyCode grab = KeyCode.E;
public Transform ball;
public Transform cam;
public bool grabPressed;

private void Update()
{
    if (Input.GetKeyDown(grab))
    {
        grabPressed = true;
    } else
    {
        grabPressed = false;
    }
}
private void FixedUpdate()
{
    Vector3 fwd = cam.TransformDirection(Vector3.forward);

    if (Physics.Raycast(cam.position, fwd, 5, 30) && grabPressed)
    {
        Debug.DrawRay(cam.position, fwd, Color.green, 10);
        ball.position = new Vector3(transform.position.x, transform.position.y, transform.position.z + .5f);
    }
}
#

changed to this and still doesn't work

wintry quarry
#

and put grabPressed = false; at the end of FixedUpdate

cursive viper
#

ohhh right because then it will turn it to false every frame even before the code inside the if in fixedupdate is executed right?

#

still doesn't work

rich adder
#

ur layermask is prob wrong

gaunt harbor
cursive viper
#

I have ball at layer 30 and using layer 30 in the code

rich adder
#

those layers aren't the same

#

that won't work, use a layermask
public LayerMask layerToHit;

cursive viper
#

except I replace mask to whatever I want it to be called?

summer stump
rich adder
#

more info herehttps://unity.huh.how/bitmasks#bitmasks-and-layermasks

gaunt harbor
hexed terrace
#

Have you shared your spherecast code?

rich adder
#

also use your IDE to make sure its the correct ones

#

if IDE doesn't show those param suggestions, configure it

gaunt harbor
quaint flicker
#

I keep coming here with generic open questions. I'm coming from python where "There should be one-- and preferably only one --obvious way to do it." so I keep getting hung up on a multiple ways to implement things in csharp and I don't have much intuition what the "best" way is. I'm extending my sfx manager to be able to play spatial audio and optionally parent the audiosource to a moving object would you:

  • Have one Play() method with optional parameters?
  • Have 3 Play() overloads with different params?
  • Have 3 different explicit Play, PlayAtPoint, PlayAtTransform?
rich adder
#

thats your raycast code

hexed terrace
#

That quite clearly says..... Raycast

gaunt harbor
#

ยฟDo I share the full code?

gaunt ice
#

why you think you can simply replace "Raycast" to "SphereCast" (literally replace the text) without changing the parameters....

cursive viper
#

and itd be better to do that then

public LayerMask layerToHit = LayerMask.GetMask("Ball");
gaunt harbor
#

I don't know what I'm doing wrong : /

rich adder
#

your ide is clearly not configured

rich adder
open apex
#

FindObjectOfType<GameManager>();
Can anyone explain me the logic behind this code please? Why do we put "()" Brackets at the end of the code? and can't we use the brackets instead of "<>"?

polar acorn
rich adder
gaunt ice
#

this is c# syntax

open apex
#

What is the difference of it and GetComponent?

rich adder
#

signature is public static T FindObjectOfType();

rich adder
polar acorn
#

They do different things but the syntax is the same

#

Both take a type and no function parameters

cursive viper
#

ok so I got it to work but now the ball starts absolutely tweaking

#
if (ballGrabbed)
{
    ball.position = new Vector3(transform.position.x, transform.position.y, transform.position.z + 1.5f);
}
timber tide
open apex
#

I am a bit lazy (I might not want to read the 2 pages you guys sent me) ๐Ÿ˜” What is the difference?

rich adder
cursive viper
rich adder
cursive viper
#

I checked that but the balls is quite far from the player

#

yeah I figured there was a better way than using the ball.position and transform.position

wintry quarry
rich adder
#

also is that ball inside layerToHit

modest dust
rich adder
#

cause if it is it will keep spazzing out also

cursive viper
#

whats the physics part? if im just changing the position of the ball to the position of the player with a 1.5 added to the z

cursive viper
rich adder
polar acorn
rich adder
#

but also if you're using rigidbody on ball you want to not use transform.position

cursive viper
#
if (Physics.Raycast(cam.position, fwd, 5, layerToHit) && grabPressed)
{
    Debug.DrawRay(cam.position, fwd, Color.green, 10);
    ballGrabbed = true;
    grabPressed = false;
}
#

it needs to be in the layertohit

rich adder
swift crag
open apex
cursive viper
# rich adder you want to ball to be hit or are you hitting something else?

hold on let me post the entire script that will probably help

private void Start()
{
    layerToHit = LayerMask.GetMask("Ball");
}

private void Update()
{
    if (Input.GetKeyDown(grab))
    {
        grabPressed = true;
    }
}
private void FixedUpdate()
{
    Vector3 fwd = cam.TransformDirection(Vector3.forward);
    if (ballGrabbed)
    {
        ball.position = new Vector3(transform.position.x, transform.position.y, transform.position.z + 1.5f);
    }
    
    if (Physics.Raycast(cam.position, fwd, 5, layerToHit) && grabPressed)
    {
        Debug.DrawRay(cam.position, fwd, Color.green, 10);
        ballGrabbed = true;
        grabPressed = false;
    }
}
rich adder
rare basin
#
  float currentTime = timer.currentTime;
  int minutes = Mathf.FloorToInt(currentTime / 60);
  int seconds = Mathf.FloorToInt(currentTime % 60);
  int milliseconds = Mathf.FloorToInt((currentTime - Mathf.Floor(currentTime)) * 1000);
  
  timeLeft.text = string.Format("{0:00}:{1:00}:{2:000}", minutes, seconds, milliseconds);

Anyone could help why are te miliseconds always displaying 000?

rich adder
open apex
rare basin
open apex
swift crag
swift crag
#

tangent: you might find TimeSpan to be useful here

rare basin
#

CeilToInt also returns 000

#

tried TimeSpan aswell

#

doesnt work

swift crag
#

it lets you specify a timespan and then format it to a string

cursive viper
rare basin
#

timeSpan.Milliseconds % 1000

#

or just timeSpan.Milliseconds

swift crag
#

is timer.currentTime actually including a decimal portion

rare basin
#

same result, always returns 000

polar acorn
cursive viper
rare basin
swift crag
#

or is it just giving you whole seconds

swift crag
#

that's not good enough.

rare basin
swift crag
#

so what?

#
float x = 3;
rich adder
polar acorn
swift crag
#

Actually check instead of just assuming

cursive viper
swift crag
#

you could do this by logging currentTime, or by inspecting with a debugger

rare basin
#

that might be the case, the timer is set to "900" in the inspector (15 minutes)

#

then im doing currentTime--; in a coroutine

#

every second

swift crag
#

well, there you go

#

of course it doesn't have decimal values

polar acorn
rare basin
#

right

polar acorn
#

You literally aren't tracking them

rare basin
#

makes sense ๐Ÿ˜„

#

can't do it in a coroutine then

#

alteast not with wait for seconds (1)

rich adder
polar acorn
#

If you want this to be updated every frame, why not just... update it every frame

#

subtract deltaTime in update

swift crag
#

that'll actually be more accurate

#

since subtracting 1 every time WaitForSeconds finishes will cause some wobble

rare basin
swift crag
#

it will actually take 1.03 or 1.01 or 1.02 or whatever seconds for that to finish

cursive viper
#

can you parent objects to other objects inside of a script?

polar acorn
cursive viper
#

lemme try that rq

rare basin
# polar acorn Do that _in update_ when the seconds value changes
private void Update()
{
    if (stopTimer == false)
    {
        currentTime -= Time.deltaTime;

        if (Mathf.Floor(currentTime) <= 5 && !isSecondElapsed)
        {
            lastSecondsPlayer.PlaySound();
            isSecondElapsed = true;
        }

        if (Mathf.Floor(currentTime) < currentTime)
        {
            isSecondElapsed = false;
        }

        if (Mathf.Floor(currentTime) != Mathf.Floor(currentTime + Time.deltaTime))
        {
            UpdateTimerText();
        }

        if (Mathf.Floor(currentTime) <= 0)
        {
            onTimerEnd?.Invoke();
            stopTimer = true;
        }
    }
}
#

that will work i guess

swift crag
#

or else it's not going to show milliseconds very effectively..

rare basin
#

i show miliseconds only in the summary screen

#

the UpdateTimerText() is only minuted and seconds

#

no miliseconds in there

#
    private void UpdateTimerText()
    {
        int minutes = Mathf.FloorToInt(currentTime / 60);
        int seconds = Mathf.FloorToInt(currentTime % 60);
        timerText.text = string.Format("{0:00}:{1:00}", minutes, seconds);
    }
rich adder
# cursive viper so I do another bool that checks if the ball is parented, inside the if method t...
Vector3 fwd = cam.TransformDirection(Vector3.forward);

    if (ballGrabbed ) return;
  
    if (Physics.Raycast(cam.position, fwd, 5, layerToHit) && grabPressed)
    {
         ball.SetParent(cam); // etc.. make your own point to parent to infroot of cam
        Debug.DrawRay(cam.position, fwd, Color.green, 10);
        ballGrabbed = true;
        grabPressed = false;
    }```
You just need the method to launch the ball / unparent it and set bool `ballGrabbed` false
polar acorn
open apex
#

I am trying to make it so, when the place is not touching "ground" it runs the function "EndGame" but it says that "OnCollisionEnter" it's not working

#

How can I make it work?

polar acorn
cursive viper
rich adder
cursive viper
#

ok

#

thanks u really helping me a lot lol

rich adder
#

no problem ๐Ÿ™‚

cursive viper
#

would probably be on this for hours otherwise lol

rich adder
#

yeah it takes hours sometimes

#

was stuck on my ai for a gamejam yest for 5 hours ๐Ÿฅฒ

cursive viper
rich adder
#

exactly, mine was figuring out I just needed a dictionary in the end ๐Ÿฅน

cursive viper
#

one time I tried to implement gun spread by having 4 gameobject children of the player rotate at certain degrees depending on the gun type and then casting a ray in the forward direction of each of those game objects and calculating the "diamond" shape that the raycasts made when they hit a collider and firing another ray inside of that "diamond" ๐Ÿ˜ญ

#

then some guy on the unity discord turned my paragraph of code into two lines without the unecessary gameobjects

dusty coral
#

why is the audio clip not playing?

cursive viper
#

by the way the code still doesn't work lol, now the ball tweaks slightly less for like 5 seconds before it just noclips through the floor lmao

wintry quarry
cursive viper
#

do any video recording software come with windows?

rich adder
#

yeah but obs is better imo

rich adder
dusty coral
wintry quarry
#

My advice is the same

#

you have to debug

rich adder
# cursive viper yeah hold on

also I think if you want collisions while holding the ball then parenting is not the solution and might need to use rigidbody instead

cursive viper
open apex
rare basin
#

then ask?

open apex
#

I have put it in a FixedUpdate function on purpose

#

Is it going to update or just gonna run once?

polar acorn
rare basin
#

you made a local function

wintry quarry
rare basin
#

and you are not calling it

rich adder
cursive viper
cursive viper
open apex
rare basin
#

called local functions

open apex
#

is it gonna only run once?

wintry quarry
polar acorn
rare basin
wintry quarry
#

that's the point of OnCollisionEnter

rich adder
open apex
#

ohhhh

cursive viper
open apex
#

๐Ÿ˜Š Thanks

cursive viper
#

that was much easier than I thought lol I uploaded it before you even answered if I should use it or not

rich adder
cursive viper
# rich adder yea much easier to read

btw even though this code includes the line

ball.position = new Vector3(transform.position.x, transform.position.y, transform.position.z + 1.5f);

on line 34 I tried running it without it and didnt work

#

this is for the parent

rich adder
#

ah its a rigidbody

#

simply parenting wont work

cursive viper
#

and this is for the obj

rich adder
#

also your scale is inverse, always keep root object at 1,1,1 with all the components and meshes resized as children

cursive viper
rich adder
#

but you still need to manually move it iirc

rich adder
#

I also have done it in the past where you can keep the ball dynamic rigidbody if you dont want it to clip through walls

open apex
#

How can I code my player, so, if it's not touching ground. It prints "GameOver"

#

That was what I was trying to code

rare basin
#
if(!isGrounded)
   Debug.Log("GameOver");
#

many ways to check for isGrounded

#

many tutorials on that

rich adder
shell sorrel
#

you were told this the other day when you did the function in a function as well

open apex
open apex
cursive viper
# rich adder yeah kinematic is what you want sure to not make it move
if (Physics.Raycast(cam.position, fwd, 5, layerToHit) && grabPressed)
{
    Debug.DrawRay(cam.position, fwd, Color.green, 10);

    ballRb.isKinematic = true;
    ball.position = new Vector3(transform.position.x, transform.position.y, transform.position.z + 1.5f);
    ball.SetParent(cam);

    ballGrabbed = true;
    grabPressed = false;
}
rich adder
tepid summit
# rich adder you have to provide the code

im back

    public CoilyBoily CoilyBoily;
    public float speed = 20f;
    float xRotation = 0f;
    

    public LayerMask layerMask;
    
    void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
        CoilyBoily = GetComponent<CoilyBoily>();
    }

    void Update()
    {
        float xAxis = Input.GetAxis("Mouse X") * speed * Time.deltaTime;
        float yAxis = Input.GetAxis("Mouse Y") * speed/2f * Time.deltaTime;
        xRotation -= yAxis;
        xRotation = Mathf.Clamp(xRotation, -90f, 90f);
        Mathf.Clamp(yAxis, -90, 90);
        player.Rotate(0f, xAxis, 0f);
        transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
    }
    void FixedUpdate()
    {
        RaycastHit hit;
        if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity, layerMask))
        {
            CoilyBoily.canMove = false;
        }
        else
        {
            CoilyBoily.canMove = true;
        }
    }
}
cursive viper
#

ah ok that seems like a better way to move the ball

rich adder
rich adder
tepid summit
cursive viper
#

@rich adder all this code will still work in multiplayer as long as instead of using references I get the rb and transforms within the script and then just sync the position of the ball and players and such right?

rich adder
tepid summit
#

no

cursive viper
#

assuming I successfully somehow manage to implement multiplayer in a game ever

tepid summit
#

this is the other one

open apex
rich adder
open apex
#

thanks for the help Xaxup

rich adder
#

multiplayer needs to be build from scratch its harder to implement into a made game

tepid summit
rare basin
open apex
rare basin
#

The code is sometimes in the question you write

#

Read your question again I didn't make anything particular to write this pseudo code

cursive viper
rich adder
tepid summit
#

yeah

#

is ent it

cursive viper
#

but yes I know I have to make multiplayer from scratch im just messing around with this rn to get an idea going

rich adder
tepid summit
#

oh wait

#

i selected it but didnt pres copy

#

so i thought i sent tit

rich adder
tepid summit
#

can you do the bot command for teh links

rich adder
eternal falconBOT
tepid summit
cursive viper
#

but for now the ball has reached unprescedented levels of tweaking

#
if (Physics.Raycast(cam.position, fwd, 5, layerToHit) && grabPressed)
{
    Debug.DrawRay(cam.position, fwd, Color.green, 10);

    ballRb.isKinematic = true;
    ballRb.MovePosition(new Vector3(transform.position.x, transform.position.y, transform.position.z + 1.5f));
    ball.SetParent(cam);

    ballGrabbed = true;
    grabPressed = false;
}
tepid summit
rich adder
# cursive viper

first make sure the pivots are correct , i see you're in center mode

cursive viper
#

I think

rich adder
cursive viper
#

the main camera is a child of another object called camholder

tepid summit
#

makes sure its..?

cursive viper
#

and the player gameobject has several children

cursive viper
#

I think the best course of action would be to give the player another child called "ballHolder" and parent the ball to it

#

or do you think thats overthinking it

rich adder
#

both should be 1,1,1

rich adder
polar acorn
tepid summit
#

i did

rich adder
#

in playmode?

tepid summit
tepid summit
rich adder
#

and what is the result the screenshot above?

tepid summit
#

wdyn

#

oh

#

yeah

#

thats the inspector

rich adder
#

so CanMove is false in playmode?

open apex
#

When I specifically write position.y < -1 does the job. Are there any reasons it doesn't work this way?

tepid summit
#

no

#

it keeps going back to true

#

im gonna review my code

rich adder
#

so you just lied

wintry quarry
#

position is a property

#

it is not a function

#

only functions can be invoked with (parameters)

open apex
#

in the y axis

polar acorn
wintry quarry
#

because it makes no sense

open apex
#

hmm ok

tepid summit
open apex
#

it worked when I did position.y < -1

wintry quarry
polar acorn
wintry quarry
#

you are checking if the value of the property is less than -1

tepid summit
#

i didnt say it did

polar acorn
cursive viper
#

I thought you meant yeah thats a good idea and I did it lol

#

its not working either way the ball doesn't do anything now

eternal needle
open apex
cursive viper
#
if (Physics.Raycast(cam.position, fwd, 5, layerToHit) && grabPressed)
{
    Debug.DrawRay(cam.position, fwd, Color.green, 10);

    ballRb.isKinematic = true;
    ball = ballHolder;
    ball.SetParent(ballHolder);

    ballGrabbed = true;
    grabPressed = false;
}
tepid summit
#

i looked

rich adder
polar acorn
# open apex thanks for the help guyz

You should seriously consider learning basic C# syntax instead of coming here with some buck-wild hypothetical guess at the syntax every ten minutes

#

There are many useful links in the pins

tepid summit
rich adder
#

anyway put debug.log inside your methods there and see if the bool is triggered at all through function

polar acorn
open apex
#

Do you mind checkings dms?

polar acorn
open apex
polar acorn
#

Minimum two hours

rich adder
#

pretty fair

polar acorn
#

Paid in advance

charred spoke
#

Thatsโ€ฆcheap

cursive viper
#

Ill charge a quarter of that, but ill get the answers wrong half the time and ill be using google to answer most of them

polar acorn
tepid summit
#

the collider wasnrt scaled correctly in the model

#

ive got it rom here

charred spoke
open apex
#

It's fun learning how to code, but it's more fun trying to code with some theory and 0 knowledge (because I get digiholic busier ๐Ÿ˜Ž )

charred spoke
#

And the most fun is solving the problems yourself

open apex
#

Bro, that's called "torture"

silk night
#

nah +1 to Uri

polar acorn
open apex
#

LASOD;JKHG[OIJFASDG

#

lmao

#

I know it's sometimes kinda annoying that I keep on asking questions, but honestly I do (sometimes) try to solve my problem on my own.

silk night
#

and why do we endure the pain? ofcourse to have more advanced pain on more convoluted problems!

rich adder
#

pain grinder 2000

open apex
#

Daddy GPT decided to take on the pain for the boys

rich adder
#

funny

#

you like playing dice

tepid summit
#

can i change the max polyogns limit

rich adder
#

did you fix your previous problem?

#

also why are you going over polygons limit

polar acorn
polar acorn
rich adder
tepid summit
#

its aight i just use a capsule collider

polar acorn
tepid summit
rich adder
#

that got me too

#

my dislexia made it look correct for a secUnityChanLOL

rich adder
#

mesh colliders are expensive

#

if you hit limit on convex you prob have something guaranteed to implode and to complex

tepid summit
#

you mean too complex?

#

jk

polar acorn
#

I'm the one that made the spelling comments, be snarky in my direction

smoky epoch
#

I'm having issues making an object transparent. Every time I use the fade render mode my body no longer overlaps the visor. I can't find anything on google about it. I just want my player to become transparent but so far the only way I've found to do that is with the fade/transparent rendering mode on my material.

tepid summit
#

change the material

#

idk

polar acorn
smoky epoch
#

well i figured there might be some stuff at runtime to mess with it but yeah ill keep looking thanks

robust kelp
#

anyone willing to review this yanderedev type script and explain to me why is my velocity clamped at 30 while sliding in air?

timber tide
#

you have a max velocity method there so why don't you debug that

#

if you're not supposed to be calling it while sliding then throw out some more logging

#

or better yet, use breakpoints

robust kelp
#

ill try thanks

ancient cloak
#
    {
        horizontalInput = Input.GetAxis("Horizontal");
        forwardInput = Input.GetAxis("Vertical");

        
        transform.Translate(Vector3.forward * Time.deltaTime * speed * forwardInput);
        transform.Rotate(Vector3.up, Time.deltaTime * turnSpeed * horizontalInput);
    }```
#

how can i adapt this to limit the rotation of the object (a car)

#

basically when i press a or d the object will rotate in place and it feels unrealistic so im trying to fix it but i have no idea how

ancient cloak
#

oh okay thanks

hexed granite
#

hi I have a little problem I know I had already asked several times but they helped me I installed something and now my script looks like this and I don't know why it displays this : Can't add script component 'PlayerController' because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match. ```c#
using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.EventSystems;

public class playerController : MonoBehaviour
{
public float movespeed;

private bool isMoving;

private Vector2 input;

private void Uptade()
{
    if (!isMoving)
    {
        input.x = Input.GetAxisRaw("Horizontal");
        input.y = Input.GetAxisRaw("vertical");

        if (input != Vector2.zero)
        {
            var targetPos = transform.position;
            targetPos.x += input.x;
            targetPos.y += input.y;

            StartCoroutine(Move(targetPos));
        }
    }
}

}

IEnumerator Move(Vector3 targetPos)
{
isMoving = true;

while (targetPos - trasnform.position).sqrMagnitude > Mathf.Epsilon)
{
    Transform.position = Vector3.MoveTowards(transform.position, targetPos, moveSpeed * Time.deltaTime);
}
Transform.position = targetPos;

isMoving = false;

}

languid spire
#

you have very obvious compiler errors. Please learn some C# basics

hexed granite
#

okay how

languid spire
#

you also have non compiler errors which will mean even if you fix the errors it wont work

languid spire
eternal falconBOT
#

:teacher: Unity Learn โ†—

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

hexed granite
#

and how to make it work even if you know how to do C#

languid spire
#

Learn will teach you that as well

hexed granite
#

but I can't learn I don't have time if only

#

it is for school

#

I have to do a project presented and I chose to create a little game

dreamy ravine
#

Hi! I need some help. I want to make a 2-player card game for a school project.
I'm using Lobbies to connect the 2 players and I have an issue: I'm testing it with ParrelSync, but I get this error:

Unity.Services.Lobbies.LobbyServiceException: player is already a member of the lobby

because the players have the same ID. Is there any way I can make the players generate different IDs?

languid spire
hexed granite
#

we have to choose a project that is close to our hearts, I thought it would be less complicated, the problem is that I understand almost nothing

#

I understand what I write in scripts but when there is an error having to resolve it without help is quite hard

topaz pendant
topaz pendant
hexed granite
#

I completely agree with you but when you speak French itโ€™s not so simple

topaz pendant
#

that's true, but to be a developper you kinda have to learn english

dreamy ravine
# topaz pendant Hello, could you provide your code so that I can look into it

I found a tutorial about Lobbies on YouTube and the guy had no problem with this code. Someone in the comments said they had the same problem as me and the guy didn't explain why he didn't have said problem in the video (He just hit Build and Run). He pointed that person to his Discord server because someone encountered the same issue. There are other scripts that link the Join and Host buttons but they mainly use functions from here.

eternal needle
#

If this isnt a unity specific class, save yourself the headache because the people marking it wont care if it's a shitty game in unity vs a shitty game in python. Except one is much easier to make

hexed granite
#

i just want to make a game similar to Pokรฉmon Platinum and have a character move in a 2D world and capture beasts, it seems hard to me now

topaz pendant
#

tristan try using RPG Maker

hexed granite
#

okay do you have a link good for official page ?

modest dust
#

You have to pay for RPG Maker

hexed granite
#

oh shit

modest dust
#

Unless you, you know.

hexed granite
#

i dont pay

#

only free

#

crack ?

cunning rapids
#

Should my weapon be under the player game object or camera holder

hexed granite
#

Can someone just tell me how I can correct my mistakes and tell me what should I do to make it work in less than 1 hour because I have to finish it by July

polar acorn
dreamy ravine
scarlet skiff
#

idk how to make a good cooldown systemm.. this one isnt working

hexed granite
frosty hound
cunning rapids
polar acorn
cursive viper
#

how can I make a collider phase through another?

eternal needle
hexed granite
#

me too

cunning rapids
hexed granite
#

me not dollar me euros

topaz pendant
#

Services

cursive viper
hexed granite
cunning rapids
tawdry rock
cunning rapids
cursive viper
cursive viper
#

I think probably making it a trigger isnt the way to go here anyway

#

I just want it to phase through another specifc collider not every collider

tawdry rock
cunning rapids
cunning rapids
dreamy ravine
cursive viper
#

not every collider

#

and I dont need it to be a trigger either

eternal needle
cunning rapids
cursive viper
tawdry rock
dreamy ravine
cunning rapids
cursive viper
tawdry rock
#

i mean if you use GameObject.Find then performance wise it matter (very slightly) because unity will search for the gameobject from top to bottom each time in the hierarchy. thats why its a good solution to cache it in a singleton refference

cunning rapids
#

Camera stacking is a common method

eternal needle
cursive viper
#

ill show a video tho

#

im stupid lol

#

definitely should not be colliding with the player

#

maybe the floor and the player for best results

#

maybe should avoid all collisions while holding then stop ignoring them once launched

#

how can I unattach an object from its parent?

rocky canyon
#

set its parent to null

cursive viper
#

was thinking that

#

thanks

rocky canyon
#

just using seperate Renderers in the piepeline

#

still a legitimate approach in teh Standard Renderer Pipeline tho

shell sorrel
rocky canyon
#

i guess

#

well u only use 1 camera

shell sorrel
#

its a pretty common way to handle things like view models and not clipping geo

rocky canyon
#

as opposed to having multiple camera's at once..

#

u can just stack renderers in teh asset

#

each doing a different thing.. and u can insert passes between the stuff thats already there

rocky canyon
#

"renderer feature" is what i was thinking

#

i use this + layers to render an outline in one of my projects

shell sorrel
#

yeah have used that for rendering outlines for interactables etc

#

or sometimes i just do it manually with my own render feature + render pass

rocky canyon
#

yea i just noticed this "Stack" area

#

seems like u can do it there too

cunning rapids
#

How to switch moving tools in the 2019 editor

cunning rapids
#

Unlike before they implemented stacking

cunning rapids
#

In the 2021-Now editor it has a button to switch

rocky canyon
#

ya, it seems theres multiple ways.. as u could use a singular camera, and have a certain layer render after everything else..

#

which would be equivilent to stacking camera's w/ different culling

#

but yup, many ways to peel a banana i suppose

rocky canyon
#

u can find all ur shortcuts here in this menu, as well as modify them to ur liking

#

i have mine set to mirror Blender's transform tools

fiery fjord
#

I have a coroutine in an OnTriggerExit2D method shown here:

    {
        if(!shipExited && other.CompareTag(WORLD_TAG))
        {
            shipController.ShipEnteredWorld(false);
            
            StartCoroutine(WaitForShipExit());
        }
    }
    
    private IEnumerator WaitForShipExit()
    {
        shipExited = true;
        
        yield return new WaitForSeconds(0.25f);
        
        shipExited = false;
    }```

Every time I restart the level or stop playing the game in Unity, I get this error around 3-4 times:

``Coroutine couldn't be started because the the game object 'Collision Detection' is inactive!``

I have attempted to change my if statement to this: ``if(!shipExited && other.CompareTag(WORLD_TAG) && gameObject.activeSelf)``

And this has not fixed it, any recommendations? Thanks!
cunning rapids
rocky canyon
#

meaning if the gameobject is inactive the updates and stuff stop.. but the physics methods wont..

#

so its trying to call the coroutine. when the coroutine cant run

#

if(!shipExited && other.CompareTag(WORLD_TAG) && gameObject.activeSelf)

fiery fjord
#

Ah, gotcha, that makes sense

rocky canyon
#

u could try this..

#

to make sure the gameobject is active when the physics methods try to run

#

wait.. u said u tried that?

#

u could also make a method to check if the coroutine is already running. to avoid calling it mutliple times.. but not sure thats the issue

fiery fjord
#

I believe I did, that's why it was pretty confusing. Though, I am trying it now and it seems to be working. Unfortunately the error happens once in a while, so I just have to wait and see

rocky canyon
#

yea theres other things like the method to check if its running that might solve all the issues

fiery fjord
#

I was thinking there might be multiple instances of the script running

#

I might double check to see if that is the case as well

rocky canyon
#
    if(condition)
    {
        if (!IsCoroutineRunning(WaitForShipExit()))
        {
            StartCoroutine(WaitForShipExit());
        }
    }

private bool IsCoroutineRunning(IEnumerator coroutine)
{
    return coroutine != null && coroutine.MoveNext();
}```
#

something like this.. but i dont know what it does.. just seen it in a unity forum

#

i had to look up what .MoveNext() was

rocky canyon
fiery fjord
#

Hahaha, I will try to avoid that if possible. Not that it won't work, it just seems a little overkill maybe

#

Thanks for the help

rocky canyon
#

ya true..

#

np, gl

#

the whole physics functions running on a disabled object had me stumped with my own issue a year or so ago

#

turned my hair gray b4 i figured it out

fiery fjord
#

Lol, I never knew that happened, thought the physics function couldn't run if the object is disabled

rocky canyon
#

yea i did too thats why i never thought to debug it

#

and i went looking for the solution in all the wrong places lol

#

it wasnt until i started seeing debugs from a disabled object i finally connected the dots

#

i started adding booleans to all my stuff that had physics

#

"allowDetection"

#

and i would enable and disable it in the OnEnable() Disable() functions

fiery fjord
#

It seems like the physics function runs a few times, even after disabling or destroying the object when the scene unloads or loads. Like for example, I put StopAllCoroutines() in an OnDestroy() and OnDisable() methods, both still gave me the error. Though, I don't know whether that would fix it anyways

rocky canyon
#

just a blanket fix.. so i wouldnt forget about it

#

ya, not sure why that is.. im not super good with coroutines and how they work

fiery fjord
#

Me either

rocky canyon
#

i can use them but not quite fully understand them

#

u may want to cache the coroutine and stop it directly

fiery fjord
#

Imma head out and see if this issue is fixed, thanks for the heads up on the physics functions, I will have to keep that in mind

rocky canyon
#

altho im not sure that would yield any different result

fiery fjord
rocky canyon
#

๐Ÿ€ good luck again

swift crag
#

activeSelf tells you whether this specific game object is activated

#

It does not tell you whether its parents are activated.

#

And if any parent of the game object is deactivated, then every child will be inactive.

#

You want activeInHierarchy.

scarlet skiff
#

My intention is to make it so that the player can only "float" aka hold down the space bar for 3 seconds, and after that they need to wait half a second to do it again, but it like floats for 1 frame then poof

swift crag
#

And there's no way for a game object to be inactive yet have an active child

keen hill
#

how can i unlock the free movement of a sprite attached to a gameobject to fully rotate and face the player instead of weirdly changing shape here is the pic of two of them they should bot face me they are both square sprites and both have the same script the one closer to me works fine and the other one doesnt heres a pic

#

its like its stuck to the log

#

"log"

swift crag
#

so the if statement fails and the else statement runs instead

#

and you stop floating

#

your conditions are wrong

keen hill
swift crag
#

This will cause distortion as child objects rotate.

#

If you can't make a model with the correct shape, then set it up like this

#
- Parent
  - Cube
  - Sprite 1
  - Sprite 2
keen hill
#

i mean the sprite that rotates corectly is not attached to the cube

#

its just an example

#

that the second one is stuck

late bobcat
#

https://hatebin.com/rlkkzogpdm Guys any idea on why it is not resetting positions of Player and Ball after scoring a goal? (Last method is what should reset positions, and it's being called in the Ontrigger Method) I've linked positions already in the unity inspector and linked Player gameobject too

swift crag
#

Don't do that. All of the parents should have a uniform scale.

#

i.e. all three scale values should match

#

Parent the cube to an empty object and scale the cube however you want

swift crag
late bobcat
#

ye i debugged

swift crag
#

The score going up would be sufficient.

#

What did you do to debug it?

cursive viper
#

Ive been stuck on this for like 30 minutes and chatgpt couldnt come up with anything either but

private void FixedUpdate()
{
    Vector3 fwd = cam.TransformDirection(Vector3.forward);

    Vector3 velocity = (ballHolder.position - ball.position) / Time.fixedDeltaTime;

    if (ballGrabbed && !grabPressed)
    {
        ball.GetComponent<Collider>().enabled = false;

        ballRb.velocity = velocity;
        ballRb.MoveRotation(Quaternion.RotateTowards(ball.rotation, ballHolder.rotation, rotationSpeed * Time.fixedDeltaTime));

        return;
    }

    ball.GetComponent<Collider>().enabled = true;

    if (Physics.Raycast(cam.position, fwd, 5, layerToHit) && grabPressed)
    {
        Debug.DrawRay(cam.position, fwd, Color.green, 10);

        ballGrabbed = true;
        grabPressed = false;
    }
}

this code works almost perfectly except for that when the ball is dropped and the collision of the ball is re enabled, because the button to grab the ball has to be pressed in order for it to be dropped, the second if method is immediately reactivated and it goes back to the first if method and keeps returning. I tried adding a delay between the re enabling of collsion and second if method but didnt work

keen hill
#

so when i move it the name stays in place

late bobcat
#

i debugged ResetPositions @swift crag

swift crag
#

The collider can remain on the cube.

keen hill
#

collider too?

swift crag
#

Rigidbodies look at all of their child colliders, so it'll work fine

keen hill
#

no

scarlet skiff
swift crag
#

The collider can stay.

late bobcat
#

i was trying to edit the code and i had a method that after scoring a goal it would reset the current scene. But i only wanted to reset positions, not the whole scene

swift crag
#

you want to fail if the current time is past the float-end time

#

note that your variable name is not good here

#

"float duration" implies that it's a duration

#

but that's not what floatDuration stores

#

it stores a time

#

floatEndTime would be appropriate

#

That should make it clear that DateTime.Now < floatEndTime means "the current time is before the time we stop floating"

swift crag
#

Are you using rigidbodies for the ball and player?

late bobcat
#

yep

swift crag
#

I bet you have interpolation enabled.

viral tulip
#

i have a collision detector to keep score, but it only works for the first one?

late bobcat
#

@swift crag on players/balls?

swift crag
#

When you set the position of a transform, you're going arounds the physics system's back.

#

Yes.

#

Don't turn interpolation off -- it's just what's causing the issue to happen.

#

When interpolation is on, the rigidbody sets the position of the transform every single frame

#

(so that it isn't just moving during physics updates)

scarlet skiff
swift crag
#

But this means that if you set the position directly, it gets overwritten instantly

#

You need to set the position of the rigidbody component directly.

late bobcat
#

it's on youre right

swift crag
#

You already have that for _ball

#

_ball.position = ...

late bobcat
#

ye

swift crag
#

I would suggest referencing the player as a Rigidbody2D as well

late bobcat
#

but shouldn't it work for ball at least?

swift crag
swift crag
#

It's identical to what you're doing for the Player

late bobcat
#

ohh i see

#

so i just grab rigidbody and edit it

swift crag
#

both GameObject.transform and Rigidbody2D.transform give you the Transform for the object / the object they're on

late bobcat
#

for both players and ball

swift crag
#

change GameObject Player to Rigidbody2D Player and then change Player.transform.position to Player.position

#

and you'll be good

#

yep

swift crag
eternal falconBOT
late bobcat
#

i see thanks, that's because interpolate is updating the position of the object is attached to?

swift crag
ancient holly
#
    private List<Dungeon> _dungeons = new List<Dungeon>();
    private int _currentDungeonIndex;
    private Dungeon _currentDungeon { get { return _dungeons[_currentDungeonIndex]; } }

the last {get {}} causes index out of range exception in editor, whats the ideal way to fix this?
the last {get {}} causes index out of range exception in editor, whats the ideal way to fix this?
is there a way i can make that get {} not get executed while in editor
or should i just add an if statement

swift crag
#

I'm not really clear how that works out, actually

keen hill
#

why is my rigidbody falling through the floor ?

late bobcat
#

i see

swift crag
swift crag
late bobcat
#

ty @swift crag ๐Ÿ™

swift crag
#

oh wait -- the second screenshot is the floor, isn't it

keen hill
#

yes

swift crag
#

I thought you had a concave mesh collider on a rigidbodyh

#

That would cause errors.

ancient holly
#

because dungeon is a struct

swift crag
keen hill
#

the console's empty

swift crag
#

This is kind of wrong

#

But if all you're doing is stopping it from throwing up in the editor, I suppose that's fine

keen hill
#

hold on ill send all of the player componets's

ancient holly
#

welp, it won't ever happen inside the gameplay

#

so its fine i guess

ancient holly
swift crag
#

default is the default value a field gets, iirc

#

for reference types it's null

#

and for other types it's going to be things like zero

keen hill
swift crag
#

use backticks, not single quotes

#

it's the lowercase tilde

#

`

swift crag
# keen hill

You have both a character controller and a non-kinematic rigidbody here. This is not correct.

keen hill
#

okay i understand

ancient holly
#

i was using new struct() with default constructors on structs before

keen hill
#

that what i was thinking too

ancient holly
#

this is way more practical

swift crag
ancient holly
#

or cleaner

swift crag
#

I'm a little fuzzy on the intricacies there

keen hill
#

ill probably change my movement script cuz its trash anyways

swift crag
#

default is nice for generic methods

#

(although, it's also a little bit misleading for value types...)

viral tulip
#
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;
using UnityEngine.UI;

public class TileSpawner : MonoBehaviour
{
    public GameObject tile1;
    public GameObject tile2;
    public GameObject detector;
    public Text score;
    int i = 0;

    void Start()
    {
        score.text = "Score: ".ToString() + i.ToString();
    }
    void OnCollisionEnter(Collision col)
    {
        if(col.gameObject.name == "Player")
        {
            i++;
            score.text =  "Score: ".ToString() + i.ToString();


        }
    }
}
scarlet skiff
swift crag
#

floatCooldown is probably in the distant past

#

you want to check if the time is greater than the time the cooldown ended at

swift crag
#

but doesn't do it afterwards?

viral tulip
#

yes

swift crag
#

You should use Debug.Log(col.gameObject.name); to log what's hitting the collider each time

scarlet skiff
polar acorn
viral tulip
#

@polar acorn there are multiple of them

swift crag
#

you wrote <=

#

that's less than or equal

#

this checks if the cooldown is not yet over

swift crag
#

and they're all going to say your score is 1 after one hit on them

polar acorn
viral tulip
swift crag
#

Multiple of what?

viral tulip
#

oh my bad

#

multiple collidable objects

swift crag
#

and does each one have its own TileSpawner component?

viral tulip
#

yes

scarlet skiff
viral tulip
#

i just copied and pasted them

keen hill
#

how can i disable a sprite renderer componet through code?

scarlet skiff
#

soo... like this?

rocky canyon
#

now time to refactor b/c this is a mess!

shrewd swift
polar acorn
swift crag
# scarlet skiff soo... like this?

Yes, that's what I envisioned. But this is still going to be wrong, since you set floatDuration = DateTime.Now.AddSeconds(3); constantly as long as you have space held.

scarlet skiff
swift crag
#

You need to detect when you start floating exactly once

scarlet skiff
#

so i put it with getkeydown

fiery fjord
swift crag
#

Then a second condition should check when the player stops floating. It'll have two reasons:

  • GetKey is returning false
  • The float end time is reached
swift crag
#

one decides to start floating if GetKeyDown is true and all of the conditions are met

#

one decides to stop floating if GetKey is false OR the time runs out

teal elk
#

I'm confused as why my bullet when spawned dosent shoot at my mouse direction. i have made a code like this in another project's the same way and it just works but here i get this issue```cs
public void Fire()
{
if (Time.time > timeTofire)
{
timeTofire = Time.time + playerData.FireRate;
Projectile newProjectile = Instantiate(projectile, projectileSpawnPoint.position, projectileSpawnPoint.rotation) as Projectile;

        newProjectile.SetSpeed(playerData.ProjectileSpeed);
        
    }
}```
viral tulip
swift crag
#

I'm guesing that your projectileSpawnPoint transform is rotated wrongly.

sand veldt
#

how can we add ads in unity game

ivory bobcat
swift crag
#

Maybe SetSpeed sets your speed in the +Y direction, but the spawn point's +X axis is pointing forwards from your ship.

#

in that case, you need to rotate the projectile spawn point so that it's pointing in the right direction

teal elk
# swift crag what is `SetSpeed`?

its this function im my projectile script, so i can set my player projectile speed in the weapon script.cs public void SetSpeed(float newSpeed) { speed = newSpeed; }

shrewd swift
keen hill
#

please help im getting this error and i think its cuz i retrieved the bool from the other script incorrectly

ivory bobcat
swift crag
#

go to the first error -- the one on line 14

shrewd swift
swift crag
#

something on that line is getting used, but is null

keen hill
#

sry the rest of the pics didnt send

swift crag
#

You've expertly cropped out the line numbers

keen hill
#

lol

#

one sec

swift crag
#

scr is null

viral tulip
teal elk
polar acorn
keen hill
ivory bobcat
eternal falconBOT
swift crag
#

a NullReferenceException falls out whenever you try to read a member from a reference typed variable.

polar acorn
shrewd swift
keen hill
scarlet skiff
shrewd swift
#

if you spawn your bullet looking towards the mouse

swift crag
shrewd swift
#

wait i might be confusing with UE

scarlet skiff
#

floatDurastion had to be updated not in the else statement

#

thanks btw

swift crag
polar acorn
ivory bobcat
shrewd swift
keen hill
rocky canyon
keen hill
#

i retrive it form my other script

swift crag
#

it would be useful to look at the projectileSpawnPoint

#

you don't have to pause after shooting a bullet that way

#

the rotations will be identical

polar acorn
rocky canyon
#

its still very much a WIP and imma most likely need help today.. as i got to get these waypoints into the navmesh script.. w/ is pretty chunky and bad rn