#💻┃code-beginner

1 messages · Page 164 of 1

eternal falconBOT
swift crag
#

make sure you've followed every step in the VSCode instructions

meager steeple
#

is it possible to have text grow and shrink in a loop, a bit like the terraria logo

swift crag
#

sure. i'd just set its localScale

#
transform.localScale = Vector3.one + Mathf.Sin(Time.time) * 0.1f * Vector3.one;
#

this would go up and down between 0.9x and 1.1x scale

glass urchin
#

okay weird as soon as I signed in to Microsoft to use c# dev kit it started working

swift crag
#

that isn't necessary, but it might've caused your editor to restart

glass urchin
#

I had already restarted it

rotund garnet
#

Cant figure out what causes this error...

swift crag
#

This is Unity's fault. Just restart the editor and it should clear up.

#

something went wrong with a graph window (like the shader graph editor)

swift crag
#
Mathf.Sin(Time.time * Mathf.PI * 2)

This would cycle once per second.

meager steeple
#

so the scale is going from 0.9 to 1.1 what if i want it to vary at a bigger number, like from 2.9 to 3.1

swift crag
#

more generally

#
transform.localScale = baseScale + Mathf.Sin(Time.time) * scaleRange * Vector3.one;
#

where baseScale is a Vector3 and scaleRange is a float

#
Vector3 baseScale = Vector3.one * 3;
float scaleRange = 0.1f;
#

e.g.

meager steeple
#

right thank you so much

glass urchin
#

I wanna create a HingeJoint using a script, but it won't let me set the attached gameObject because it's readonly

swift crag
#

you can't set the gameObject property of a component

#

that's also irrelevant when setting up a hinge joint

#

a hinge joint is attached to a rigidbody or an articulation body

glass urchin
#

oh right

daring stream
#

Hello everyone! I wanted to ask, how can I display a character's health using TMP? I've figured out the part where I can change the UI text to whatever i want through code. But I can't figure out how to change the Health float to a string that only shows the Health without any decimals. So basically as an integer

languid spire
#

ToString("N0")

signal narwhal
#

Or do health.text = "Hp: " + health;

polar acorn
#

They want to display it as an int with no decimals. You'd need to use a ToString formatter for that one

signal narwhal
polar acorn
#

Again, that would just display the entire number. Nothing there converts it to int or rounds it or drops the decimals

signal narwhal
#

Oh nvm i thought the health float was an int

rocky canyon
#

ToString() = no decimals ToString(F1) = 1 decimal, and so on

amber spruce
#
players = GameObject.FindGameObjectsWithTag("Player");

is it possible to have that also add objects that are disabled that have the tag Player

meager steeple
#

how would you change a button's properties on hover, would it have to be code or could you do it in a simpler way?

half patrol
#

Hello, beginner here so i face this issue. When player is jumping he falls down like in a picture. how to prevent this? it's rigidbody2d

`public class Player : MonoBehaviour
{
private float moveForce = 10f;

private float jumpForce = 11f;

private float movementX;

private Rigidbody2D myBody;
private Animator anim;
private SpriteRenderer sr;

private string WALK_ANIMATION = "Walk";

private bool isGrounded;
private string GROUND_TAG = "Ground";

private void Awake()
{
    myBody = GetComponent<Rigidbody2D>();
    anim = GetComponent<Animator>();
    sr = GetComponent<SpriteRenderer>();
}

void Start() { }

void Update()
{
    PlayerMovementKeyboard();
    AnimatePlayer();
    PlayerJump();
}

void PlayerMovementKeyboard()
{
    movementX = Input.GetAxisRaw("Horizontal");
    transform.position += moveForce * Time.deltaTime * new Vector3(movementX, 0f, 0f);
}

void AnimatePlayer()
{
    if (movementX > 0)
    {
        anim.SetBool(WALK_ANIMATION, true);
        sr.flipX = false;
    }
    else if (movementX < 0)
    {
        anim.SetBool(WALK_ANIMATION, true);
        sr.flipX = true;
    }
    else
    {
        anim.SetBool(WALK_ANIMATION, false);
    }
}

void PlayerJump()
{
    /*
        adding force to rigidbody using vector to tell player to jump in 2D
        ForceMode2D.Impulse tells it to use force right away
    */
    if (Input.GetButtonDown("Jump") && isGrounded)
    {
        isGrounded = false;

        myBody.AddForce(new Vector2(0f, jumpForce), ForceMode2D.Impulse);
    }
}

private void OnCollisionEnter2D(Collision2D collision)
{
    if (collision.gameObject.CompareTag(GROUND_TAG))
    {
        isGrounded = true;
    }
}

}`

amber spruce
eternal needle
amber spruce
amber spruce
half patrol
eternal needle
#

What's the use case?

amber spruce
# eternal needle What's the use case?

im trying to have them be disabled until they select their character so when they spawn in i disable them and when they select their character i reenable them

amber spruce
half patrol
# amber spruce

btw, disabling it from unity engine is enough right? i dont have to do this in code

amber spruce
half patrol
amber spruce
#

your welcome

eternal needle
amber spruce
#

wait it does

#

how can i acces it

eternal needle
#

I'm not on my pc, google should lead you from here

glass urchin
#

how to remove the red lines???

eternal needle
#

I forgot exactly where it is

glass urchin
#

it keeps saying im not using mscorlib and shit

swift crag
#

I think your editor threw up

#

VSCode sometimes does that for me

#

It completely loses the plot and can't recognize anything

#

give it a restart

glass urchin
#

ahhhh

#

it almost worked then it didnt

#

is there a way to check collisions outside of the collision system? like to check discretely if two specific trigger colliders are intersecting on load?

#

the animator not playing nice with the physics engine is starting to piss me off

daring stream
swift crag
swift crag
#

the field initializer runs once when the object is constructed

#

that doesn't sound like you want anyway

#

you want to set the text constantly

#

health.text = "Hp: " + health; will work just fine in Update

swift crag
robust kelp
#

is it possible to replicate source engine stafing in unity using rigidbody?

glass urchin
swift crag
#

I'd just store the values into variables and then pass those variables in, as the example shows

glass urchin
#

So if I have a bunch of colliders and I need to check which ones intersect which ones should I just have one script in the parent that checks all instead of a script in each gameobject that has the colliders?

swift crag
#

I suppose that's how I'd do it, yes.

rocky canyon
#

ya, keep ur logic tight

glass urchin
#

my aim is for each collision on load, I create a new empty and attach the newly created empty to both game objects by a hinge joint. just dont wanna do the entire area of this level manually

rocky canyon
#

if u have a problem much easier to debug a singular script vs 3 or 4

daring stream
glass urchin
#

this is something I can do manually but I want to be able to adjust all variables on the fly

long scarab
#

Is there a way to change Button state to selected or other color tints in code?

#

I looked at some documentation

#

can't find any

#

maybe I should use a toggle insted 🤔

rocky canyon
#

https://gist.github.com/SpawnCampGames/f854b2e0313aa0fcaeefe619dd429f53
Hello, I've been working on this setup for a while, and i finally got it working somewhat how i want..

  • when you single click on an object (if its selected it gets deselected and vice versa)
  • when you click and hold (on the object) (if its selected we open a menu)

so far i have this raycast that detects if its selectable (using an interface)

  • when we first click we get teh object so we can check wether or not its selected
  • this also triggers the (holdingAction) so we can decide whether we release early (short click) or release it later (long click)
    The dragging feature is where I'm stuck.. b/c I need a way to know whether or not we are dragging the mouse (away from the selected unit)

