#💻┃code-beginner

1 messages · Page 311 of 1

whole idol
#

the problem is that my player will always go through them

#

these are my player's components

rancid tinsel
#

did you tick is trigger?

#

on the box collider component

#

send a screenshot with the components expanded so we can see if the issue is there 🙂

whole idol
#

i just did

#

still goes through them

rancid tinsel
#

if it wasnn't ticked before that's good

#

it isn't meant to be ticked

#

down to hop on a vc so you can screenshare it to me?

whole idol
rancid tinsel
#

untick "is trigger"

whole idol
#

untick?

rancid tinsel
#

that disables "physical collisions" i guess you could call them

whole idol
#

i want them to be collidable

#

rock hard

rancid tinsel
#

😭

#

i know

#

but trust me

whole idol
#

aight

rancid tinsel
#

is trigger is basically to let objects pass through, but so you can still access the collision

#

it would be used for something like checkpoints etc

#

also great tutorial, thats the exact one i started with

#

remember to untick it for both the upper and lower pipes, as well as the player

#

youll have to do that to the actual prefabs down in your assets folder

#

so that all the pipes you spawn in have the same settings applied

whole idol
#

by the way

#

I just realized, they all got box collider 2D

#

this is a nested pipe

#

which has a pipes

#

inside of pipes there's two more nested objects called

#

upper and lower

rancid tinsel
#

yup

whole idol
#

inside of each of these there's an actual collider 2D as an object in the hierachy

#

both collider and upper/lower have colliders

rancid tinsel
#

those are the ones you need to untick it for

whole idol
#

should that be happening?

#

which ones?

#

green or red?

rancid tinsel
#

oh

#

as in

#

upper and lower have colliders

#

but then they also have child objects that also have colliders?

whole idol
#

dont worry about that

rancid tinsel
#

you can get rid of those child objects pretty sure

rancid tinsel
#

do you know the timestamp for when in the tutorial you make the nested pipes?

#

I want to double check what he was doing with that

whole idol
rancid tinsel
whole idol
#

yep, exactly

#

by the way it still doenst work

rancid tinsel
#

dont worry i understood the maxor reference

whole idol
#

I unticked the ticks

rancid tinsel
#

what was the nested pipes prefab meant to be for?

whole idol
#

uhm... I wanted to move around the rigidbody 2D thingies and I couldn't if it was on the same Gameobject layer because moving one of these components would move the entire thing along with it and i couldnt adjust it properly

#

but now its ggwp

rancid tinsel
#

im not sure i follow

#

either way, send a screenshot of the inspector for the player and the pipes

whole idol
#

erm.. i couldnt move around the rigidbody 2d bro

rancid tinsel
#

and make sure the collider values are visible

whole idol
#

moving it around would move the pipes too

#

and i wanted to readjust the size etc, you know

whole idol
#

Ohhh

rancid tinsel
#

yeah

#

and also if you were to resize the object the collider is on, it would also change the size of the collider

#

so its just a matter of making sure the collider fits on the object and you dont really need to fiddle with it anymore

whole idol
#

thanks for the heads up

rancid tinsel
#

but yeah send the player and pipes inspector screenshots

#

im assuming the issue might be an "is trigger" tick on the player collider?

#

but cant know without seeing

whole idol
#

yep

#

i unticked them all, hold on, imma show u

rancid tinsel
#

I mean the upper and lower objects

#

so I can see the collider values lol

whole idol
#

you can see the collider values

#

oh wait you mean these values?

#

on info?

whole idol
rancid tinsel
#

yes

#

that checks out

#

what about the player?

whole idol
whole idol
#

I even added a sphere collider on top of the player

#

and turned on all the is Trigger

#

also, still nothing happens, no collissions

rancid tinsel
#

you're meant to turn off the is Trigger

#

"A trigger doesn't register a collision with an incoming Rigidbody. Instead, it sends OnTriggerEnter, OnTriggerExit and OnTriggerStay message when a rigidbody enters or exits the trigger volume."

#

also sorry for late reply, I had to go do something quickly @whole idol

#

its best to put the collider on the player game object btw, rather than on a separate one

modest dust
#

Or at least make the collider a child of the rigidbody.

#

But in your case it's enough to just put it on the same go as player

whole idol
#

I already have a rigidbody 2d on the player

#

and for some reason Unity's boundary is that you can either have one or the other

rancid tinsel
#

no

#

i see the issue now actually

#

you used a sphere collider

#

which is for ball shaped objects

#

as in

#

3D

#

you need to use a circle collider 2D

#

and it will work when putting it on the player with the rigidbody 2D

whole idol
#

I dont have a sphere collider

modest dust
#

And you don't need one, because it wouldn't work

whole idol
#

and I don't have one

modest dust
#

Add a CircleCollider2D onto the player object

whole idol
#

oh

#

it's amazign that i can actually add that

#

along with rigidbody 2d

#

i was so confused at one point

#

thinking i can either have one or the other with when it comes to these physics components

#

anyway... ill try unticking the IsTrickers again

#

You said they gotta be turned off right?

modest dust
#

It doesn't really need to be turned off

#

A trigger collider can still 'collide' with another trigger collider

#

And you'd usually use triggers to, well, trigger something, think of it as of a detection range

whole idol
#

amazing

grizzled fulcrum
#

So I'm rather new to Unity, and I'm doing a small project with friends. One thing I'm trying to do is to make an object appear and disappear within a 5 second timeframe, let's say a rectangle
How would I be able to make it work? I've tried to use Coroutine but I'm fairly sure I might've placed it on the wrong location, since said rectangle disappears and never comes back lol

keen dew
#

Show the code

rich bluff
modest dust
#

It's either the script or you're deactivating a gameObject where that component resides on, thus disabling the component itself and killing the coroutine as cache said

grizzled fulcrum
#

I was gonna send the script but it's most likely that

#

Would making a parent empty object and tossing the script there work?

modest dust
#

Sure, if you reference the child from there

rich bluff
#

you can also only disable the target component, like sprite renderer

grizzled fulcrum
#

I'll give it a shot once my Unity stops entering game state-

#

Nevermind it crashed

#

So just to make sure I'm not doing anything wrong, this was the script I was going to use
I just want said rectangle to constantly activate and deactivate, wherever the player is

whole idol
#

Assets\scripts\GameOver.cs(7,29): error CS0236: A field initializer cannot reference the non-static field, method, or property 'Component.GetComponent<Camera>()'

#

can someone explain this error? this

rich bluff
#
private WaitForSecondsRealtime wait5 = new...;