but I have the mousebutton down (which starts the raycast) so I'm a bit confused on where or how would be the best way to do it..
The initial MouseButtonDown (is on line 73)
The Raycast in which the stuff starts happening is on line 149
The Raycast sets the booleans which are monitored in the update

sorry, theres so much information in here, I just wanted to explain it thoroughly..
any questions, suggestions, or follow-ups you can ping me

rocky canyon
long scarab
#

I just wanted to change its colour

#

so basically a toggle haha

#

but thanks for reply!

#

already writing listener for toggle 😄

glass urchin
#

if a capsulecollider is on the x axis does that mean the quaternion is identity?

#

or is that the y axis?

#

or is it always identity unless changed?

swift crag
#

A capsule collider on an unrotated object will align with the Y axis

glass urchin
#

I set mine to X

swift crag
#

oh right, you can change it

glass urchin
#

does that change the rotation?

#

since the axis is a propety of capsule collider?

swift crag
glass urchin
#

okay

swift crag
#

Unity just needs to know how the collider's object is positioned and oriented

#

similarly, I don't think you need to do anything with the Center of the collider

glass urchin
#

so then assuming the colliders intersect, I need to check if I already created an empty that collides with them, since each empty will be connecting to up to 4 rigidbodies

#

is this considered complex?

rocky canyon
#

lol, how do you feel about it

swift crag
#

sounds like it could become a giant headache very quickly.

I would first build a list of all rigidbody-rigidbody pairs, then create joints on them afterwards

rocky canyon
#

ya, i was gonna say, id try to get it working quickly.. and not touch anything afterwards 😄

swift crag
#

separate the "finding pairs" logic from the "connecting pairs" logic

rocky canyon
#

but keeping a list is def smart

swift crag
#

this will also let you manually define pairs if you want to

#

also, I'd suggest just making a method that checks for an overlap and nothing more

glass urchin
#

I'm testing my script with just a set of 4

#

Well, yes, but idk how to STORE those pairs

rocky canyon
#

multiple colliders and multiple physics calls can get very hard to debug..

long scarab
#

I made a custom class for my pairs

rocky canyon
#

just try to keep ur stuff straight

glass urchin
#

I have 4 days and I have more to do after this area.

swift crag
#
public static bool TestOverlap(Collider first, Collider second) {
  return Physics.ComputePenetration(
    first, first.transform.position, first.transform.rotation,
    second, second.transform.position, second.transform.rotation,
    out var _, out var _
  );
}
#

now you have a nice simple TestOverlap method

glass urchin
#

why position and not localposition?

rancid tinsel
#

im wondering if the way im coding here could cause a bug if the player was to purchase an upgrade that increases their attack speed while the coroutine is running?

swift crag
#

you're asking "would these two collider overlap if they were positioned and rotated in this way?"

#

you tell it the world position of the colliders

rancid tinsel
#

cuz im assuming it would take the A value of the variable and count down those seconds, while ignoring the new value B

rancid tinsel
#

yeah i thought so

#

thanks

swift crag
#

I wouldn't consider that to be a huge problem

#

you already shot the weapon

rocky canyon
#

nah, the player wouldnt even notice i bet

swift crag
#

the upgrade will kick in next time you fire

rocky canyon
#

or be buying upgrades and shooting at the same time anyway

swift crag
#

Ah, I do see the problem though

hard hornet
#

you could also do StopCoroutine() when you buy an upgrade

swift crag
#

The sprite wouldn't match the actual ready state of the weapon

glass urchin
#

what's out var _?

swift crag
#

Why not just make the sprite change based on timeUntilFire?

swift crag
#

You can declare the variable as part of the function call by including a type

wintry quarry
rocky canyon
#

i think _ just means default

swift crag
#

I used var, since it's obviously a float

#

float would also be fine

rancid tinsel
swift crag
#

and then since I don't care about the result, I use _

rancid tinsel
#

i might just do that but i want to test which one feels better

swift crag
#

_ is used when you don't actually want a variable

glass urchin
#

okay

#

so it discards the minimal orientation and distance?

long scarab
#

as in GC

swift crag
#
public void SetToThree(out float result) {
  result = 3;
}

void Foo() {
  float myVar = 0;
  SetToThree(result);
  Debug.Log(myVar); // "3"
}
swift crag
#

i don't know exactly what the compiler will do

#

there's also no real reason to worry about that

rocky canyon
#

its just a float, or bool.. yea GC doesnt matter in that case

rancid tinsel
#

there are 2 sprite renderers in children, any way to specify which one?

swift crag
#

we can't just leave the parameters out

swift crag
long scarab
#

so what is the difference between using _ and using proper variable

swift crag
long scarab
#

true haha

rocky canyon
#

every time

rancid tinsel
#

is there a different thing i can use to achieve what i want?

rocky canyon
#

u could use the plural version to get all of them.. and then ud have to do another check to get the right one

#

else id use a different method of finding it..

#

using a blank Monobehaviour as a tag.. or using a regular unity tag

glass urchin
#

it says no bc its c# 6.0

swift crag
#

not "get two sprite renderers"

swift crag
rocky canyon
#

and search for it first.. and then grab the component from the one u know its from

glass urchin
#

2017.4

swift crag
#

aeugh

#

okay, just use out float whatever or something

rancid tinsel
glass urchin
#

that cant change

swift crag
rancid tinsel
#

the tower is basically split into the background and then the bit that rotates

swift crag
#

If you can assign the reference manually, just do that

#
[SerializeField] SpriteRenderer rotatingPart;
#

drag the sprite renderer in and you're golden

rocky canyon
#

^ best bet

rancid tinsel
#

it will be a prefab so i dont think i can do it manually

swift crag
#

sure you can

#

do it in the prefab

rocky canyon
#

if its inside the prefab

rancid tinsel
#

ohhhh

#

right

#

got it

rocky canyon
#

then thats all that matters

swift crag
#

prefabs would be useless if you couldn't assign intra-prefab references

rocky canyon
#

that would suck

rancid tinsel
#

so i dont need the Start() function all together

glass urchin
rancid tinsel
#

since i just assign it in inspector?

wintry quarry
# rancid tinsel got it

Best practice is never to really reach "inside" other objects like that anyway. Put a script on the root of the prefab. Give that script the references (to inside itself). And have external code only interact with that script.

swift crag
#

okay, just declare two float variables before you call ComputePenetration

#

and then pass them in as , out var1, out var2);

glass urchin
#

its vector3 and float

swift crag
#

ah, then Vector3 and float :p

rocky canyon
#
var var1 = Vector3.zero;
var var2 = 0f;```
#
Vector3 var1 = Vector3.zero;
float var2 = 0f;```
glass urchin
#

still not working

#

how do I do that

rancid tinsel
#

is this a good workaround to the player buying more attack speed during the animation?

glass urchin
#

says its already defined in this scope

swift crag
#

show me your code

#

i have no idea what you've written

glass urchin
rocky canyon
#

lol...

swift crag
#

Do not include the types.

#

That's trying to declare new variables named var1 and var2

#

also, your IDE is having a meltdown right now

rocky canyon
#

lmao i'd say

glass urchin
#

I know

swift crag
#

try regenerating project files from the External Tools menu and restarting the editor

rocky canyon
#

i can't really tell whats kicking off the red squigglies

swift crag
#

the editor forgor about every single type

#

VSCode does that to me occasionally

rocky canyon
#
Vector3 var1 = Vector3.zero;
float var2 = 0f;

public static bool TestOverlap()```
#

hehe, w8 that wouldnt make them error

swift crag
#

there's no reason to declare them outside of the function

glass urchin
rocky canyon
#

yea lol idk im just hunting for error (if there is one)

glass urchin
#

when I go to assign it to the output of TestOverlap it says it doesnt exist in the current context

swift crag
#

you're going to continue seeing a huge pile of errors because of this IDE problem

rocky canyon
#

why would bool be underlined?

#

yea.. the IDE is drunk

glass urchin
#

I mean in Unity

#

Unity says it doesnt exist

swift crag
#

if it's not defined in the same class, that won't work

glass urchin
#

in the same class

swift crag
#

Show me the entire script.

rocky canyon
#

can u share the entire class

#

yea, context would help

swift crag
#

I need to actually see what you're doing.

#

!code

eternal falconBOT
gaunt ice
#

probably mismatch {}

rocky canyon
#

possible

swift crag
glass urchin
#

its not much I can paste it here how do you do that thing?

swift crag
glass urchin
#
// using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Analytics;

public class WebConnectorScript : MonoBehaviour {

    // Use this for initialization
    GameObject[] empties;
    void Start () {
        // GameObject[] childrens = GetComponents<GameObject>();
        WebPieceScript[] webpieces = GetComponents<WebPieceScript>();
        for(int i = 0; i < webpieces.Length; i++) {
            Transform transform = webpieces[i].transform;
            CapsuleCollider[] colliders = transform.GetComponents<CapsuleCollider>();
            CapsuleCollider trigger;
            foreach (CapsuleCollider C in colliders) {
                if (C.isTrigger == true) trigger = C;
            }
            for (int j = i+1; j < webpieces.Length; j++) {
                Transform transform1 = webpieces[j].transform;
                CapsuleCollider[] colliders1 = transform.GetComponents<CapsuleCollider>();
                CapsuleCollider  trigger1;
                foreach (CapsuleCollider C in colliders1) {
                    if (C.isTrigger == true) trigger1 = C;
                }
                bool doesIntersect;
                doesIntersect = TestOverlap(trigger, trigger1);
                if (doesIntersect==true) {
                    Debug.Log("Piece "+i+" and Piece "+j+" intersect");
                } else {
                    Debug.Log("Piece "+i+" and Piece "+j+" do not intersect");
                }
            }
        }

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

    private bool TestOverlap(CapsuleCollider first, CapsuleCollider second) {
  Vector3 var1 = Vector3.zero;
  float var2 = 0f;
  return Physics.ComputePenetration(
    first, first.transform.position, first.transform.rotation,
    second, second.transform.position, second.transform.rotation,
    out var1, out var2
  );
}
}
swift crag
#

okay we really need to get this IDE fixed

#

this needs an auto-format

glass urchin
#

how?

swift crag
glass urchin
#

the currrent error in unity btw:

#

I opened the script from unity and restarted vscode

#

idk what else you could mean

swift crag
#

Do you not understand what this means?

#

try regenerating project files from the External Tools menu

glass urchin
#

in Unity?

swift crag
#

Yes.

#

In Unity.

#

You had to go to that menu when setting up VSCode to work with Unity.

rocky canyon
#

heres some formatting

glass urchin
#

I did I think

swift crag
swift crag
#

the variables absolutely exist

#

It's just possible for your code to not set anything

#

You could initialize both to null

rocky canyon
swift crag
#

this is ancient unity

glass urchin
#

Unity 2017.4

swift crag
#

so it may be different

rocky canyon
#

lol facts

swift crag
#

I'm not sure if you can even get a working editor now

#

maybe with Visual Studio

swift crag
#

trigger may still be unassigned after this code runs

#

Hence the error.

glass urchin
#

oh well it will be

swift crag
#

doesn't matter. the compiler is not convinced.

rocky canyon
glass urchin
#

screw the compiler

swift crag
#

If you're certain that a collider will be found, then initialize the variables to null

glass urchin
#

null check incoming

swift crag
#

no, this has nothing to do with checking for null

glass urchin
#

why?

swift crag
#

CapsuleCollider trigger;

This variable is not initialized.

rocky canyon
#

lol ya thats what chatgpt said 😄

swift crag
#

It doesn't contain null. It has no meaningful value at all.

rocky canyon
#

"here i added some null checks for you"

swift crag
#

Attempting to read trigger is an error.

shrewd swift
glass urchin
#

cool compiler is happy

swift crag
rocky canyon
swift crag
#

it would be worthwhile to test if they're null right before you use them

rocky canyon
#

thats why i didnt post the changed code.. i just wanted it to reformat (i know it does that decent)

swift crag
#

but that's not why the compiler is mad

glass urchin
#

andddd debug printed nothing

rocky canyon
#

unreachable perhaps

shrewd swift
#

Does it print if null ?

#

Try printing (yourObject == null)

#

Unity doesnt print by default all stuff from my experiences

gaunt ice
#
Transform transform1 = webpieces[j].transform;
CapsuleCollider[] colliders1 = transform.GetComponents<CapsuleCollider>();
```no idea why you get colliders on same tf again
rocky canyon
glass urchin
#

Debug.Log

rocky canyon
#

i was askin Fishy, but ya Debug > Print

glass urchin
#

I used the wrong method

#

getcomponents not getcomponentsinchildren

#

so should I cache each set that intersects? can you make an array that contains arrays?

rocky canyon
#

why not make a struct or a class that contains w/e u need and just keep an array of those instead?

glass urchin
#

struct?

rocky canyon
#

sounds like ur trying to complicate it even more..
struct.. like a data holder

glass urchin
#

I think I did that in UE4 once but it was visual coding

shrewd swift
glass urchin
#

I wanna do it all in the Start method with not too much complex stuff

rocky canyon
#
public struct MyData
{
    public int intValue;
    public float floatValue;
    public string stringValue;
}```
glass urchin
#

a struct can contain arrays?

rocky canyon
#

but since u probably wanna store colliders/ and stuff like that may jsut make a class

wintry quarry
glass urchin
#

The script is a class.

#

I have a script on each game object that I'm trying to connect

shrewd swift
#

Sometimes idk if i should make a class or struct

#

They have a lot of similarities

wintry quarry
#

as a beginner you're probably better off using a class almost always

rocky canyon
#
public class MyData
{
    public Collider collider1;
    public Collider collider2;
}```
```cs
  // Create an instance of MyData
  MyData myDataInstance = new MyData();

myDataInstance.collider1 = blabla; myDataInstance.collider2 = blabla;

#

something along these lines.. u should get the idea

shrewd swift
#

I have the reflex to always do structs

rocky canyon
#

the way i see it is.. if i want to use Unity stuff (the components) i use a class

shrewd swift
#

Im probably shooting myslelf in my toes

rocky canyon
#

if its just data.. like numbers only id use a struct

rocky canyon
#

but thats just my personal workflow

glass urchin
#

then I can make an array of MyData structs?

shrewd swift
#

Yes

#

Maybe a list here if its changing at runtime

rocky canyon
#

since ull be adding to it u may want to use a List<> vs an Array

wintry quarry
glass urchin
#

List?

rocky canyon
#

its just a class.. same as u make a list of any other class..

    List<MyData> myDataList = new List<MyData>();```
glass urchin
#

List<MyData>?

rocky canyon
#

well <NameOfScript>

#

so if u had a class called ColliderData it'd be List<ColliderData>

#

but since my example was of MyData i just used that

glass urchin
#

can I declare it inside my current class?

#

or at least in the same script?