...
yield return wait5;
modest dust
whole idol
#

thats a non-static field?

grizzled fulcrum
modest dust
#

Fields initializers cannot reference non-static stuff

#

Do it in Awake or Start instead

whole idol
#

what type is camera thne?

#

non-static?

#

okay

burnt vapor
rich bluff
#

like other fields in class

burnt vapor
#

The code assumes you make a static call

#

Removing it uses the instance instead

whole idol
#

ill just do this instead then

public Camera mainCamera;
#

and drag the camera in from the inspector

#

like a boss

grizzled fulcrum
rich bluff
burnt vapor
#

If only Unity would have just used structs, then it would not have been required

grizzled fulcrum
rich bluff
# grizzled fulcrum Fair enough I'm not quite used to it yet since the whole recent start and all

To explain, WaitForSeconds is a class, when you new it, you create a new instance of that class, an object
that object is allocated (a segment of ram now stores it) on the heap (long term ram storage in .net), which means that when it is no longer used anywhere (no references to it) it will be collected by garbage collector to free that ram, and the more stuff garbage collector has to analyze (it walks all the objects and counts the references to them to see if the object can be collected) the more time it takes to complete a single gc pass over memory
hence the more objects you reuse instead of spamming allocations the less is the probability of you encountering micro stutters due to GC taking too long

#

you are very far from it causing issues for you, so just note it for the future

grizzled fulcrum
#

I see

#

Oh, btw, if I want to make a detection of the player on top of the rectangle when it's active, how would I be able to do that?

rich bluff
#

If its 2d, the 2d physics components and their callbacks

rare basin
rare basin
#

show pls

grizzled fulcrum
#

I think that's how it should be at least

languid spire
# grizzled fulcrum

if I may make one suggestion.
You have programmed an infinite loop. Add a

if (Vapor==null) break;

into it so you have a way out of it

grizzled fulcrum
#

Oh thanks

whole idol
#
using JetBrains.Annotations;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameOver : MonoBehaviour
{
    //public float lowerBoundsY = -5.98f; // position.y
    public BoxCollider2D mycollider;
    private bool isCurrentlyTrigger;
    public GameObject player;

    // we want this script to restart the game everytime somethign happens, also we want to define what a defeat is, and there has to be many 
    //types of defeat, like falling back, falling down etc. and then we wanna restart the player from where he was.
    void Start()
    {
        bool isCurrentlyTrigger = mycollider.isTrigger;

    }

    // Update is called once per frame
    void Update()
    {
        if (isCurrentlyTrigger == true)
        {
            Debug.Log("player touched the lava");
            //here we could use some animation or something
            //player dies
            Destroy(player);
        }
    }
}

#

why does this never Debug?

gaunt ice
#

is currently trigger is false

#

you only set it in start

languid spire
#

this

bool isCurrentlyTrigger = mycollider.isTrigger;

is a local variable not the class variable

whole idol
#

ok I added it inside Update and now its printing

languid spire
#

not the solution. just remove the 'bool' from the line I showed

halcyon geyser
#

Id recommend a starting course

languid spire
#

@whole idol btw your ide should have flagged that that statement in Start is pointless

whole idol
#

it didnt?

#

weird

#

btw

#

right now it always Logging that the player is flying

#
using JetBrains.Annotations;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameOver : MonoBehaviour
{
    //public float lowerBoundsY = -5.98f; // position.y
    public BoxCollider2D mycollider;
    private bool isCurrentlyTrigger;
    public GameObject player;

    // we want this script to restart the game everytime somethign happens, also we want to define what a defeat is, and there has to be many 
    //types of defeat, like falling back, falling down etc. and then we wanna restart the player from where he was.
    void Start()
    {
        isCurrentlyTrigger = mycollider.isTrigger;
        isCurrentlyTrigger = false;
    }

    // Update is called once per frame
    void check_Death()
    {

        if (isCurrentlyTrigger == true)
        {
            Debug.Log("player touched the lava");
            //here we could use some animation or something
            //player dies
            Destroy(player);
        }
        else if (isCurrentlyTrigger == false)
        {
            Debug.Log("Player is flying in the air like normal");
        }
    }
    void Update()
    {
        check_Death();
    }
}

#

oops

#

I see what I did

#

isCurrentlyTrigger = mycollider.isTrigger;
isCurrentlyTrigger = false;

#

Ok I removed the isCurrentlyTrigger = false

#

but if I do that

languid spire
#

you need to fix the first error

whole idol
#

my player will be destroyed from the first frame

#

what error?

#

game is being compiled and played

#

oh wait

#

THAT error

languid spire
#

this one

whole idol
#

yeah

#

ok so problem persists

#

I Cleared the error

#
using JetBrains.Annotations;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameOver : MonoBehaviour
{
    //public float lowerBoundsY = -5.98f; // position.y
    public BoxCollider2D mycollider;
    private bool isCurrentlyTrigger;
    public GameObject player;

    // we want this script to restart the game everytime somethign happens, also we want to define what a defeat is, and there has to be many 
    //types of defeat, like falling back, falling down etc. and then we wanna restart the player from where he was.
    void Start()
    {
        isCurrentlyTrigger = mycollider.isTrigger;
    }

    // Update is called once per frame
    void check_Death()
    {

        if (isCurrentlyTrigger == true)
        {
            Debug.Log("player touched the lava");
            //here we could use some animation or something
            //player dies
            Destroy(player);
        }
        else if (isCurrentlyTrigger == false)
        {
            Debug.Log("Player is flying in the air like normal");
        }
    }
    void Update()
    {
        check_Death();
    }
}

#

there is no unassigned variable however I think I know what the problem is

#

BoxCollider2D is not a GameObject

#

its not referencing to a gameobject

gaunt ice
#

isCurrentlyTrigger is only be assigned in start
and it is value type, the value got copyed

whole idol
#

its referencing to the boxcollider2d of a gameobject

#

and there is no way to drag that from the inspector

#

or is there?

#

oh wait I think I can make a unity layout

#

somehow

#

so that i can have 2 different inspectors open at the same time

gaunt ice
#
public int x=10;
public int y=x;
y=9;
Debug.Log($"x is {x}")//x is 10
#

same as bool

whole idol
#

lol

#

how else am I gonna point to that boxcollider2d of that object

#

specifically

#

the IsTrigger

#

istrigger of boxcollider2d of lava gameobject

languid spire
#

show the inspector of the gameobject with the gameover script on it

whole idol
#

right now only lava has it lol

languid spire
#

that is correct

whole idol
#

looks correct