rocky canyon
#
  • Setup a class that holds the data you want

  • When you want to add that to the list you create a new one
    MyData myDataInstance = new MyData();

  • then you can set the values..
    myDataInstance.collider1 = whatever;

and then you add that to the list
myDataList.Add(myDataInstance);

rocky canyon
swift crag
#
public class SomeClass {
  public class AnotherClass {
    public int x;
  }
}
#

inside SomeClass, you can refer to AnotherClass directly

rocky canyon
#

^ so now im 100

swift crag
#

Outside of SomeClass, you refer to it as SomeClass.AnotherClass

#

It's useful for classes that are strongly associated with the containing type

#

for example, I have several "pickers" that use a set of criteria to decide what to do

#

each one declares a Criteria struct inside of it

#

although this is actually a no-no according to microsoft; they want nested classes to be private

#

too bad, Redmond! i'm doing it anyway!

glass urchin
#

can a method call itself?

swift crag
#

sure

rocky canyon
#

no..

swift crag
#

that's called recursion

rocky canyon
#

lol i mean.. it can

#

but then u get a infinite loop

swift crag
#

recursion can elegantly solve some problems, but you're also responsible for preventing infinite recursion

glass urchin
#

I just want to call it 4 times to get the 4 collider checks then once I have 4 to return

rocky canyon
#

oh then as long as u stop it thats fine

glass urchin
#

or once I've exhausted the list

swift crag
#

sounds like method A should be calling method B

rocky canyon
#

ya, a for loop or foreach loop can do that

glass urchin
#

because I don't want to look at 4 nested for loops

rocky canyon
#

at this point i think you're trying to make ur setup as complicated as possible

#

Colliders check within itself, an array of an array, and now a recursive method..

warm condor
#

hey, can anyone tell me why when I press shift and "D" or "A" at the same time, I start at maxRunningSpeed? I there maybe a problem with the if statment?

        accilerate(direction);
        limitMaxRunningSpeed(direction);
        playerAnimator.SetBool("hasStopedRunning", false);
    }
    private void accilerate(int direction){
        if (Input.GetKey(KeyCode.LeftShift) ){
            initialiseAccelirationRunningValues(direction);
            accelerateBeforeRunning(direction);
        }
    }
    private void initialiseAccelirationRunningValues(int direction){
        if (Input.GetKeyDown(KeyCode.LeftShift)){
            speedDuringRunning = Math.Max(initialHorizontalSpeed, walkingSpeed);
            time = timeItTakesToFinnishAcceliration;
        }
    }

    private void accelerateBeforeRunning(int direction){
        if (time > 0f && speedDuringRunning < maxRunningSpeed){
            time -= Time.deltaTime;
            speedDuringRunning += accelirationValue * Time.deltaTime;
            rb.velocity = new Vector2(direction * speedDuringRunning, rb.velocity.y);
        }
    }
    private void limitMaxRunningSpeed(int direction){
        if (speedDuringRunning >= maxRunningSpeed){
            rb.velocity = new Vector2(direction * maxRunningSpeed, rb.velocity.y);
        }
    }```
rocky canyon
#

🤣 got me tripping over here

rancid tinsel
#

is there a simple way to make a 2D object face another 2D object?

#

i tried doing LookAt with a vector3 z = 0 but it just makes it disappear

wintry quarry
#

Use a paste site

warm condor
#

what site?

wintry quarry
wintry quarry
eternal falconBOT
rancid tinsel
warm condor
#

hope this works

rocky canyon
rancid tinsel
rocky canyon
#

mmhm but use praets method

#

its a solid way to get the direction

rancid tinsel
#

i know in general its bad practice to use LookAt in 2D

#

i was just hoping it would work but the solution was so simple literally just transform.up = target.position - transform.position;

rocky canyon
#

well transform.up or transform.right

#

make sure u use the right one 👍

rancid tinsel
#

.up in my case since its an arrow pointing upwards 🙂

rocky canyon
#

cool 👍

#

visual

vale bronze
#

how do I make a gameobject rotate towards my mouse to always be pointing at it? i've tried like 10 different things but no code works as I want it to.

wintry quarry
#

there's a lot of code here, I looked for a little but can't identify the problem, there are a ton of very long named functions here.

warm condor
#

yea sorry about that 😅

glass urchin
#

can i instance a list as null and still add to it?

wintry quarry
#

if you instantiated the list, it's not null

#

you can make an empty list, yes.

warm condor
#

wait @wintry quarry, could it be because because limitMaxRunningSpeed() is being called imidiatly instead of starting with the accilerate function?

wintry quarry
#
List<Whatever> myList = new();```
swift crag
#
  • use Quaternion.LookRotation to get a rotation that faces a certain direction
  • use Quaternion.RotateTowards to steadily rotate from one rotation to another
#

Is this a 2D game?

wintry quarry
vale bronze
#

nevermind, Camera.main wasn't working because I had a script called Camera...

swift crag
#

woops

swift crag
#

common error

swift crag
#

since you don't want to rotate an object's forward vector to face something

#

in 2D, the forward vector points into the screen

smoky niche
#

Hey there, is it possible to add two LayerMasks at once when doing Raycasting.
I have 2 LayerMasks which should both be detected by the ray, but apart from these rays, the LayerMasks don't have anything in common and I wouldn't want to make a separate LayerMask for them if not needed

swift crag
#

You can use | to union two layermasks together

#

| is the bitwise OR operator.

wintry quarry
#

you cannot use two separate masks

glass urchin
#
SetOfColliders set;
set.collider1 = trigger1;
set.collider2 = trigger2;
set.collider3 = trigger3;
set.collider4 = trigger4;
ListOfSetsOfColliders.Add(set);
wintry quarry
#

just use one mask that contains both layers

#

public LayerMask myMask; < add both layers in the inspector

smoky niche
#

Does that not work?

rocky canyon
#

ur making a new class
adding ur colliders to it.. and then adding it to ur list

wintry quarry
smoky niche
#

Awesome, thanks!

rocky canyon
#

you'll have (2) sets

glass urchin
#

i dont get it

#

doesnt it change set each time and add a new one?

rocky canyon
#

no.. when it runs the 2nd time.. its gonna set.collider1 =

#

its gonna overwrite what ur set already had

glass urchin
#

im completely confused

#

overwrite the set in the list or just the set?

rocky canyon
#

set.collider1 = <--- thats gonna set collider1 in teh class u have named set

glass urchin
#

It's .Add so doesn't it always prevent overwrite?

rocky canyon
#

when u run it again.. its gonna set collider1 in the class u have named set

#

same class... same name..

glass urchin
#

the class name is SetOfColliders

rocky canyon
#

it's gonna overwrite it

#

yea.. but ur using an instance of that class called set

glass urchin
#

uh huh

rocky canyon
#

u called it set

glass urchin
#

yes

rocky canyon
#

ya,,, so next time ur gonnna be using the same reference

#

do u not need different versions?

#

that code is gonna set the same colliders on the same set

#

over and over

#

each time u run it

glass urchin
#

no because

rocky canyon
#

ya, its gonna say "remember set?"

glass urchin
#

my for loops are indexed with i, j, k, and l

#

they are nested

rocky canyon
#

"yea change the variable of that again`

glass urchin
#

listen

rocky canyon
#
        SetOfColliders set = new SetOfColliders();
        set.collider1 = collider1;
        set.collider2 = collider2;
        set.collider3 = collider3;
        set.collider4 = collider4;

        listOfSetsOfColliders.Add(set);```
glass urchin
#

they are nested, and j starts at i+1, etc.

rocky canyon
#

i get that..

glass urchin
#

so each for loop only checks higher value indices

rocky canyon
#

but its still calling set.collider1 = thast always the same variable

#

ok, maybe i dont understand, ignore me then lol

glass urchin
#

!code

eternal falconBOT
rocky canyon
#

but i use the new keyword.. so it makes a new version of SetOfColliders

glass urchin
rocky canyon
#

okay, that may be fine.. i thought u were calling a function multiple times

#

but its all in start

jovial sandal
#

Does some1 have any idea how i can make the shotgun from knockback like karlson

wintry quarry
#

Add a force to your player object (assuming it's a Rigidbody)

rocky canyon
#

ur shotgun should face a certain direction.. if u negate that direction (-direction) u get the opposite direction

#

then u can apply that to the player

#

-shotgunsTransform.forward; <-- the opposite direction

jovial sandal
#

Okey what if i am using a charcter controller

rocky canyon
#

then u got to add taht force into ur Move() function

wintry quarry
rocky canyon
#

add it to ur vectors or w/e

wintry quarry
# jovial sandal Can i use this?

you can of course use that to get the direction but the actual handling of adding a force to the player will need to be written from scratch

#

and your movement code will need to be aware of it

#

basically you'll need to have an internal concept of velocity and forces in your player controller.

shell herald
#

two questions. i cant seem to hide my cursor. in the unity docs it states that a simple

Cursor.visible = false;

should do the trick, but for me, the visible doesnt seem to exist

also, in the new input system, if i use Any Key [Keyboard]that includes the esc key right? what do i need to do in order to exclude it?

glass urchin
rocky canyon
#

it really is that simple..

glass urchin
#

oh in game

rocky canyon
#

if its set to false.. when u click into the game window it should vanish

#

and u can test if its the escape key

shell herald
#

maybe im massively misunderstanding something, but this doesnt seem to work. atleast i get an error in VS and inside unity

rocky canyon
#

if (Input.anyKeyDown && !Input.GetKeyDown(KeyCode.Escape))

languid spire
#

visible

rocky canyon
#

well.. its not spelled right 😄

shell herald
#

even if it is

languid spire
#

do you have your own class/struct called Cursor?

shell herald
#

that might be it

rocky canyon
#

or rename ur Cursor to something more "custom" CustomCursor.cs maybe

#

don't forget to rename the class name inside the script also..

shell herald
#

yeah i simply changed the class since it was a non used script anyway

rocky canyon
#

did u see the way to check for escape key?

echo matrix
#

hey, is there a way to transform the postion of an object only on one axis and leave the other 2 as they are?

frosty hound
echo matrix
#

problem is my game object is moving

#

i currently have a transform.postition moving it at a set speed to the right

now i want to have a public float giving it its hight while moving (instantly)

frosty hound
#

So set the value of its position to the height you want

honest haven
#
    {
        //recheck in future what player can move does
        if (_canPickUp && Input.GetKey(KeyCode.P))
        {
            if (_isWeapon)
            {
                GameManager.instance.AddWeapon(GetComponent<Item>().itemName);
            }
        }
    }```best way to only register this once?
wintry quarry
rocky canyon
#

transform.position.x, transform.position.y, myposition.z;

#

or w/e

robust kelp
#

void OnGUI()
{
float rotatero = orientation.rotation.y;
GUI.Box(new Rect(10, 10, 140, 100), "Measurements");

    GUI.Label(new Rect(20, 40, 80, 20), "   " + rotatero + " m/s");
}
#

why is the first value so different than the other

honest haven
echo matrix
wintry quarry
#

it has nothing to do with the y rotation in the inspector.

timber tide
#
sceneView = SceneView.lastActiveSceneView;
sceneCamera = sceneView.camera;```
what callback can I throw this in so it doesn't throw me errors after script compilation
#

OnSerializationCallback almost works after it spams my console with 999 errors

grizzled pagoda
#

hi i have a unity project due tuesday and im almost done, im having a problem getting the amount of an object in my scene at once then using that int in an if

robust kelp
rocky canyon
grizzled pagoda
rocky canyon
#

use a Component <ScriptOfYourChoosing>

grizzled pagoda
#

this is what i have rn

rocky canyon
#

that will place ALL of em in the array.. then u can use array.Length to get teh number of elements in teh array

#

yea, that basically what i was saying

wintry quarry
grizzled pagoda
rocky canyon
#

is this the name of the script?

#

u named a script ZombiePrefab ?

grizzled pagoda
rocky canyon
#

yea no thats not what that does

wintry quarry
grizzled pagoda
#

oh

rocky canyon
#

it finds Components..

#

not names

grizzled pagoda
#

ah

robust kelp
grizzled pagoda
robust kelp
rocky canyon
#

make an empty script put it on ur zombie.. and then search for that script

#

ya that will work

grizzled pagoda
#

alr ill try that

wintry quarry
#

which is what's displayed in the inspector

rocky canyon
grizzled pagoda
#

oh

rocky canyon
#

even if the name was Originally ZombiePrefab it wouldnt find them correctly unless u manually rename them after u instantiated it

#

but u should be good if u have a component thats exclusive to the zombie

grizzled pagoda
#

okay

shell herald
#

on enable gets called every time the gameobject its on get activated right?

grizzled pagoda
#

rror while saving Prefab: 'Assets/My things/Prefabs/ZombiePrefab.prefab'. You are trying to save a Prefab that contains the script '', which does not derive from MonoBehaviour. This is not allowed.
Please change the script to derive from MonoBehaviour or remove it from the GameObject 'ZombiePrefab'.
UnityEditor.PrefabImporterEditor:OnDestroy ()

#

whats this mean?

#

i tried adding that blank script

rocky canyon
#

well it cant be completely blank lol

wintry quarry
rocky canyon
#
using UnityEngine;
public class ImAZombie : MonoBehaviour
{

}```
wintry quarry
rocky canyon
#

ya, i shoulda included that information sorry lol

glass urchin
#

!code

eternal falconBOT
glass urchin
#

well its not even creating the gameobject

grizzled pagoda
#

@rocky canyon thanks dude your a lifesaver, for some reason all the documentation forums didnt specify you had to put a script in and i assumed it was an object that you had to find

#

also is there a way i can check for all objects in a array? or would it be simpler to check for all those that have the same script?

grizzled pagoda
#

oh

#

i was looking at smth else then

rocky canyon
#

type means alot of things, Monobehaviour is a type, Collider is a type, a rigidbody is a type

#

a name is not however

rocky canyon
glass urchin
#

Type T?

woeful lagoon
#

Hey guys, the ui buttons I have (TMP) don't show up in builds but do in game view on the editor, I've searched the net and nothing came up that could fix my issue, any ideas?

rocky canyon
#

i was talkin to Mahdboi, but yea sometimes Type is represented as T

#

i think that means it can be any type or its a placeholder type

#

not so sure on that one

rocky canyon
#

i would think ur canvas isnt scaling correctly.. and when u build (and its a bigger resolution) they're off the edge

woeful lagoon
#

Change scale mode to scale w/ screen size?

swift crag
#

your anchors are probably wrong

#

show me the inspector for one of your UI buttons

#

along with the scene view

woeful lagoon
swift crag
#

the anchor looks okay, but that's a really funnily shaped canvas

#

is your game view really a narrow rectangle?

woeful lagoon
#

Yeah

swift crag
#

also, depending on scaling settings, it's possible that the buttons are becoming very small and then winding up off screen

#

i wouldn't expect it, but...

#