#

weird

#

this is always true

languid spire
#

of course it is, the value of isTrigger does not change

whole idol
#

btw checked Is Trigger is on

languid spire
#

yes,

 if (isCurrentlyTrigger == true)
        {
            Debug.Log("player touched the lava");
whole idol
vital cargo
#

why does my firepoint not rotating

    private void Attack()
    {
        anim.SetTrigger("attack");

        if (transform.localScale.x > 0)
            firePoint.rotation = Quaternion.Euler(0, 0, -90);
        else 
            firePoint.rotation = Quaternion.Euler(0, 0, 90);

        
        fireballs[0].transform.position = firePoint.position;
        fireballs[0].GetComponent<Projectile>().SetDirection(transform.localScale.x);
    }
}```
whole idol
# languid spire yes, ```cs if (isCurrentlyTrigger == true) { Debug.Log("pla...
using JetBrains.Annotations;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameOver : MonoBehaviour
{
    //public float lowerBoundsY = -5.98f; // position.y
    public BoxCollider2D mycollider;
    private bool isCurrentlyTrigger;
    public GameObject player;

    // we want this script to restart the game everytime somethign happens, also we want to define what a defeat is, and there has to be many 
    //types of defeat, like falling back, falling down etc. and then we wanna restart the player from where he was.
    void Start()
    {
        isCurrentlyTrigger = mycollider.isTrigger;
    }

    // Update is called once per frame
    void check_Death()
    {

        if (isCurrentlyTrigger == false)
        {
            Debug.Log("player touched the lava");
            //here we could use some animation or something
            //player dies
            Destroy(player);
        }
        else if (isCurrentlyTrigger == true)
        {
            Debug.Log("Player is flying in the air like normal");
        }
    }
    void Update()
    {
        check_Death();
    }
}

you mean that i should reverse this?

whole idol
#

this is supposed to be true

#

only when the player is touching

#

that lava object

#

correct?

languid spire
#

Not correct at all, you do not seem to understand how collisions/triggers work

whole idol
#

when does it get turned on then?

wintry quarry
#

It will not change again after that

#

Also it's just checking if your collider is a trigger collider. It's not doing anything with regard to actual collision or trigger detection

dusk merlin
# whole idol when does it get turned on then?

The isTrigger property in Unity's colliders allows objects to pass through each other while still detecting collisions. When a collider set as a trigger interacts with another collider, Unity fires specific events (like OnTriggerEnter, OnTriggerStay, and OnTriggerExit). You can handle these events in your scripts to perform actions when the trigger collision occurs. For instance, in the OnTriggerEnter method, you can write code to respond when an object enters the trigger, such as opening a door or triggering a cutscene.

wintry quarry
languid spire
lilac hemlock
#

Can someone help me out please. I have a structure: Ship Class, Ship Properties SO and ITurnable Interface. My ITurnable Classes will have various parameters, and I want to be able to set these parameters inside SO. Parameters need to dynamically change based on selected ITurnable. How can I implement this? I thought about using OdinInspector with their SerializedScriptableObject.

For example, ITurnable A has turnSpeed, and ITurnable B has turnSpeed and rollSpeed

vital cargo
#

why does my firepoint not rotating

    private void Attack()
    {
        anim.SetTrigger("attack");

        if (transform.localScale.x > 0)
            firePoint.rotation = Quaternion.Euler(0, 0, -90);
        else 
            firePoint.rotation = Quaternion.Euler(0, 0, 90);

        
        fireballs[0].transform.position = firePoint.position;
        fireballs[0].GetComponent<Projectile>().SetDirection(transform.localScale.x);
    }
}```
languid spire
vital cargo
#

Dam

burnt vapor
languid spire
#

log if the code is even being called

burnt vapor
vital cargo
#

i should see a debug log right?, but i dont see anything

{
    anim.SetTrigger("attack");

    if (transform.localScale.x > 0)
    {
        firePoint.rotation = Quaternion.Euler(0, 0, -90);
        Debug.Log("working");
    }
    else 
    {
        firePoint.rotation = Quaternion.Euler(0, 0, 90);
        Debug.Log("working");
    }```
burnt vapor
#

Then your method is not called

#

Considering you didn't share anything else but the method, we can't help you

#

Consider checking how the method is called, and if you actually call it there

vital cargo
#

ok ty

loud mango
#

how do i make a timer so that it is in sync with the fps of the player

#

i saw somewhere that u have to use time.Deltatime

#

but idk how it works exactly

languid spire
#

deltaTime is very simple. It is the length of time taken to process and render the previous frame.
So...
if you had a timer that did

timer += 1;

then timer would vary depending on the fps of the running game
but if you have

timer += Time.deltaTime;

then you have a timer which is independent of fps

loud mango
#

ooo

#

thanks! i will try it on the game

#

its running! thanks\

whole idol
#
using JetBrains.Annotations;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameOver : MonoBehaviour
{
    //public float lowerBoundsY = -5.98f; // position.y
    public BoxCollider2D mycollider;
    private bool isCurrentlyTrigger;
    public GameObject player;

    // we want this script to restart the game everytime somethign happens, also we want to define what a defeat is, and there has to be many 
    //types of defeat, like falling back, falling down etc. and then we wanna restart the player from where he was.
    void Start()
    {
        isCurrentlyTrigger = mycollider.isTrigger;
    }

    // Update is called once per frame
    void check_Death()
    {

        if (isCurrentlyTrigger == true)
        {
            Debug.Log("player touched the lava");
            //here we could use some animation or something
            //player dies
            Destroy(player);
        }
        else if (isCurrentlyTrigger == false)
        {
            Debug.Log("Player is flying in the air like normal");
        }
    }
    void Update()
    {
        check_Death();
    }
}

#

yoooooooo, why is this happening?

#

player is already Destroyed from Frame 1 😭 😭 😭

loud mango
#

bruh how

#

u set your bool to ur collider trigger

#

and from my guess u would have turned it on

languid spire
loud mango
#

dont complicate it.
just use

void onCollisionEnter2d(other collider){
if(other.gameObject.compareTag("Lava"){

    Destroy(gameObject);

}

#

add a tag called " Lava "

#

write this code according to the intellisense

#

i wrote it in discord

#

and put the script in player..... and try to understand ur code dude

#

u had a silly problem last time too

#

add this script to ur player movement script or the script that is in ur player. no need to create a new one

whole idol
#

other is a boxcollider2d object right?

#
public BoxCollider2D other;
modest dust
# whole idol yoooooooo, why is this happening?

Dear lord, please go follow a tutorial or read the docs to learn how how collisions work. You've already been told that mycollider.isTrigger is not what you want, and besides you only set a value to your boolean once, in Start

#

.isTrigger tells you whether the referenced collider is a normal collider or a trigger collider (kinda detection range as I said earlier)

modest dust
#

It has nothing to do with actual collisions taking place

whole idol
verbal dome
modest dust
eternal falconBOT
#

:teacher: Unity Learn ↗

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

verbal dome
#

Ah, seems like caesar explained it

whole idol
#

oh okay

languid spire
eternal falconBOT
#

:teacher: Unity Learn ↗

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

whole idol
#

this tutorial is kinda mid honestly, where does it explain Is Trigger for example?

verbal dome
#

Which tutorial are you talking about

#

The whole site?

whole idol
#

ye, the whole site

#

i dont get it

#

anyway, ill try to follow the tag technique

#

Mrc recommended

verbal dome
fervent mulch
#

Hey, before asking questions here, I want to ask this: Do you get angry with new people because you are constantly exposed to the same questions?

#

chatgbt gave me basic isGrounded code but doesnt work 😄

modest dust
fervent mulch
#

If I press the space key and press the space key again while in the air, the jumping animation works again.

modest dust
whole idol
#

https://youtu.be/HBCjCr-1_xo

anyway this tutorial looks good

In this video we will learn how to detect collision 2D in Unity.
OnCollisionEnter2D,
OnCollisionStay2D, And OnCollisionExit2D...

Enjoy the video ☕

————————————————————————————
🖐 Hi Game developer
Welcome to Rehope Games I'm Murat

I share unity tutorial videos on my channel. if you want to make a game with unity (especially 2d platformer...

▶ Play video
whole idol
#

docs is kinda hard to read honestly

#

video form is more engaging

modest dust
loud mango
loud mango
languid spire
eternal falconBOT
loud mango
fervent mulch
loud mango
#

oo

#

idk havent worked with animation logic for a long time

languid spire
fervent mulch
#

Can you suggest a way to prevent the jump animation from being used again after the character presses the space bar until he falls to the ground?

loud mango
#

when the player is not touching the ground play the animation once and dont press again until the player is on the ground and jumps again

fervent mulch
modest dust
loud mango
#

i think ur animation loop is enabled

#

check it in the animation its probably there

whole idol
fervent mulch
loud mango
#

try disabling loop

#

i see the problem

#

when u press space

#

it jumps and plays the animation correctly

hexed terrace
loud mango
#

but ur animation has loop animation enabled

loud mango
#

oh wait i think yeh

#

!code

eternal falconBOT
loud mango
#

it grows the first part of the plant when i interact with it

fervent mulch
#

already when i remove loop box jump aniamtion never play just going upward

loud mango
loud mango
#

check ur code

#

use a pen and paper or something and manually write what happens. like a tree or something

#

i do that a lot and it helps

modest dust
hexed terrace
loud mango
#

just trying get the gameplay

loud mango
fervent mulch
loud mango
fervent mulch
#

no

modest dust
#

Character Controller from what I can see.

#

Not familiar with it tho

loud mango
#

oh oops, didnt check the script

loud mango
hexed terrace
#

need to throw in a log and print out isGrounded see if it's still true when jumping or not

fervent mulch
#

i have only 3 script FPSController(from github) PlayerAnimation(from chatgbt) and groundCheck (from chatgbt)

loud mango
#

wait u are starting make a game for the first time right?

#

like u are new to it

fervent mulch
#

🤙 😄

loud mango
#

wdym by 🤙 😄

fervent mulch
#

i just trying walk animation run animation jump animation

#

not too much

loud mango
#

😂 i am making my 4th 3d game and i still havent added any animations.

#

i need to learn it

fervent mulch
#

its so hard bro

hexed terrace
#

If you're an actual student in education, you're doing yourself an injustice by using "AI" and if I (and many others in here) was your tutor , I would fail you for using "AI"

fervent mulch
#

there is no enaughly youtube tutorial videos

loud mango
#

but i swear to god, beans and cubes are the best models for every game

fervent mulch
#

walk run is easy but jump animation really really

rare basin
loud mango
#

there are enough yt vids on youtube

loud mango
#

i can find everything i want. u will too

hexed terrace
#

Calling a jump animation is no different than calling a walk/ run animation..

loud mango
#

when i started i used gpt too but then i realized that its not worth it

fervent mulch
hexed terrace
#

What about it?

loud mango
#

are u making a whole game or just learning animations?

modest dust
loud mango
fervent mulch
loud mango
hexed terrace
loud mango
#

finally i fixed the crop growing error notlikethis

oblique herald
#

its me again...
i have a function for selecting an item in my inventory, and I have a crafting system where user select 2 items in the inventory and it will show up on the craftingUI, but I want the user to only choose 2 items max, so I implemented an int of selected. When selected <= 2, then I can select and selected += 1, else I shouldnt be able to select. however when I tested it, it was like the photo shown. Below are my codes that I hope is relevant:

    public int selected = 0;

    public void OnPointerClick(PointerEventData eventData) {
        if (eventData.button == PointerEventData.InputButton.Left) {
            OnLeftClick();
        }
        if (eventData.button == PointerEventData.InputButton.Right) {
            OnRightClick();
        }
    }
    
    public void OnLeftClick() {
        if (selected <= 2) {
            selected += 1;
            Debug.Log("It has " + selected + " selected.");
            selectSlot();
        }
    }
whole idol
#

Not trynna be this guy again, but there is something really weird happening in my code which I dont undestand

whole idol
#

how the fuck am i instantiating new clone pipes if no Instantiate() us attached anywhere in any script in my gameobjects?

loud mango
#

ur code is simple so i alone can help

whole idol
#

lets look at deez prefabs

loud mango
whole idol
#

nope not here

#

not here either

#

not here either

loud mango
#

show script

whole idol
loud mango
#

not panel

whole idol
#

ok

#

now lets look at the script that some of these have

#

only script they got is a plain MoveLeft script

#

thats it

loud mango
#

show me the script that works with the pipe

whole idol
#

1 sex

#

I mean 1 second

#

sec

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

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

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

loud mango
whole idol
loud mango
#

wrong video

#

how could that happen then

whole idol
#

how the fuck does this happen?

green ether
#

did you save the script?

whole idol
#

yes

#

all of them

green ether
#

then there is another script

loud mango
#

yeh

whole idol
#

where?

loud mango
#

it cant clone unless its the code

#

show ur files

whole idol
#

I know

#

I have all these scripts

green ether
#

Depending how simple your hierarchy is just check every single GO and child for other scripts

whole idol
#

which I was experimenting with

#

im not even sure

#

I should had probably deleted some of them

green ether
#

I assume there is a PipeGenerator somewhere on a gameobject

whole idol
#

but at this point

#

I cant locate which one does the work

green ether
#

Alternatively search the hierarchy for the names of these scripts

loud mango
#

just recheck cloner and pip generator \

green ether
#

Search the Hierarchy for "Cloner" and "PipeGenerator"

#

i mean it could be in any of those scripts but just going off of the names thats where I would assume it is

whole idol
#

oh okay I found it

loud mango
#

lol

whole idol
#

It was emptyAbyss just playing hide and seek

loud mango
#

welp good luck with ur game

whole idol
#

sometimes Unity can be like searching for a hidden sock in the laundry

#

yep

smoky mauve
#

is there any way to use an int64

loud mango
#

dude

whole idol
#

looking for new things to add tho

#

😄

loud mango
#

ur game is still simple

#

;-;

whole idol
loud mango
#

its easy to manage

green ether
#

Things are always only exactly where you put them

whole idol
loud mango
#

i got like 10 scripts and total of 2k-2.5k lines of code

smoky mauve
loud mango
green ether
#

But its multiplayer/ networked so that adds alot

loud mango
green ether
#

I am in the middle of refactoring my whole game though so I am sure it will become less xD
When I wrote most of the code I was so much worse at programming than now

whole idol
loud mango
green ether
#

Adding it from the start is so much better

loud mango
#

can i disable any static variable to get changed again by a script

green ether
#

Took me a few weeks to get steam integration and public/ friend lobby finder to work

whole idol
loud mango
#

like disable bool X to be edited when bool Y is true

green ether
#

readonly

loud mango
loud mango
#

its like this

#

so when i reach the stage 4 of plant growing

green ether
#

So you want a variable that you can only change when some bool is true?

loud mango
#

or

#

no like

#

i just want the player to use E only once

loud mango
# loud mango

basically this script checks if the player presses E near a plant box and then start the plant growing process

#

oh wait i got it

green ether
#

Cant you just add a && plantCrop.timerIsrunning == false

#

to the if?

loud mango
#

yeh

green ether
#

But it wouldnt change anything right?

loud mango
#

add a bool at the start of the script that is true

#

make it so that if(raycast && boolx) then do stuff

#

when the stuff it does is plant and change boolx to false

#

so the if cant rerun

#

🤓

green ether
#

do it the other way around

#

if(boolx && raycast)

#

checking the bool is cheaper than the raycast

loud mango
#

but then i wanna add other stuff to the same script

#

i mean its not that heavy rn

#

but why not

whole idol
#

I deleted a GameOver script

#

and then I realized I needed that

loud mango
#

no

#

u dont

whole idol
#

and tried to skoop it back out of the recycling bin

loud mango
#

just add it in ur player movement script

whole idol
#

and now its corrupted and it doenst work

#

it deleted all its contents

loud mango
#

just use OnCollisionEnter2d

whole idol
#

ok

whole idol
#

ok cool, thankfully it didnt take that long to fix this time

loud mango
#

yeh its really easy

#

u can just add "Lava" tag or something like that in objects that will kill player on touch

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

public class GameOver : MonoBehaviour
{
    void OnTriggerEnter2D(Collider2D other) // Use 'other' as the convention
    {
        if (other.gameObject.CompareTag("Player"))
        {
            // Handle game over logic (e.g., destroy player, display game over screen)
            Destroy(other.gameObject); // Destroy the player on collision
            // Add code to display game over UI, reset level, etc.
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
        }
    }
}
loud mango
#

yeh

whole idol
loud mango
#

no wait

whole idol
#

what i fix kinda cringe about this is that whenever these pipes hit you in the face position.z goes perma negative by that amount

loud mango
#

wait

#

u did it wrong

whole idol
#

what?

#

there is a skylimit

#

i cant go above that

green ether
#

You should have one script on the player that checks in OnCollisionEnte

whole idol
#

and below that i die

green ether
#

not on all obstacles

loud mango
#

replace "player" with "killObject" or something

whole idol
#

if i touch the floor

loud mango
whole idol
#

oh true

green ether
#

Instead of Having GameOver on each obstacle, have one script on the player that check for collisions with objects with the tag "obstacle" or something

#

and then ends the game

loud mango
#

add a object that moves with ur background

#

and give the killObject kill tag and keep the object and the ground

#

that will act like lava

#

also i suggest u make the pipe height high cuz i can just go really high and then wont be able to die

whole idol
#

ok so only flying is safe now

loud mango
#

yeh

#

ofc

whole idol
#

all collisions kill player

loud mango
#

noh

whole idol
#

except if position.x goes too negative

loud mango
#

yeh

whole idol
#

away from the camera view

#

which is kinda weird

#

but will fix that later probably

loud mango
#

wait why would that happen

whole idol
#

maybe a limit to how far back it can go

loud mango
#

how could that happen

whole idol
#

oh wait

loud mango
#

the background will keep moving at a speed

whole idol
#

it cant happen

#

I just realized

loud mango
#

its not like u controll the player

whole idol
#

now pipes will you

loud mango
#

yeh

whole idol
#

so it will no longer be happening anyways

loud mango
#

nice

#

when u are done a small prototype upload it to https://itch.io

itch.io

itch.io is a simple way to find, download and distribute indie games online. Whether you're a developer looking to upload your game or just someone looking for something new to play itch.io has you covered.

#

mine is almost complete. just some polishing

whole idol
#

there is also a lava above his head

#

lol

loud mango
#

lol

#

idk if should be therew

whole idol
loud mango
#

i mean if the player doesnt come down

#

or wait

#

wait

whole idol
#

but that one doesn't have a GameOver script

#

so nothing happens if you touch it

loud mango
#

just add a cube instead of lava on the head

#

so the player just cant go higher

whole idol
#

its not lava, i just call bad things lava

loud mango
#

yeh the bad things

whole idol
#

😛

loud mango
#

my game rn is almost complete

whole idol
#

i just made a giant pipe

#

and then duplicated it

loud mango
#

single player, farming, zombie survival, day/night cycle

whole idol
#

and increased the size of them both

#

and named them lavas 😛

loud mango
#

just the menus are remaining

#

and some gui

whole idol
#

video?

loud mango
#

just a sec

whole idol
#

My favourite game is deceit

#

from steam

#

ive been playing too much of it and I originally wanted to make one game like that, multiplayer too. survival zombie multiplayer type game

#

it allowed me to meet so many friends and people all around the world, very voice chat oriented type of game too

#

I wanna make one game like that one day

loud mango
#

oh i will try playing it

#

i like zombie survivals

whole idol
#

have you finished any games?

loud mango
#

yeh

#

its not really good

whole idol
#

looks clean!

loud mango
#

i made it in a game jam

loud mango
#

ik whats causing it just that idk how to fix it

whole idol
#

holy.., does it increase in difficulty as time goes on?

loud mango
#

i have been thinking to stream my developing on twitch or yt

#

just to keep track

whole idol
#

so much nostalgia from these types of games

loud mango
#

i will add it to the currently 3d game i am working on

whole idol
#

I loved the old call of duty zombie survival modes

loud mango
#

yeh

#

my current game is kinda like that

#

and i wont add world building so that i dont have to work on world saving

#

lol

whole idol
#

how did you add the explosion animation graphics?

loud mango
#

welp thats " Unity's Particle System "

#

if u know how to use it, it can cure cancer and world hunger

#

but i just downloaded a asset from asset store

#

and edited a bit and made it play whenever my raycast hits an enemy, the particles will Instantiate() at hitpoint at a angle from which it got hit

whole idol
#

how much time can it take to make a basic explosion like that ? rather than download an asset from the store?

loud mango
#

man i learned raycasts in this project and its a life saver

loud mango
whole idol
#

raycasts you mean the invisible lazer things?

loud mango
#

cuzz i didnt wanted to learn

whole idol
#

for your aim?

whole idol
#

amazing

loud mango
#

yis

whole idol
#

was it hard?

#

i wanna learn that at some point too lol

loud mango
#

not really if u can understand the code

#

its the unity physics

#

its like OnCollisionEnter just with raycasts

plush igloo
#

Hi guys is this the channel I can ask for some code help or should I ask elsewhere?

whole idol
loud mango
whole idol
#

how

loud mango
#

it will shoot a raycast straight from the camera

#

if it hits something, it will check if its tag is "enemy" and it will damage it

whole idol
loud mango
#

using physical bullets is expensive as in fps and is not really nice looking

loud mango
whole idol
#

ohhhh, lol

#

I feel scummed xD

#

interesting tho, i like this idea

loud mango
#

the rifle cosmetics are scuffed but yeh

whole idol
#

nice

loud mango
whole idol
#

ohhh i see what you mean

plush igloo
#

I am having the following issue: "PlayerInput does not contain a definition for actions" I am not sure what else to add to this so please help me if you guys need additional information.

whole idol
#

it drags down the performance right?

loud mango
#

cuz u create many objects which have to be rendered and calculated

#

while using high firerate guns, it can be laggy

loud mango
whole idol
#

how do video games handle bullets then?

loud mango
#

i can show u a different way @plush igloo

loud mango
#

@plush igloo if u wanna jump when u press space your code can go like this

   ```
    if(Input.GetKeyDown(KeyCode.Space)){
        // code for jumping
    }```
#

here Input is a tool in unity

#

"GetKeyDown" will detect if a key is press

#

KeyCode.Space will detect if the key is space and run the jump code

plush igloo
#

oh I understand that part, I'm using the "new" input system so was trying different ways. I am just baffled why it is throwing me this error. went over the video 5 times to check and all is the same.

loud mango
#

i dont really use the input system u are using so i dont have any idea

#

@whole idol talk in dms, we were talking in code questions lol

loud mango
plush igloo
#

I will repost thanks bud

loud mango
#

yeh np

plush igloo
#

Hi guys! I am having the following issue: "PlayerInput does not contain a definition for actions" I am not sure what else to add to this so please help me if you guys need additional information. Reposted the question per MrcJoc's advice.

#

This uses the new unity input system

loud mango
#

tbh old one is better cuz u can use it from the script

#

so u dont have to go into different window

final kestrel
#

Hey all! Say I am inheriting a base class. Do I have to use all of its methods? Or can I just like use the ones I want only.

loud mango
#

show code and explain. ......

loud mango
green ether
#

Not sure if this helps you, i just recently started redoing my inputs in the new input system

#

But that works for me so far

loud mango
#

whats the difference

green ether
#

Controller support

loud mango
#

oooooooooooooh

green ether
#

But you dont have to use them

final kestrel
green ether
#

You can mark methods on the base class as abstarct, then you enforce each subclass to implement their own override for that method

loud mango
#

bruh, i cant understand this words. i can just see a code and can help lol

green ether
final kestrel
#

I mean the remaining two thats untouched.

green ether
#

can you send a code example?

final kestrel
#

hm no I'm not working on anything that just is out of my mind.

green ether
#

Ok let me type it out then

silk night
# loud mango but whyyy

The list of new functionality that the new input system offers is about as long as discord would allow to type a message, starting with controller support, built-in support for multiple players, different click types (hold, double click), mouse delta tracking, conversion of key-combos to a vector2 (WASD, arrow keys) and plenty more

green ether
#

Does that answer your question?

#

Not sure if the syntax is 100% correct

loud mango
#

what can i use in a if statement as a " or "

for example: if(1 = 1 && 2 + 2 = 4) {}

green ether
#

||

loud mango
#

instead of " and " i wanna use " or "

green ether
#

||

loud mango
#

ohki

#

thanks

final kestrel
green ether
#

You dont have to

#

You can

#

If you want to completely replace you dont do base.MethodX();

#

but if you want to keep logic of methodX in the baseclass and add new stuff on top then you do that

silk night
final kestrel
#

makes sense all right. So I got the method x. What happens if i dont override the method y and do not include it in the B class?

green ether
#

You can still call it on class B

#

like i did

final kestrel
#

Yeah I mean I can call but what if I dont call it?

green ether
#

Same as any method

final kestrel
#

Just exists then?

green ether
#

nothing happens

#

yeah

final kestrel
#

Aa okay okay it got me confused a bit

#

thanks for the thorough explanation!

green ether
#

You can also mark the methods as abstract to enforce overwriting them if thats something you want

#

Thats more like an interface then

final kestrel
#

Yeah I kinda get how it works when its abstract classes. I just get confused when the base method actually does something and I inherit that from another class.

ripe oyster
#

i want the mouse to able to be controlled only on the left side of the screen, i have trouble finding any information about it (most of the information is how to lock it to the center of the screen)
Is there a way to make borders that the mouse can't pass on one side of the screen?

silk night
ripe oyster
#

so the image can't pass the border, sounds good. (it's a game where you need to dodge stuff using the mouse so this might be perfect)
i'll see what i can do.

silk night
#

Oh an i think you need to the set cursor lock state

#

there is good documentation in the unity docs about that one

willow scroll
# ripe oyster so the image can't pass the border, sounds good. (it's a game where you need to ...
  • CursorLockMode.None: the cursor can move freely inside and outside of the game window
  • CursorLockMode.Confined: the cursor can move freely just inside of the game window unless Escape is pressed. This way the cursor can move outside of the window. Once the game window is selected by being clicked, the cursor is locked.
  • CursorLockMode.Locked: the cursor is fixed in the middle of the window
#

In your case, you don't want the player to be able to bass the border. This way you'll have to consider setting the cursor to Locked.

Cursor.lockState = CursorLockMode.Confined;
final kestrel
#

marking a method virtual means you can override it. Marking a method abstract also lets you override it. The difference is that abstract stuff do not have a body. What is the difference then?

buoyant knot
#

the first declaration of a virtual method is like a default implementation

green ether
#

You have to implement an override

#

In the inherited class

buoyant knot
#

abstract forces all children to have to override, and define their own thing from scratch

willow scroll
final kestrel
#

Ah okay that makes sense.

silk night
buoyant knot
#

you should only make a method virtual when you actually want all the children to have a basic version of the method to work with

#

that they all share in common

final kestrel
#

Like I cannot find any examples and it does not make sense as it is now

final kestrel
#

No I mean. Like an example where I want to run the base method then add more things to do in that method while overriding.

#

In the ovveridden method

willow scroll
#
// Foo.cs
protected virtual void Foo()
{
    print("Foo.Foo");
}

// Bar.cs
protected override void Foo()
{
    base.Foo();

    print("Bar.Foo");

    // =>
    // Foo.Foo
    // Bar.Foo
}
buoyant knot
#

i have public class Singleton<T> : MonoBehaviour
It has
protected virtual void Awake() {
that makes the singleton set up it single instance if it doesn’t exist, destroy if there is a duplicate etc

green ether
buoyant knot
#

then I define singeltons like
CameraController : Singleton<CameraController>
CameraController has its own Awake that it wants to call, but it also NEEDS to do the singleton Awake when it calls awake so the singleton can work

final kestrel
buoyant knot
#

so CameraController will have
protected override void Awake() {
base.Awake();
//Then camera controller stuff
}

green ether
green ether
willow scroll
green ether
#

the other inherited one will print

buoyant knot
#

i have many other classes that call base.Whatever, but the singleton is maybe the most generic

green ether
#

The logic will be the same

final kestrel
#

but yes I see now.

final kestrel
#

Thanks a lot for the answers!!

green ether
willow scroll
buoyant knot
#

basically, it’s when you want to like “keep adding more” to whatever method is there, but tie it to the same signature

green ether
#

Meant that it prints something additionally

willow scroll
final kestrel
buoyant knot
#

good luck

#

oh i also do that with initialize methods

green ether
#

Abtract methods are very useful for example for items when you f.e. want to use items. Each type of item will have its own logic for using it:
The base item class then has an abstract "UseItem()" method.

All inheriting classes must then implement their own using logic.

That way you dont have to do stuff like:

ìf (item is Weapon) ...
if (item is Tool) ...

You can just do

item.Use()

For example

final kestrel
#

Yeah abstract stuff seems simpler for me.

#

But I just want to learn thats all

final kestrel
buoyant knot
#

class 1 has public virtual void Initialize(…) { set up parameters in base class}
class 2 : class 1 then has
public override void Initialize(…) {
base.Initialize(…); // sets up parameters and crap in the parent
// Then set up things required for class 2
}

willow scroll
final kestrel
#

It is just confusing when I override and can optionally call the base method first then add some more stuff.

green ether
buoyant knot
#

base.MyFunction calls the function with the given signature in the base class

green ether
#

Was just the example of how not to do it

buoyant knot
#

base.MyFunc() looks to invoke MyFunc() of this particular instance, as looking for the definition in the base class.

willow scroll
# green ether yeah thats what the ... are for

Oh, I see, you're right. It doesn't make sense to use the variant I've shown if the Use method is in the base class, as calling it from the derived reference will give the same result.

buoyant knot
#

inherittance can be tricky. Interfaces might actually be simpler in a way

final kestrel
#

can you hold properties in interfaces?

buoyant knot
#

property yes. field no

#

an interface is like an abstract class with no fields, but you can “inheritt” (actually called implement) as many of them as you want. You can only inherit from one class

green ether
# final kestrel It is just confusing when I override and can optionally call the base method fi...
public class Tool{
  public virtual void UseTool(){
  // Logic that is for all tools. F.e.: Reduce Durability
  }
}

public class Pickaxe : Tool{
  public override void UseTool(){
    base.UseTool(); // you want to also reduce the durability here
    
    // Code for only Pickaxe logic. F.e.: break stone
  } 
}

public class Bucket : Tool{
  public override void UseTool(){
    // base.UseTool(); // You dont want buckets to loose durability, so you comment this out/ remove it
    
    // Code for only Bucket logic. 
  } 
}
#

a small example for the base.Method()

final kestrel
buoyant knot
#

so I can have something like:
public interface IDamageable {
public int CurrentHp {get;}
public void DoDamage(int damage);
}

#

any class implementing IDamageable must have a property called CurrentHp with a public getter that returns an int

final kestrel
#

I never did properties in Interfaces. Do I have to implement them as well?

final kestrel
#

It is amazing how you have many ways to do one specific thing. Its intimidating haha

buoyant knot
#
private int HP = 5;
public int CurrentHp => HP;
public void DoDamage(int damage) {
HP -= damage;
}
}```
#
public int CurrentHp => 1;
public void DoDamage(int damage) {
BreakChair();
}
private void BreakChair() { ….}
}```
final kestrel
#

oh nice so this how you would do it with interface all right.

buoyant knot
#

interface lets you handle things that have nothing to do with each other. but allows other things to act on/with them through the few parts they are guaranteed to have

final kestrel
#

I could just remove the property from the interface and hold them as fields in classes themselves and just do the logic on the implemented methods too right?

buoyant knot
#

yes. but then you can’t access it via that object when typed as the interface without downcasting

#

(and you really don’t want to spam downcasting nonsense)

#

so you should think hard about what your interface should actually have

final kestrel
#

ah okay. Thanks a lot for the help!

buoyant knot
#

in this case, IDamageable should NOT have a CurrentHp property, because it doesn’t make sense if I’m forcing that shit onto classes that don’t actually have HP

stuck palm
#

what is the non character controller equivalent of charactercontroller.move()?

rare basin
#

huh, weird question

loud mango
#

yeh

rare basin
#

your own move function

stuck palm
summer stump
faint osprey
#
        {
            if(Input.GetKeyDown(KeyCode.Escape))
            {
                Debug.Log("woking");
                onComputer = false;
                freeMove = true;
                StartCoroutine(ComputerCamTransition());
            }
        }```
i dont think unity is reading this properly as instead its just trying to tab me out the window
rich adder
faint osprey
#

tab me out of like game view

#

so like making my mouse appear

rich adder
#

nothing in this code does that 🤷‍♂️

faint osprey
#

yeah i know but thats what escape does in unity

rich adder
#

only in editor

faint osprey
#

yeah well im in the editor so how do i test it

rich adder
#

test it with another key?

#

switch it when building

#

if you unity didn't allowcursor unlock mouse would be stuck forever

faint osprey
#

true just seems really impratical

rich adder
#

yup only for esc button though

stuck palm
#

can you get a trigger point from on collision enter?

summer stump
stuck palm
rich adder
stuck palm
#

i see

summer stump
#

You can do some math using bounds I guess

rich adder
#

there are workarounds like using
ClosestPoint and a raycast

stuck palm
#

is on trigger when you are the trigger or when the other thing is a trigger

rich adder
slender nymph
#

yes

stuck palm
#

oh i need rigidbody

#

i forgot

rich adder
stuck palm
#

why isnt the sphere collidingg with the floor? both have a rigidbody and collider

polar acorn
#

How are you moving the object

stuck palm
#

im not using physics

polar acorn
#

You have to move the object with physics

stuck palm
#

ah

#

damn

#

so it has to be trigger then i guess

hexed terrace
#

no..

polar acorn
#

A trigger also would not work

hexed terrace
stuck palm
rich adder
#

by approximation but wont be totally accurate

stuck palm
#

i wanna hit this baseball around but rigidbody just doesnt work with it

#

can i move the rigidbody while its kinematic?

#

will that respect collisions?

rich adder
#

nope

#

why dont u just use velocity?

stuck palm
#

like rb.velocity or something

rich adder
#

yea

stuck palm
#

while its kinematic?

rich adder
#

no

stuck palm
#

will that work?

#

ffs

latent thorn
#

Does anyone know why when I start my 2D game the Y transofrm axis just keeps going up infinitely? ive tried looking at diff sollutions none of them are working

rich adder
#

kinematics dont have velocity

polar acorn
stuck palm
hexed terrace
polar acorn
stuck palm
#

i'll just use trigger then

latent thorn
#

what speicfic information would be relevant for this? im really new to unity

hexed terrace
#

well, what could be affecting the movement of an object?

latent thorn
#

I first looked at the movement script and disabled it but its still just going down indefinitely

latent thorn
#

my dumbass forgot to put the tilemap collider

#

thank you

stuck palm
deft grail
#

so its not an actual collider

stuck palm
#

thanks i didnt even see that

reef totem
#

how can i move a object back. and forth

#

ik it sounds really easy but i want to do it locally

#

like reletive to the objects rotation

summer stump
languid spire
#

then use
transform.position += transform.forward * new Vector3 (x,y,z);

reef totem
#

so it goes 5 units foward and the goes 5 units back

#

and it just reapeats that

summer stump
#

So use transform.forward and -transform.forward

#

And move it back and forth

reef totem
#

but how do i make it know when to go back after i go 5 units foward

languid spire
#

flip a bool

reef totem
#

but how do u identifly that it has gone foward 5 units

summer stump
#

Check position against a set "center"

reef totem
#

huh

summer stump
#

Keep track of how far it has moved

#

Lots of ways

reef totem
#

can u show me one

#

the one that would be affctive in this case

summer stump
#

I just told you two

#

I'm on my phone, so I'm not gonna write code

#

Might be easier if you make it a child object btw

reef totem
#

could u at least give me like a link something

summer stump
#

The parent would represent the center

reef totem
#

to some explination

summer stump
reef totem
reef totem
summer stump
reef totem
summer stump
# reef totem so how do i do this

Vector3 representing a center position
Check if you are over 5 units in front of it
Or over 5 units behind it
You can subtract one position from another and check the magnitude, or add the distance moved to a float and poll that float

languid spire
#
float dist = 5;
...
v3 = -v3;
position += forward * dist;
reef totem
#

is this what u mean or did i copt the code wrong

oblique herald
#

hi guys :D i have a silly question, but how do I link script? my phrasing could be wrong cuz i dont really know how to name this question
basically, I have a locked door, and I have a key in my inventory, how do I tell the script locking the door that I contain a key unlocking the door in my inventory script?

slender nymph
#

it sounds like you want to learn how to get a reference to another object. you can check this out to see different ways to get a reference: https://unity.huh.how/references

oblique herald
#

alright thanks :D

slender nymph
#

you cannot multiply two Vector3 together using the * operator since that operation is not defined. If you just want to transform a Vector3 to be relative to the object's direction just use transform.TransformDirection which will convert the direction from local space to world space

reef totem
#
position = forward * v3;
slender nymph
#

and it's wrong for the reason i already stated

reef totem
#

ok then how do i fix

languid spire
reef totem
#

ok

#

so like for the sake of simplcity ill just make it a random number and times it by time. delta time and ill see what happens

languid spire
reef totem
#

what about v3 = -v3

#

if these is no vector3

languid spire
#

obviously dist = -dist

reef totem
#
  float test= 2f; 
    void Update () 
    {
        test = - test;
        transform.position = transform.forward * test;
    }
#

does this work

languid spire
#

do += rather than =

reef totem
#

ok

languid spire
#

also - test looks wrong -test is better

reef totem
#

ok

#

nothing happens

#

the cube is just now stuck on the ground

languid spire
#

well you are doing this every frame which will mean it is moving so fast you cannot see it

reef totem
#

yea ik

#

so i do a corotine

languid spire
#

could do

reef totem
#

but still this code wont be local

#

like if the cube is roatetd will it still go foward and back

languid spire
#

why, using transform.forward will mean it will move in the direction it is facing

reef totem
#

wait i just noticed something in my code for the reason the float test is just 0

reef totem
#

and i cant just change it

#

it stays 0

#
 public float test= 2f; 
    void Update () 
    {
        test += -test;
        transform.position = transform.forward * test*Time.deltaTime;
    }
}
#

this is the code btw