consider changing the Pivot point to [1, 1] and then making Pos X and Pos Y both zero

sage mirage
#

Hey, guys! I have a question. Is there a way to make an animation for my Game Title Scene? I want to make something like when the game starts and the player appears in title scene where the name of the game is shown to see an animation like in background.

woeful lagoon
#

is that of my empty contaning them or the buttons themselvs?

#

Changing all of them worked

#

Thanks guys!

rocky canyon
#

it can be a 3d world. with a text canvas on top for the buttons

minor spindle
#

Any settings suggestion for making transitions from idle states to walking etc faster?

rocky canyon
#

u can manually drag that blue highlight or u can set this value that says "Transition Duration"

minor spindle
rocky canyon
minor spindle
#

Should I repost there or can we finish resolving it here?

wintry quarry
#

or reduce the exit time

minor spindle
rocky canyon
minor spindle
#

thank you boss 🙏🏼

rocky canyon
#

ahh, ya i didnt see that. exit time means the animation plays fully before it would transition

honest haven
#

Hi trying to fix an issue. when my player walks over an object he slighty comes of the ground then walks in the air. Im trying to add gravity but now when he hits the object he starts flying into the air

minor spindle
rocky canyon
#

if u want it to play fully yea,

minor spindle
#

Okay, thanks yall :))

rocky canyon
#

the ones w/o are ones that would get cut off

#

like walking, idling etc

minor spindle
#

Thank you 🙏🏼 I'll make sure to post animation related questions in #🏃┃animation next time

rocky canyon
minor spindle
rocky canyon
#

😱

minor spindle
#

but it works for now which is all that matters right 😅

rocky canyon
#

thats right!

minor spindle
#

"If it works it works"

rocky canyon
#

well, for now.. as u get better and learn more, you'll get into the refactor this and that.. and start thinking about scaleability (how easy is it to add or modify this).. and so on

wispy karma
#

Hey, I feel like this is a silly question, but I literally cannot get the bullet I am firing to instantiate vertically, I tried fixing it manually in the animator., I tried rotating the prefab itself, but nothing it working. The code is here

using System;
using UnityEngine;
using UnityEngine.InputSystem;

public class Shooting : MonoBehaviour
{
    public Transform firePoint;
    public GameObject bulletPrefab;
    public float bulletForce = 20f;

    [SerializeField] private InputActionReference shootAction;

    public event Action OnShoot; // Event to handle shooting

    private void OnEnable()
    {
        shootAction.action.Enable();
        shootAction.action.performed += OnFirePerformed;
    }

    private void OnDisable()
    {
        shootAction.action.Disable();
        shootAction.action.performed -= OnFirePerformed;
    }

    private void OnFirePerformed(InputAction.CallbackContext context)
    {
        if (bulletPrefab != null)
        {
            Shoot();
        }
    }

    void Shoot()
    {
        Debug.Log("Bullet fired");
        GameObject bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
        Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
        rb.AddForce(firePoint.up * bulletForce, ForceMode2D.Impulse);

        // Invoke the OnShoot event when shooting.
        OnShoot?.Invoke();
    }
}```
rocky canyon
#

Step 1 - well make sure u've removed anything you tried in the animation

#

that'll overwrite ur code every time

obtuse sluice
#

Good Evening beatiful people,

Im about to start my first collabo project with a friend of mine. Now I found two options to do that so. Can someone here, who already made collaborations which is the easiest or more efficent one?

So first
Unity Teams/ Control Version
or
GitHub repository

🤔

rocky canyon
#

Github every day + Git Desktop Companion Software

obtuse sluice
#

Ok thanks haha

#

I tried Control, but it was a bit confusing honestly

rocky canyon
#

i use 'Fork' but beginner may see more documentation with GitDesktop or w/e its called

wispy karma
#

it's weird af

rocky canyon
#

well github isn't a walk in the park

wispy karma
#

How do you like it?

rocky canyon
#

but if u start it correctly it shouldnt be too bad

rocky canyon
#

unless something about it changes

wispy karma
#

oh fr?

swift crag
#

ride or die on the command line

wispy karma
#

Doesn't it cost money tho?

swift crag
#

Lots of things cost money

wispy karma
#

True

swift crag
#

it's good to pay money for things you use a lot

rocky canyon
#

i love the visual filetree

swift crag
#

"add files"

north kiln
#

Fork 🍴 is da best

shrewd swift
#

What is Fork ?

swift crag
#

okay, so @cunning locust : generics let you write methods that work on many different types

shrewd swift
#

A repo & version control manager ?

north kiln
#

it's a git GUI

woeful lagoon
#

Having a bit of trouble with netcode D; , my clients aint moving

languid spire
#

@cunning locust

T math<T>(T a, T b, char opr = '+') where T: struct
woeful lagoon
#

I have the clientnettransform script from git

shrewd swift
rocky canyon
#
public abstract class Singleton<T> : MonoBehaviour
where T : MonoBehaviour
{
    public static T Instance { get; private set; }

    void Awake()
    {
        // Destroy this object if we already have a Singleton defined
        if(Instance != null)
        {
            Destroy(gameObject);
            return;
        }
        DontDestroyOnLoad(gameObject);
        Instance = (T)this;
        DoAwake();
    }

    // Virtual method to allow implementations to use Awake
    protected virtual void DoAwake() { }
}``` oh, i have a generic singleton
#
using UnityEngine;
public class GameManager: Singleton<GameManager>
{
    public void Start()
    {
        Debug.Log("Check");
    }
}```
#

i think some of its wrong tho.. I can't remember if i ever fixed it

cunning locust
shrewd swift
#

A singleton i just a class that will be used once ?

rocky canyon
#

ya, pretty much

#

can only be 1

#

of itself

#

so u can have a reference u can access via anywhere, knowing its the only one

swift crag
rocky canyon
#

singleton.Instance.DoStuffFromAnywhere();

wintry quarry
swift crag
#

given that struct makes no promises about being to add the values, and that the compiler doesn't think you can cast back from int to T

languid spire
woeful lagoon
#

How do I give ownership of a player object to a client so they can use transforms on them

rocky canyon
#

how could u cast to T?

#

hows that work in general speaking

shrewd swift
wintry quarry
#

You can make it one, if you wish

languid spire
swift crag
wintry quarry
#

both of those work, as well as as

swift crag
#

it doesn't accept casting an int to T with a cast operator

rocky canyon
rocky canyon
languid spire
rocky canyon
#

🤯 ... welp, thats interesting

woeful lagoon
swift crag
#

This method may be used with any type.

#
int x = Identity(3);
float y = Identity(1.0f);
string z = Identity("hello");
#

However, this method is not very useful. We have absolutely no constraints on what T can do, so we can assume very little about it

languid spire
#

the call would be

int x = math<int>(x,y,'*')
or
float z = math<float>(a,b,'-')

so no casting required

swift crag
north kiln
#

you know what would explain this, watching a tutorial 😛

languid spire
#

yes, exactly what you want

rocky canyon
swift crag
#

and the compiler doesn't believe that casting an integer value to T works at all

woeful lagoon
rocky canyon
#

then why not let them the ability to modify transforms?

languid spire
#

no it wont bacause you cannot constrain T to primitives only value types

woeful lagoon
cunning locust
rocky canyon
#

how did u do the camera?

swift crag
woeful lagoon
#

Using a public transform

#

With movement its applying force to a rb

#

Camera is locked to a var

cunning locust
rocky canyon
#

u have to write player code, one that all players would use to move their respective transforms

swift crag
cunning locust
#

makes sense

swift crag
languid spire
#

and you need to constrain T in order to be able to do anything sensible with it

swift crag
#

indeed!

#

the more you constrain it, the more you can do with it

#

completely unconstrained types are only really found in data structures

woeful lagoon
#
 // calculate movement direction
 moveDirection = orientation.forward * verticalInput + orientation.right * horizontalInput;

 // on ground
 if (grounded)
     rb.AddForce(moveDirection.normalized * moveSpeed * 10f, ForceMode.Force);

 // in air
 else if (!grounded)
     rb.AddForce(moveDirection.normalized * moveSpeed * 10f * airMultiplier, ForceMode.Force);```
swift crag
#

and even then, they often make some demands of the type -- such as making sure that it's comparable

woeful lagoon
#

This wouldn't work?

cunning locust
#

thanks!

rocky canyon
#

do bolf 😈 🖥️ 🖥️ .. lol

woeful lagoon
#

whuh

#

aight

swift crag
woeful lagoon
#

oooh

#

ok, I gotcha

cunning locust
swift crag
#

Been a hot minute since I played with this stuff, though

woeful lagoon
#

I already have a network rb tho

rocky canyon
#

whats controlling it?

woeful lagoon
#

Aight fixed

#

my movment is scuffed now tho

#

only on the client apparently

rocky canyon
#
        if(Input.GetMouseButtonUp(0) && (drag ^ hold))
        {
            if(hold) hold = false;
            if(drag) drag = false;
        }```
does this make sense?
#

i mean, both hold and drag need to be the same value, also

north kiln
#

why not just write something normal lol

rocky canyon
#

lol, i seen a mention of a ^

#

and if i think im right thats an exclusive or gate?

#

so either one or the other returns true for the entire ()

#

lol, i was refactoring b/c it was worse, i have 3 or so if conditionals looping at different times each also having the GetUp tagged towards the bottom of the function

north kiln
#

what are you trying to check? Because it'll just check if they're different

rocky canyon
#
    void RequestSelection(Vector3 pos)
    {
        Ray ray = Camera.main.ScreenPointToRay(pos);
        RaycastHit hit;

        if(Physics.Raycast(ray,out hit,distanceOfRay))
        {
            focusedTransform = hit.transform;
            if(hit.collider.TryGetComponent(out ISelect selectable))
            {
                scrollLock = true; // the map shouldn't move until we release
                hold = true; // we're (possibly holding down the mouse button)

                lastSelectable = selectable;

                // Store the initial mouse position when the drag starts
                initialMousePosition = Input.mousePosition;
                drag = true;
            }
            else
            {
                Debug.Log("We clicked something unselectable");
                lastSelectable = null;
            }
        }
    }
``` mouse down starts a timer, to see if we clicked a ISelect interface
#

and then theres diff states, if its selected and we click and hold a 2nd menu opens.. if its selected and we click and drag a different function would trigger

#

and for the time being im ignoring stuff if its not selected if clicking and doing nething

#

i think that conditional works just fine tho, as ive not exposed the drag variable but it debugs..

glass urchin
north kiln
eternal falconBOT
glass urchin
#

thanks for the non answer

north kiln
#

Is your IDE configured?

echo matrix
#

Hey i am currently working on an ecg, but the first complex always looks ugly and i cant figure out why it is that way. I would provide code, but i dont know how to make those grey boxes in discord and dont want to clutter the chat

north kiln
#

!code

eternal falconBOT
glass urchin
#

I've tried enough to get the IDE to work.

grizzled pagoda
#

i have a zombie that continually moves forward and will encounter a plant that its supposed to collide with and eat, problem is it passes through the plant and reduces the plants health by one only and doesnt stop and reduce the plant's health past the first collision

echo matrix
#
 {
     float elapsed = 0;
     while (elapsed < duration)
     {
         amplitude = normalPWave.Evaluate(elapsed);
         elapsed += Time.deltaTime;
         yield return null;
     }
 }```
glass urchin
#

wait I know what the problem is

#

I have to modify the Vector3 not the float

grizzled pagoda
echo matrix
#
{
    yPos = GameObject.FindWithTag("ECG").GetComponent<ECGPatern>().amplitude;
    transform.position += Vector3.right * moveSpeed * Time.deltaTime;
    Vector3 targetYPosition = transform.position;
    targetYPosition.y = yPos;
    transform.position = targetYPosition;
}```
#

is there anything wrong with the code that could produce this error only at the beginning?

tawdry rock
grizzled pagoda
tawdry rock
#

what you try to achive is not clear to me. so the zombie eat the pea and decrease the zombie health by 1 like in every seconds?

glass urchin
#

how to make a certain scripts start function happen before another's?

#

or generally order them?

tawdry rock
glass urchin
#

but what if I have multiple I wanna order?

tawdry rock
#

Edit > Project Settings and then select the Script Execution Order

glass urchin
#

okay nice thanks

#

thats easy

rancid tinsel
#

why is this code resulting in the color changing back to startColor despite the mouse still hovering the object??

grizzled pagoda
#

void OnTriggerEnter(Collider other){
if (other.CompareTag("Zombie"))
{
PeashooterHealth--;
Debug.Log("PeashooterHealth: " + PeashooterHealth);
}

// Check health in OnTrigger
    if (PeashooterHealth <= 0)
    {
        Destroy(gameObject);
    }
tawdry rock
#

@grizzled pagoda please use alt+96 to make a ` and place your code in a code tag 3

grizzled pagoda
#

alr

#

alt 96?

glass urchin
#

hold alt and type 9, 6

#

that gives `

tawdry rock
rancid tinsel
rancid tinsel
rocky canyon
#

even that might not work.. b/c it says

grizzled pagoda
#

test

grizzled pagoda
glass urchin
#
// c code here
#

do you have unicode installed?

tawdry rock
#

put it after monobehaviour then you can use public void OnPointerEnter(PointerEventData pointerEventData) or OnPointerExit @rancid tinsel

grizzled pagoda
#

unicode? on my pc or what

#

'test'

rancid tinsel
rocky canyon
#

as long as it has a collider it should work..

glass urchin
#
copy this message as a template
north kiln
rocky canyon
#

a graphic/physics raycaster may be needed on teh camera

#

i cant remember about that generally

grizzled pagoda
#

test

#

there we go

rocky canyon
#

but his issue was he said it changed back

grizzled pagoda
#

ah i see

glass urchin
grizzled pagoda
#

sorry for being dumb haha

rocky canyon
#

so that means it must have changed originally

rancid tinsel
#

the clip i just sent should demonstrate what I mean

grizzled pagoda
#

` void OnTriggerEnter(Collider other){
if (other.CompareTag("Zombie"))
{
PeashooterHealth--;
Debug.Log("PeashooterHealth: " + PeashooterHealth);
}

// Check health in OnTrigger
    if (PeashooterHealth <= 0)
    {
        Destroy(gameObject);
    }
}`
#

this is my plant code

rancid tinsel
#

startColor is when its grey, hoverColor is when its yellow

grizzled pagoda
glass urchin
#

also alt codes dont work on the top row of numbers unless you have that enabled. but works on the keypad by default

rocky canyon
#

somethings in teh way @rancid tinsel

rancid tinsel
grizzled pagoda
#
        if(collision.gameObject.CompareTag("Pea")){
            HealthPoints = HealthPoints - 1;
            Debug.Log("Zombie HealthPoints: " + HealthPoints);
        }
        if(collision.gameObject.CompareTag("Plant")){
            speed = 0f;
        }
        else if{
            speed = 10f;
        }
    }```
rancid tinsel
#

yup its pixel perfect camera causing it

tawdry rock
# rancid tinsel

you can add a component called event trigger that listen for your mouse but i would still stick to IPointerEnterHandler and IPointerExitHandler

grizzled pagoda
rancid tinsel
#

also a similar issue happens (not as badly as in the clip) when fully zoomed out

#

it seems to think the mouse isnt over the square anymore when close to the edges

#
  • with pixel perfect camera disabled
tawdry rock
rancid tinsel
tawdry rock
#

!code

eternal falconBOT
rancid tinsel
#

i know i thought small code likke this was fine tho

tawdry rock
#

its not about the lenght, pictures are uncopiable

rancid tinsel
#

right that makes sense

#

this is the BuildManager script

#

in case you wanted to see that one as well

grizzled pagoda
#
        if(collision.gameObject.CompareTag("Zombie")){
            Destroy(gameObject);
        }
    }```
#

could anyone tell me why this may not be working?

calm coral
#

The type or namespace name 'InputSystem' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?)
Hey, I have a pretty basic problem aniblobsweat not sure why using UnityEngine.InputSystem; doesn't work

rancid tinsel
grizzled pagoda
tawdry rock
rancid tinsel
#

if you go into Project Settings > Physics (or Physics 2D if youre in 2D)

grizzled pagoda
rancid tinsel
#

you can scroll all the way down to have the different layers and what they can collide with

rancid tinsel
#

but youll have to make new layers by clicking on the pea and zombie objects, clicking layers and making new ones respectively

calm coral
rancid tinsel
#

the bottom bit with the tickboxes

ivory bobcat
rancid tinsel
#

but you should create layers first

grizzled pagoda
#

how

rancid tinsel
#

go on your zombie prefab and click on the dropdown under its name in the inspector called "Layer"

#

and then Add Layer

#

name it and then go back to the zombie prefab and change the layer to that

#

do the same for the bullets and plants as well

grizzled pagoda
#

layer overides?

#

oh nvm add layer

rancid tinsel
#

but give them individual ones

grizzled pagoda
#

found it

rancid tinsel
#

nice

calm coral
rancid tinsel
#

yeah its just easier to do it this way than checking which thing it colllided with

grizzled pagoda
#

okay

rancid tinsel
#

and hopefully you wont run into issues with this method

grizzled pagoda
#

what about sorting layers? that important or nah?

rancid tinsel
#

where is that?

grizzled pagoda
#

just beside the layer selection

rancid tinsel
#

oh in sprite renderer?

grizzled pagoda
#

also, if i want the zombie to interact with all my plants the same, ill just give the plants the same layer right?

rancid tinsel
#

yes

grizzled pagoda
#

okay

#

and coding wise how would i check if the layers collide?

rancid tinsel
#

basically what the ticks do is you choose which layer can collide with which layer

rancid tinsel
glass urchin
#

how do I see my code's memory usage and stuff while testing?

rancid tinsel
#

if your plants will only collide with the zombies, then you can just check for general collision

#

cuz it will be the only one that can happen

#

if you have 2 different layers colliding with a layer then you will have to check like normal i believe

grizzled pagoda
#

so instead of checking for tags i check for layer colliding or what?

rancid tinsel
#

ok what will your plants collide with?

#

is it just the zombies?

icy cape
#

yo so where did they move navmesh stuff in 2022

grizzled pagoda
#

just zombies yeah

icy cape
rancid tinsel
#

that means that only zombies can colllide with plants

grizzled pagoda
#

okay

rancid tinsel
tawdry rock
rancid tinsel
#

same as how i have bullets only colliding with enemies on mine

grizzled pagoda
#

i also want the pea to collide with the zombie, how would i do that?

grizzled pagoda
glass urchin
#

is 4096 rigidbodies a lot/too many?

#

what's a good limit?

rancid tinsel
#

basically tick means it can collide with objects in that layer, untick means it cant

grizzled pagoda
#

okay

tawdry rock
grizzled pagoda
#

but my zombie cant even collide with the plant cuz theres no option to tick it you see?

rancid tinsel
#

do you not need something else forr the pointer things to work?

shrewd swift
tawdry rock
#

Mahdboi, are you making 2d or 3d game?

grizzled pagoda
#

3d

rancid tinsel
#

look at the left side of the table

#

its a bit confusing to look at

#

but zombie is on both the top and the left

grizzled pagoda
#

ohhh

#

damn

rancid tinsel
#

yeah that got me earlier too lol

grizzled pagoda
#

aight fixed it

#

now how do i check for it

#

in my code

rancid tinsel
#

just normal OnCollisionEnter

grizzled pagoda
#

parameters stay the same?

rancid tinsel
#

so basically untick everything except the thing you want it to collide with

#

and it should work

grizzled pagoda
#

so like

rancid tinsel
#

get rid of the if statement basically

grizzled pagoda
#

oh

rancid tinsel
#

and it should work fine

tawdry rock
#

maybe use image for your sprite and change the image's color

rancid tinsel
#

i mean the Sprite Renderer works for you no?

grizzled pagoda
rancid tinsel
#

update on the issue: this only happens on certain squares, towards the edge of the screen mainly

rancid tinsel
grizzled pagoda
rancid tinsel
#

then make movement only happen when its true

grizzled pagoda
#

how would i specify which layer is colliding

rancid tinsel
#

oh for zombie you would need the pea and the plant layers

#

right

grizzled pagoda
#

is there no way i can specify each indivisually?

rancid tinsel
#

check the number of the layer for plants and peas

#

so where you select the layer it should have a number next to the name

grizzled pagoda
#

yeah

rancid tinsel
#

if (collision.gameObject.layer == plant layer number)

grizzled pagoda
#

ah

#

okay

rancid tinsel
#

let me know if that works

tawdry rock
#

@rancid tinsel see if this helps. put image component on your square, and put your sprite as the source. make a refference for the Image then change it's color by refferencename.color = startColor

grizzled pagoda
#

doesnt give me an error either

rancid tinsel
#

mahdboi wanna do a quick call so you can screen share it to me?

#

i want to see what the inspectors like

grizzled pagoda
#

alr cant talk rn tho

rancid tinsel
rancid tinsel
warm condor
#

Is there a reason why this invoke function is not delaying the function enableMovingAndAnimationControles()?

        if (Input.GetKey(KeyCode.A) && Input.GetKey(KeyCode.D)){
            Invoke("enableMovingAndAnimationControles",2f);
        }
    }```
#

That is being called in the update function so I think that the problem is comming from this function right here.

unkempt tree
#

can someone help me understand how this is possible? As soon as I take any damage my health percentage just goes to zero. I feel like i'm doing something stupid but it looks right to me!

        {
            float healthPercentage = characterData.CurrentHealth / characterData.MaxHealth;
            healthPercentage = healthPercentage * 50;
            int index = (int)healthPercentage - 1;
            Debug.Log("Cur Health: " + characterData.CurrentHealth + "\nMax Health: " + characterData.MaxHealth + "\nHealth Percentage: " + healthPercentage + "\nIndex: " + index);
            healthGlobe.GetComponent<Image>().sprite = healthGlobeImages[index];
        }
#

.98 * 50 should get me 49

unkempt tree
#

because I got 50 diff sprites* for my health globe

#

how can .98*50=0 though?

twin wyvern
#

Hello! Was just wondering if anyone knew how to stop a player being able to change the trajectory of a jump while mid air

keen dew
unkempt tree
#

man i wasted so much time on that