#💻┃code-beginner

1 messages · Page 47 of 1

somber wren
#

why spherecasts

buoyant knot
#

because if the surface is irregular, you don’t want to get fucked by edges

#

raycasting works, but will look super wrong whenever the surface changes slope

#

because the spider (which lacks collision) will have part of him just clip right through the world

#

i know people like raycasting because it’s cheap, but casting shapes helps prevent jank

#

do you understand?

solid yew
#

@forest wolf thanks for the help I'll try those

forest wolf
#

Good luck! If you get stuck please let me know :)

somber wren
#

i don't really care about that, we dont have the time

#

its a uni project. 3 Months to do a 3D multi leg procedurally animated in a game

forest wolf
#

in this snippet you set the rotation, where do you set the position?

somber wren
#

from 0 exp on unity

forest wolf
#

then after your transform.position += line

somber wren
#

but its not in the same script

forest wolf
#

give me a sec, I need to open rider to add the lines I need :)

somber wren
#

i could do it still i think

#

okay

forest wolf
#

by the way, instead of doing screenshots it's better if you do
3x ` and then add C# then after the code add it once again

somber wren
#

oh yeah that too

forest wolf
#

you will have something like that

var trolo = hey;
somber wren
#

yeah i know

#

its mb

forest wolf
#

*CSharp not C#

somber wren
#

or cs

forest wolf
#

@somber wren I think something like that could work:

    private void Move()
    {
        var t = transform;
        t.position += (t.forward * ForwardInput * Time.deltaTime * _moveSpeed);
        Physics.Raycast(new Ray(t.position, -t.up), out var hitInfo);
        var currentDistance = Vector3.Distance(transform.position, hitInfo.point);
        var distanceAdjustment = TargetDistance - currentDistance;
        t.position += t.up * distanceAdjustment;
    }
somber wren
#

if the raycast doesnt work then currentdistance is 0 ?

somber wren
#

thank you

#

but it wont work ON my cube

#

it just goes through

#

and yeah sometimes it goes in the infinity under the ground, i will raycast from my raycaster

forest wolf
#

oh sorry, did you manage to get it working? I maybe missed something as I haven't tested that snippet

somber wren
#

xd look

forest wolf
#

Can you add Debug.Log($"{currentDistance} adj: {distanceAdjustment}");?

#

By the way if your spider is always lying on the surface then you don't even need raycasting and calculating the distance adjustmenet. If the distance is always 0

#

then you should be able to do only t.position += t.up * TargetDistance;

somber wren
#

wdym

somber wren
#

its going up to the infinity

#

i can't recooord aaa

#

im on da wall and then pouf

#

fucking up in edges yes

dry tendon
#

heey, does anyone knows how could i do this to make a fade transition?

forest wolf
somber wren
#

it works

forest wolf
somber wren
#

but on the edge it goes through its bc of my raycaster

#

look

lapis veldt
#

Hello everyone

somber wren
#

the ray goes on the wall :(

lapis veldt
#

I am following a tutorial to make a vampire survivors like game and I am stuck at cinemachine part. I selected the virtual camera to follow the player, but it doesn't follow him

forest wolf
#

and the box would have to have size of the spider body

somber wren
#

wow why XD

dry tendon
somber wren
#

i never used it wow

cosmic dagger
dry tendon
#

oh, right, thankss

dry tendon
cosmic dagger
lapis veldt
cosmic dagger
lapis veldt
tender stag
#

how can i stop players from spam eating and drinking as shown in the video? like if they switch to another item they can eat or drink straight away

using System.Collections;
using MilkShake;
using UnityEngine;

public class Food : MonoBehaviour
{
    [Header("Item")]
    public ConsumableItem item;

    [Header("Eating")]
    public bool isEating = false;
    public float eatTime = 5;

    [Header("Audio")]
    public AudioSource audioSource;
    public AudioClip eatClip;

    [Header("Shaker")]
    public Shaker shaker;
    public ShakePreset eatShake;

    private void OnEnable() 
    {
        item = HotbarManager.Instance.currentItem as ConsumableItem;
    }
    
    private void OnDisable() 
    {
        item = null;
        isEating = false;
    }

    private void Update()
    {
        if(Input.GetMouseButtonDown(0) && !isEating && PlayerHandler.Instance.canUse)
        {
            StartCoroutine(Eat());
        }
    }

    private IEnumerator Eat()
    {
        isEating = true;

        Statistics.Instance.currentHealth += item.health;
        Statistics.Instance.currentHunger += item.hunger;
        Statistics.Instance.currentThirst += item.thirst;
        Statistics.Instance.currentStamina += item.stamina;

        item.cell.SetAmount(item.amount - 1);

        audioSource.PlayOneShot(eatClip);
        shaker.Shake(eatShake);

        yield return new WaitForSeconds(eatTime);

        isEating = false;
    }
}```
#

i was maybe thinking have a static bool which goes across all food scripts

#

to check if you can eat?

#

idk

cosmic dagger
eternal falconBOT
somber wren
#

boxCast doesnt work :(

#

maybe i dont use it properly

cosmic dagger
tender stag
#

i have the coroutine

forest wolf
tender stag
cosmic dagger
tender stag
forest wolf
tender stag
#

all the food items have this script

eager elm
# dry tendon and how could i get access to alpha parametter?

at the top of a script:

public CanvasGroup myCanvasGroup;
private bool isAnimating;
private float animationTimer;
private float animationEnd = 1f;

void Update()
{
    if (isAnimating)
    {
        animationTimer += Time.deltaTime;
        AnmiateFadeOut();
    }
}
public void ToggleAnimation(bool animate)
{
    isAnimating = animate;
    animationTimer = 0;
}
private void AnimateFadeOut()
{
    myCanvasGroup.alpha = Mathf.Lerp(1f, 0f, animationTimer / animationEnd);
}
forest wolf
somber wren
#

how do i get each corner and how do i know which one is good. I only need 3 tho, one at the front and one at the back

forest wolf
#

you create an empty object and make it child of the spider. You then create a serialized fields for those transforms in your script. Drag & drop the game objects into the fields in the inspector - boom you have transforms with positions :D

tender stag
#

and deactivated

#

thats the problem

#

because on disable i do this

tender stag
cosmic dagger
# tender stag

@tender stag that's the problem. you need a controller/manager that controls the consumption of consumables. when a food item is eaten, a timer on the manager runs. switching to any food and attempting to eat will send an event to the manager that will determine if they can consume again or must wait . . .

tender stag
#

would a coroutine work if i start it when the object is still activated and then i disable it like half way through the coroutine?

eager elm
#

If the coroutine is on the object that is getting deactivated it would stop

inner marsh
#

This is like the 4th time you've said this i did what the instructions said nothing has worked 💀

forest wolf
cosmic dagger
#

just create a manager that controls the consumption. that's the simplest solution . . .

tender stag
#

and just place them on like consumables, weapons etc

timber tide
#

Can do OnDisable() to flag that the coroutine should end early

somber wren
#

@forest wolf doesnt work... sigh

forest wolf
bitter carbon
#

quick question, if something is moving will it always have a velocity above 0, and if it is not moving will it always be 0

bitter carbon
#

isnt there - velocity as well

summer stump
#

Is it using transform.position += ?

bitter carbon
#

nope

forest wolf
# tender stag so i could have like a manager for each of the categories?

Not even manager, holder holds an item, each items, be it weapons, consumables or tools can have a common interface "Usable" or something like that that have method "Use". Each item could implement the interface and thus the method. Then the holder could execute the use of any item that you are currently 'holding'

summer stump
cosmic dagger
bitter carbon
#

ok so if it is stopped it will be 0 velocity

summer stump
summer stump
bitter carbon
#

yea but i need to know if it is stopped

#

ok thanks

cosmic dagger
bitter carbon
#

nvm

#

i think i know

cosmic dagger
#

again — as we mentioned — it depends on how the object is moved. if using the physics engine, access the velocity property of the rigidbody. if manipulating the transform, you need to get the distance from the current position to the last position . . .

pastel marten
#

This is definitely a beginner question, and maybe not all that important, but I keep getting the following error when I stop the Play in my editor for a singleton:

Some objects were not cleaned up when closing the scene. (Did you spawn new GameObjects from OnDestroy?)
The following scene GameObjects were found:
InputHandler

And my InputHandler.cs has this:

//Create a Singleton for this InputHandler Static Class so it stays on Scene Change
    private static InputHandler instance;
    public static InputHandler Instance
    {
        get
        {
            if (instance == null)
            {
                instance = FindObjectOfType<InputHandler>();
                if (instance == null)
                {
                    GameObject obj = new GameObject("InputHandler");
                    instance = obj.AddComponent<InputHandler>();
                }
            }
            return instance;
        }
    }

    private void Awake()
    {
        DontDestroyOnLoad(gameObject);
    }

//more code not visible that handles input

    void OnDisable()
    {
        Destroy(gameObject);
    }

It's not breaking anything, just a little annoying. Any help would be appreciated! ♥

somber wren
summer stump
#

Also, you don't really wanna do new GameObject

#

You want Instantiate

pastel marten
pastel marten
dry tendon
#

heey, how could I do on the last methodCanvasFadeto instead change the alpha from 1 to 0 directly to make a fade changing alfa softly? ```cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LoadingScreen : MonoBehaviour
{
[Header("Preferences")]
[SerializeField] private float loadingCanvasTime;
private float loadingTextTime;

[Header("Drag")]
[SerializeField] private GameObject loadingCanvas;
[SerializeField] private CanvasGroup loadingCanvasGroup;

void Start()
{
    loadingCanvas.SetActive(true);
    loadingTextTime = loadingCanvasTime - 0.5f;
    Invoke("CanvasFade", loadingCanvasTime);
}

private void CanvasFade()
{
    loadingCanvasGroup.alpha = 0f;
}

}

summer stump
summer stump
#

You could also skip the invoke by doing that

pastel marten
cosmic dagger
spiral oak
pastel marten
cosmic dagger
spiral oak
#

@dry tendon oh its you
I can show you by DM, I made the same youre trying to do some days ago

cosmic dagger
#

why?

#

you asked seconds ago and it's just about input . . .

bitter carbon
#

how do u get numbers using this method of inputing
Image

cosmic dagger
#

what intellisense pops up after you enter current.?

bitter carbon
#

there is like 10 different ones

#

but it is all just cuz its number

bitter carbon
#

so ill put in code genereal instead

cosmic dagger
#

have you asked this question multiple times?

bitter carbon
#

nope

cosmic dagger
#

this is the first time i've seen and you've barely waited for anyone to answer . . .

#

there isn't a hundred people waiting for questions to pounce right away. you seem impatient . . .

bitter carbon
#

yea but it is not really beginer if the average person doesnt know, if you dont know that is fine just leave me be

cosmic dagger
#

did you check the docs for the Keyboard class to see its available properties?

#

have you checked anything online?

bitter carbon
#

yes

#

couldnt find anyone doing it the same as me

cosmic dagger
#

is this the old input system or the new input sytem? try to provide more details . . .

bitter carbon
#

new input system

#

it was just a method i saw by someone and used it as it is alot more simple than other methods

swift crag
#

C# names cannot start with a digit.

bitter carbon
cosmic dagger
bitter carbon
buoyant knot
#

is there a simple way to make a given field/property only accessible to its class AND one specific class that is not derived from it?

polar acorn
swift crag
#

(C++'s friend keyword allows for this)

cosmic dagger
#

no problem, next time continue reading and/or scrolling through the docs. don't just click away . . .

polar acorn
bitter carbon
cosmic dagger
buoyant knot
#

😦

timber tide
#

events

languid spire
swift crag
#

Perhaps you should add a nested class that holds a reference to the class, and then offers a property that gets and sets the class's private field

timber tide
#

c# friend classes when

swift crag
#

You would then hand an instance of this class to whoever needs access

#
    private int test;

    public class Gimme
    {
        public Entity entity;
        public int Test
        {
            get => entity.test;
            set => entity.test = value;
        }
    }
#

(the enclosing class happened to be named Entity here)

#

Although, this has a public constructor, so anyone could make an instance of Gimme

#

I'm not sure you could make this work. If you made the class private, then you could not return it from a public method. If you made the constructor private, the enclosing class couldn't call it

#

I suppose the problem here is that we're trying to do access control programatically (making something that's nominally public, but can only be granted if certain conditions are met)

#

it just doesn't really jive with the completely static nature of access control modifiers

summer stump
bitter carbon
#

ok

spiral oak
#

Hi
Does anyone know if there's a way to get the object who sent a log in the ILogHandler methods?

cosmic dagger
swift crag
# summer stump Ah ok

You shouldn't be constructing anything derived from MonoBehaviour. I believe ScriptableObject also wants you to use CreateInstance to get new instances.

#

The former has a very obvious reason: components must be attached to a game object

#

so a free-floating component would be nonsense

#

I dunno about scriptable objects.

pastel marten
swift crag
#

When you're unloading a scene, objects get destroyed immediately -- so they wind up equalling null right away

#

I had some components that were trying to access a singleton while exiting play mode

cosmic dagger
#

smth is trying to access the Singleton after its been destroyed . . .

cosmic dagger
swift crag
#

The singleton would get destroyed first, so the singleton class tried to find them again

#

It would get a bogus object reference back (because there was no valid instance of the type it wanted in the scene)

#

and then overwrite the existing instance variable with it

#

So I lost the (still totally usable) reference to my destroyed singleton and got a new (unusable) reference to nothing

#

In this case, you're constructing a new game object when you notice that the instance is null

#

So if anyone tries to access this singleton during scene unload, a new game object will be constructed

#

I'm not sure what the best option here is

#

You could try to get rid of the use of the singleton during a scene unload, or you could make the singleton not try to find an instance if it notices the game is quitting

cosmic dagger
swift crag
#

that sounds tricky to solve correctly

#

it'd have to create itself in a valid scene

#

but what is the correct scene?

#

If your code accesses the singleton while the current scene is unloading, there would be no valid place to put the new object

pastel marten
inner marsh
#

im watching a video for some movement tips, and he uses some characters inbetween thrust1D > 0.1f and thrust1D < 0.1f, i cant tell what they are, anyone knows?

frosty hound
#

They're pipes ||

#

Representing the OR operator

#

To be clear, they're two pipes |

inner marsh
#

and how do i type said symbol?

frosty hound
#

Entirely depends on your keyboard 🤷‍♂️

summer stump
#

On my phone though

inner marsh
#

ah okay found it

#

ty

pastel marten
#

@swift crag @cosmic dagger

This makes no sense to me at all, but the error magically stopped after adding a GameManager class and DataSaver class for player traits & stats.

GameManager script: https://pastebin.com/XH1VcR8e (updated)
DataSaver script: https://pastebin.com/s6bDAJXZ

Doesn't make any sense? But at least it's gone I guess... lol

nimble inlet
#

Hello there. :D Good to be back. :)

#

I'm sort of trying to get my camera working in a unity project. It doesn't move in scene view despite any changes in inspector :C

wintry quarry
nimble inlet
#

It moves in the actual view but turn on game; jumps to some high zoom

#

what, oh, maybe it doesn't.

wintry quarry
#

Well maybe it does

nimble inlet
#

where would I go with this?

wintry quarry
#

that sounds like you have a script that is setting the camera's position

nimble inlet
#

I don't think I do. :C I just set this up. imma go look around.

#

that would explain it for sure.

wintry quarry
#

objects don't move on their own

#

some component will be doing it

#

either a script you write

#

or some other component you added somewhere

nimble inlet
#

yeah I just want to set the starting location.

wintry quarry
#

you need to make sure your script respects a starting location and doesn't just trample on it

swift crag
#

If you script sets the position to [0,0,0], it doesn't matter where the camera was

nimble inlet
#

no script yet. are you saying I can't setup a camera location without a script? there's always this:

swift crag
#

It's gonna end up at [0,0,0]

swift crag
#

Praetor suggested that there is a component in your scene that is setting the camera's position

summer stump
nimble inlet
#

very beginning. don't think I have any components, unless they come with the basic setup. but can't find scripts just typing scripts to search.

wintry quarry
#

Show the same screenshot once play mode starts

swift crag
#

so, start the game, click back to the Scene tab, and screenshot that

nimble inlet
wintry quarry
#

Looks to me like you're just confused about how UI works TBH

wintry quarry
#

You are just seeing your UI

swift crag
#

oh, yes, you're trying to show an image on a Screen Space - Overlay canvas, aren't you?

wintry quarry
#

because now you're looking at game view

nimble inlet
#

well, as far as my confusion goes, there's some values on the right, and I can't alter them to alter this camera view.

swift crag
#

The canvas appears in the scene view so that you can work on it.

wintry quarry
#

it's not shown on a camera

#

it's overlaid on the screen directly

nimble inlet
#

right...

wintry quarry
#

double click on your canvas in scene view and turn on the "rect" tool

#

position your UI as desired there

summer stump
#

So there is nothing that will obviously LOOK like a different position

nimble inlet
#

I think I got it.

#

gotta figure this out on my own now. Thank you!

buoyant knot
#

if kinematic RBs in 2D use velocity, what happens when you MovePosition and also have velocity?

unreal phoenix
#

I am getting weird interactions when rotating my player where I stick to walls ass if my capsule collider was a rectangle that is clipping into them

bitter carbon
#

how come there is an issue, i just want to get the currentTime from timeScript and round it to nearest whole number so it can detect if the currentTime == 5

cosmic dagger
bitter carbon
#

yea but where do i put round thingy then

naive pawn
# bitter carbon

Math.Round is the function, you can pass timeScript.currentTime to that

#

fn(args) is how you invoke functions, so Math.Round(timeScript.currentTime)

polar acorn
#

That would imply timeScript has a member named (Math.Round)

cosmic dagger
polar acorn
#

which cannot be since you can't have parenthesis in a variable name

bitter carbon
cosmic dagger
naive pawn
bitter carbon
#

it needs (

swift crag
#

no

polar acorn
# bitter carbon

This is calling Math.Round on timeScript.currentTime == 5, which is a boolean

swift crag
#

it doesn't work because everything is out of order

naive pawn
polar acorn
#

You're attempting to round a "yes" or "no"

swift crag
#

read your error messages.

polar acorn
#

You should probably look at the Intro to C# link in the pins to see how C# syntax works

naive pawn
#

Math.Round(timeScript.currentTime) is how you get the number, then you can compare that to 5 outside the function call

cosmic dagger
#

i would understand what you're trying to do first, then take it one step at a time instead of randomly guessing . . .

bitter carbon
#

its ok i realsied it now

#

its right now

#

thanks everyone

bitter carbon
polar acorn
#

You really should make sure you understand the basics before attempting to continue

swift crag
#

this is a very fundamental concept

#

Learn C# properly. It will save you a lot of time in the long run.

swift crag
bitter carbon
#

ok ik how it works now and its unlikely ill do it wrong again, also ik certain concepts more than otehrs so me being bad at one thing doesnt mean im bad at everything

swift crag
#

i don't think you know how it works now

#

i think you know how this example works

bitter carbon
#

i do

polar acorn
bitter carbon
unreal phoenix
#

You have to understand that Mathf/Math are static function classes and not extensions of types

swift crag
#

"and not extensions of types"

#

I don't understand what you mean by this.

unreal phoenix
swift crag
#

that has nothing to do with "extensions of types"

#

. is the member access operator.

unreal phoenix
#

what is the terminology

swift crag
#

It retrieves a member from a type.

#

(or from a namespace)

cosmic dagger
unreal phoenix
#

Member access expression

swift crag
#

UnityEngine.Mathf.Round

UnityEngine is a namespace, so UnityEngine.Mathf retrieves the Mathf member from the UnityEngine namespace
Mathf is a class, so Mathf.Round retrieves the Round member from the Mathf class

cosmic dagger
#

it is how you access —public — members of a type . . .

unreal phoenix
#

I know what it does, I used the wrong terminology

swift crag
#

well, members that you have the right to access, in general

polar acorn
bitter carbon
#

is it best to use a for loop if i wanna do it like:

if (time) is 5 seconds add 1 to decay etc,etc.

polar acorn
swift crag
cosmic dagger
unreal phoenix
swift crag
#

C++ is made entirly of weird stuff

unreal phoenix
bitter carbon
unreal phoenix
bitter carbon
#

i can

short hazel
# polar acorn

And I remember it being not static for some reason? Like you could do new Mathf()

#

Might have mixed it up with something else though

summer stump
# bitter carbon i can

Well obviously. But you being able to read it has no bearing on whether others can. You have experience reading it lol

I, for example, cannot read that

swift crag
#
            var x = new Mathf();
#

cursed

polar acorn
bitter carbon
polar acorn
unreal phoenix
bitter carbon
#

i think ill just try with for loop and see if it works well or not

polar acorn
swift crag
#

A for loop is used to execute the same block of code many times.

unreal phoenix
#

I don't even know how you would loop over that

swift crag
#

If you want to perform an action every time a certain condition is met, a for loop is not appropriate (by itself, at least)

polar acorn
bitter carbon
unreal phoenix
#

you don't want a loop

swift crag
#

I continue to insist you need to stop trying random things and follow some tutorials

#

It is absurd to claim that you "can't find anything" about for loops

polar acorn
polar acorn
cosmic dagger
bitter carbon
#

ok everyone calm down i found one, it just i waslookign one from the unity documentation site

#

but ill use a different website instead

rich adder
unreal phoenix
#

This won't do anything for you when you are talking about adding something after a certain time

for (i = 0; i < someInt: i++) {}
rich adder
swift crag
#

it is fine to not understand, but it is unreasonable to pretend that you do

#

you're doing yourself a disservice

unreal phoenix
#

You may not get much out of it if you're not very familliar with Unity/C#

summer stump
#

You had that issue yesterday too iirc

#

And it WAS a unity thing you couldn't find

bitter carbon
#

yea i think googling is alot better

uncut dune
#

how can I get RaycastHit2D[] normal?

unreal phoenix
#

Yeah never search the site, use google and look for the link XD

uncut dune
#

Ik that RaycastHit2D hit would just be hit.normal but I cant find it

polar acorn
uncut dune
#

normal of this

cosmic dagger
uncut dune
#

ohhhhhh

polar acorn
bitter carbon
#

can someone pls explain differenece between || and | (ik they are both or but i dont understand differece)

uncut dune
#

but I already have a foreach loop that checks it

unreal phoenix
#

if you only care about the first thing it hit just use hitscan[0]

uncut dune
#

I was trying to access it directly from the variable name

#

I thought it would give me the full length of it

rich adder
rich adder
# bitter carbon ok thanks
cosmic dagger
rich adder
#

true, was trying to oversimplify . edited 🙂

unreal phoenix
#

aren't all single operators bitwise and doubles are conditional?

uncut dune
#

when I redo a raycasthit2d[] from inside of a foreach loop that is cycling thru its elements does the foreach get updated?

#

with the new raycasthit2d

unreal phoenix
#

if you re use the variable it will overrite the previous array

uncut dune
#

or will just end

unreal phoenix
#

it would restart

rich adder
#

the loop would finish first

uncut dune
cosmic dagger
#

it won't restart unless you tell it to . . .

unreal phoenix
#

It would finnish the previous array and end

bitter carbon
unreal phoenix
#

it would not restart, my bad

cosmic dagger
#

code only does what you write . . .

uncut dune
eternal needle
#

Would that not just result in an error? something something dont modify collections as you foreach over them

cosmic dagger
#

you cannot change or edit an array if it's iterating over the collection . . .

#

you'd get an error . . .

polar acorn
uncut dune
#

really wrong

#

cuz I got not error

unreal phoenix
# uncut dune how do I tell it to restart?

I did something like this in a project. You can make a function that is a foreach loop and restart that function with the new array as an input, but it needs a fail condition so it doesn't infinietly loop

uncut dune
#

oh Ik whats wrong

cosmic dagger
eternal falconBOT
uncut dune
#

I mean not big

#

badly written

cosmic dagger
#

i always use for loops bc it's easy to modify, change, stop, and start based on a condition . . .

unreal phoenix
#

i never use for loops

rich adder
#

yeah for loops are the best

uncut dune
#

dont get too scared

unreal phoenix
#

Banned

uncut dune
#

wha-

#

somehow Im not getting errors but it is also not working

cosmic dagger
#

my first issue is the paramater n for the shootHitScan method. it does not explain what it is used for or supposed to do . . .

uncut dune
polar acorn
cosmic dagger
#

okay, cuz i have to search for n within the code, then read where it's used to figure out what it's suppose to be . . .

uncut dune
unreal phoenix
#

I still don't know what the purpose of this code is

uncut dune
#

I'll show u

unreal phoenix
polar acorn
bitter carbon
#

this is really wierd, it is doing the if when it got to 14/15 instead of 2

cosmic dagger
uncut dune
#

this is what it does

#

it was working good I just want to be able to change a variable if I want the weapon to bounce the shot

polar acorn
uncut dune
unreal phoenix
polar acorn
#

why not just check if it's 15 instead of doing all that bitwise math?

bitter carbon
uncut dune
#

but starting from the pos of the wall to the next wall

#

also another thing that is not related do raycasts rotate according to the object rotation?

polar acorn
uncut dune
#

like if they were children of the object

uncut dune
unreal phoenix
#

I think you could have chopped this function into smaller functions to do this so that reusing some logic would be easier

summer stump
bitter carbon
polar acorn
uncut dune
polar acorn
unreal phoenix
polar acorn
bitter carbon
polar acorn
uncut dune
#

damn

polar acorn
unreal phoenix
# uncut dune what does | do

You could technically restart this function if the the bullet is able to bounce, if there is a max bounce count you woul also subtract from that

uncut dune
summer stump
polar acorn
bitter carbon
#

nah but it isnt yes or no, it is checking a number ( for example 8) and seeing if it is the same as 2 Or 5 Or 7

polar acorn
#

That's what a Boolean is

uncut dune
polar acorn
#

|| compares to booleans and returns a boolean

bitter carbon
rich adder
polar acorn
summer stump
bitter carbon
rich adder
bitter carbon
#

thanks everyonme

polar acorn
bitter carbon
swift crag
#

You can keep doing this forever, or you can just take some time to learn the language

summer stump
#

Sorry guys... 😭 lol

swift crag
#

I'm not going to help you if you refuse to help yourself

unreal phoenix
polar acorn
polar acorn
#

You don't seem to understand types or functions. You're treating numbers and booleans as if they're interchangeable

polar acorn
unreal phoenix
summer stump
uncut dune
#

good to know

zenith cypress
summer stump
zenith cypress
#

Yeah, I gotcha

bitter carbon
buoyant knot
#

anyone know what would set a kinematic rigidbody2D 's velocity to zero?

polar acorn
rich adder
polar acorn
#

You need to actually internalize what it means not just "Yeah that looks right"

unreal phoenix
zenith cypress
#

Setting it to kinematic sets the velocity to zero afaik ah only for 3d ones nvm

swift crag
buoyant knot
#

2D rigidbodies do have velocity

swift crag
#

that is fine

rich adder
swift crag
#

it is acceptable to not understand things

rich adder
#

thats what makes them Kinematic afaik

bitter carbon
buoyant knot
rich adder
#

do they? I barely do 2D physics

#

afaik Kineamtic 3D have 0 vel

swift crag
swift crag
#

Follow some of the introductory tutorials. Get through the tutorial, then play around with the code you've written.

bitter carbon
bitter carbon
unreal phoenix
bitter carbon
summer stump
rich adder
bitter carbon
summer stump
#

And don't skip around for what you want to learn. Just do it all

queen adder
#

Guys my health and damage codes do not work

#

Help please

swift crag
summer stump
cosmic dagger
eternal falconBOT
polar acorn
swift crag
#

I think it's on line 13

polar acorn
#

And what is the problem

fringe pollen
#

MaxHealth = -amount; in DecreaseeHealth I am supposing

queen adder
# polar acorn And what is the problem

The problem is that the Damage system doesn't quite work, meaning that it should every time i touch the object with the damage script it should decrease the health but it doesn't

queen adder
polar acorn
queen adder
polar acorn
queen adder
#

Yeah

fringe pollen
polar acorn
queen adder
summer stump
#

Put a debug in the OnCollision and OnTrigger methods to see if you receive those messages

fringe pollen
polar acorn
#

not a yes or no question

#

you tell me what is not happening

summer stump
polar acorn
#

that you are expecting to happen

queen adder
#

What is supposed to happen is maxhealth gets decreaseed by the damage

silent obsidian
#

Hello guys. How can I get the same behaviour as in "GetAxis("Horizontal")" with the new input system?

I don't want it to jump instantly from 0 to 1 and -1 but rather to go smoothly.

queen adder
polar acorn
summer stump
queen adder
queen adder
polar acorn
# queen adder No

Then it would seem that whatever object has the Damage script on it is never colliding with something that has a PlayerHealth component

swift crag
summer stump
#

Nm, yeah there is

polar acorn
weak isle
#

And does enemy have a collider

polar acorn
#

Show the inspectors of the Enemy and the PlayerHealth objects

queen adder
weak isle
#

queen adder
polar acorn
weak isle
#

Yeah was gonna reference that

queen adder
#

I am a fucking dumbass

swift crag
#

Character controllers can absolutely cause OnTriggerEnter to execute. I just checked.

#

A character controller that moves into a trigger collider will receive an OnTriggerEnter

queen adder
#

So it should work?

polar acorn
swift crag
#

I do not receive OnCollisionEnter, though.

polar acorn
#

A solid collider will fire OnControllerColliderHit instead

swift crag
#

yep, that seems consistent

summer stump
buoyant knot
#

I'm so confused by my physics engine. I just can't move my kinematic RBs unless I set their velocity. MovePosition just doesn't seem to move them to a given position

#

2D, so velocity does matter

#

I can MovePosition(Vector2.one) to avoid any calculation issues, but the line gets called, and the body doesn't move

ripe shard
vagrant lynx
#

Hello guys, I have a simple question....

#

How to get this everytime I enter

#

But not this

polar acorn
queen adder
buoyant knot
vagrant lynx
polar acorn
buoyant knot
#

fyi, my rigidbodies are kinematic Rigidbody2D

buoyant knot
#

they can have velocity AND moveposition. It works if I change their velocity, but I don't think it is right.

ripe shard
vagrant lynx
#

And I was talking about the curly brackets

polar acorn
ripe shard
#

you're overriding one with the other

buoyant knot
#

I see. well, kinetic rigidbodies do have a .velocity assigned

ripe shard
#

just DONT use velocity AND MovePos when you have a kinematic rb

buoyant knot
#

ok, I'll test that out

#

I tried setting the velocity to zero, to allow the moveposition to go unencumbered, but that does not work

ripe shard
#

actually, never use both

#

you are trying to do too much, just let the system work

vagrant lynx
buoyant knot
#

I am trying to figure out how to tell the system "I know exactly where I'm going. just go there."

ripe shard
buoyant knot
#

I am making a system for that. first I need to just get things moving

eternal needle
ripe shard
#

if you don't want collisions, ie you want to teleport, set the rb position directly

#

if you want to have collisions, use MovePosition with a delta that is relatively small

buoyant knot
#

I'm not worried about collisions right now

ripe shard
#

MovePosition will calculate the velocity to get to the destination in 1 update, if you ALSO set velocity, you will override whatever MovePosition has calculated

buoyant knot
#

assume I will deal with collisions later. I am right now trying to get the body to move in a vacuum

uncut dune
buoyant knot
#

I'm not moving transform

#

that will actively screw with what I'm doing. I need to move the RB

uncut dune
#

why dont u use MovePosition like mentionedbefore

buoyant knot
#

I'm trying but the system is confused because .velocity was screwed with

#

I think I need to refactor the way anikki mentioned

#

so .velocity never gets touched. I wish I could just make 2D kinematic RBs not use their velocity in simulation

ripe shard
#

then you can't have collision interpolation

#

you can't have physics and not have physics at the same time

buoyant knot
#

I will take care of collisions myself

#

I just want the physics system to generate contacts at the end

ripe shard
#

then just move the freaking transform

buoyant knot
#

I'm making a physics engine to figure out the in-betweeen

vagrant lynx
buoyant knot
#

assume I can calculate the target destination accurately

silent obsidian
# vagrant lynx Oh yes!, I'll check the settings. Thank you
{
    "FormattingOptions": {
        "NewLinesForBracesInLambdaExpressionBody": false,
        "NewLinesForBracesInAnonymousMethods": false,
        "NewLinesForBracesInAnonymousTypes": false,
        "NewLinesForBracesInControlBlocks": false,
        "NewLinesForBracesInTypes": false,
        "NewLinesForBracesInMethods": false,
        "NewLinesForBracesInProperties": false,
        "NewLinesForBracesInObjectCollectionArrayInitializers": false,
        "NewLinesForBracesInAccessors": false,
        "NewLineForElse": false,
        "NewLineForCatch": false,
        "NewLineForFinally": false
    }
}

create an omnisharp.json file in the root of your project

buoyant knot
#

also, I do not know if assigning rigidbody.position is a problem

#

for the middle of a calculation, I basically want to teleport an RB around, then teleport it back to where it started when I'm done.

delicate portal
#

Hey! How can I rotate an object from its center? I used this but this will rotate it by the pivot:
transform.parent.eulerAngles += new Vector3(0, rot, 0);

uncut dune
buoyant knot
#

ok, it seems like MovePosition overwrites anything going on with velocity

uncut dune
silent obsidian
#
    private void OnEnable() {
        playerInputActions.Player.Jump.Enable();
        playerInputActions.Player.Jump.performed += DoJump;
        playerInputActions.Player.Movement.Enable();
        playerInputActions.Player.Movement.started += DoMove;
        playerInputActions.Player.Movement.canceled -= DoMove;

    }

    private void DoMove(InputAction.CallbackContext context)
    {
        hzInput = playerInputActions.Player.Movement.ReadValue<float>();
        rb.velocity = new Vector3(hzInput * speed, rb.velocity.y, 0);
        
    }

Should the movement logic be in a fixedupdate instead ;-?

Right now if i tap the left button it just keeps walking towards that direction. I suppose that's because .canceled -= DoMove; is not the right way to do it.

buoyant knot
#

I think this is ok

#

the .canceled is wrong

#

-= removes the function from getting called

#

it does not make the function do the opposite

silent obsidian
#

Hm, then how could I make the function get called only when the "left"/"right" button is pressed.

delicate portal
#

Hey! How can I rotate an object from its center? I used this but this will rotate it by the pivot:
transform.parent.eulerAngles += new Vector3(0, rot, 0);

buoyant knot
#

you should subscribe functions for .started, .performed, and .canceled

buoyant knot
#

canceled would be something like: you were holding a button, and tabbed out. the program had the input actually interrupted

#

OR it got canceled because a different type of callback is going (e.g. long press will cancel the tap interaction)

silent obsidian
#

so i should just change the .canceled to .performed?

delicate portal
buoyant knot
#

if tap gets canceled by tabbing out, you also want to register it as letting go

wintry quarry
buoyant knot
#

else the program will keep the player moving while tabbed out

silent obsidian
#

So what i would want to do is to remove the function from getting called on the .performed and .canceled event and add it on .started ?

buoyant knot
#

Add the function to being called from all 3

#

it is reading the value in the function anyway

vagrant lynx
silent obsidian
#

Ohh okay I see. I understand now.

#

Thank you

silent obsidian
buoyant knot
#

is that input a control stick actually?

silent obsidian
#

nope, keyboard key

vagrant lynx
buoyant knot
#

nvm then. ok

delicate portal
silent obsidian
vagrant lynx
silent obsidian
#

Yep

vagrant lynx
#

Okay

silent obsidian
rich adder
delicate portal
rich adder
eager elm
rich adder
#

.center prop

#

iirc you can also get it from the mesh/renderer if you have no collider

delicate portal
#

Oh god it works!

#

Thanks!

#

Also, how can I make the cursor is on the center of the transform?
Now I am just setting the pivot's position where the cursor looks:
BuildingGhost.Instance.transform.localPosition = raycastHit.point;

delicate portal
rich adder
delicate portal
#

Let me show you

silent obsidian
delicate portal
rich adder
delicate portal
#

Sure, bot how?

rich adder
# delicate portal Sure, bot how?

basically you make a new child object place it where you wuld want pivot to be then reverse the order, make the parent now the child of this object. obv put this object outside the parent first

delicate portal
#

Also, any other options avalailbe if possible? Because the buildingghost gameobject can be various and their pivots can be different

rich adder
delicate portal
#

Yeah but that is a vector3 and not a transform

rich adder
#

the parameter is a vector3

delicate portal
#

Yes, so I should set the BuildingGhost's position to the cursor's position as there is now, and then use that Vector3?

rich adder
#

ehh actually I think you would need to do some math and get the offset
then put that in the follow transform for the ghost

formal escarp
#

Hey guys quick question. How can i make it so when i impact against a certain object a certain sound effect comes out?

cosmic dagger
rich adder
delicate portal
#

Sorry for bothering you this much, what kind of math should I use here?

#

So like I'm completely dumb

#

Use the center I assume

formal escarp
rich adder
#

that should be your offset

cosmic dagger
delicate portal
formal escarp
delicate portal
#

And then BuildingGhost.transform.position + offset = cursorPos

bitter carbon
#

anyone know how i can make it so there is around 40 different things in here, but in a different way as it will be very untidy and worsen performance if i write them all out

#

like maybe some sort of maths pattern

cosmic dagger
formal escarp
cosmic dagger
cosmic dagger
bitter carbon
#

i asked chat gpt but i think ur method is better🤣🤣

cosmic dagger
polar acorn
bitter carbon
polar acorn
swift crag
#

Explain what you want to make your game do

#

not "check these 40 numbers"

#

What gameplay are you creating?

bitter carbon
#

so ill probably end up doing in a list but

summer stump
#

A timer that goes off more often as the game goes on?

bitter carbon
cosmic dagger
#

i'd just use an animation curve that changes the value of the variable and you check that against your time . . .

polar acorn
swift crag
swift crag
#

I don't ask irrelevant questions.

summer stump
bitter carbon
#

i dotn reeally wanna explain if it doesnt matter so can u say why its impirtant

polar acorn
swift crag
#

Asking about your original goal, rather than whatever solution you attempted, will help people help you.

silent obsidian
#
private void DoMove(InputAction.CallbackContext context)
    {
        hzInput = playerInputActions.Player.Movement.ReadValue<float>();
        rb.velocity = new Vector3(hzInput * speed, rb.velocity.y, 0);
    }

    private void FixedUpdate() {
        CharacterRotate();
        Debug.Log(rb.velocity);
        Debug.Log("hzInput: " + hzInput);
        Debug.Log("speed: " + speed);
    }

Seems like my velocity on the X axis slowly decreses the longer I hold a button pressed down. ;-?
Is it because I'm not running the movement logic inside a fixedUpdate method?

cosmic dagger
bitter carbon
swift crag
swift crag
#

I prefer to use InputActionReference to get values. It makes things super easy.

public InputActionReference someAction;

...

someAction.action.ReadValue<float>();
#

I just read the value every frame and use it directly

polar acorn
cosmic dagger
bitter carbon
#

so, there is a timer that starts when the game starts,it goes up in seconds

every x amount of seconds it needs to give a message to a plant in my game so the plant will know when to develop/grow

this x amount of seconds needs to decrease the incrimenting over time so it makes the game harder, otherwise it could go on forever

#

i made a typo so reread before reply

polar acorn
rocky canyon
#

wow, cool.. thanks for remembering lol!

bitter carbon
polar acorn
#

Like, what is the actual math you intend to use to decrease x by

bitter carbon
#

well i was gunna just manually type it so i wanted to know how best to store it but i might think of a formula to do it i havent decided asi dotn nkow lal the options, for exmaple there might be a built in thing that already achieves this

rotund gorge
#

oof

bitter carbon
#

ummmm^^ MODS

summer stump
#

<@&502884371011731486>

silent obsidian
#

pathetic

polar acorn
#

bah

#

Sorry @queen adder you're cool but your name is too close to <@&502884371011731486>

bitter carbon
#

why are there no mods?

summer stump
rich adder
bitter carbon
#

ok its gone

summer stump
#

That would be a linear reduction though

cosmic dagger
#

yeah, they need a formula . . .

summer stump
#

You could use a formula

Edit: ah, as random said

bitter carbon
summer stump
polar acorn
bitter carbon
#

like maybe so it decreases the incrementation each time by 0.3 then rounds it

#

ima think about it in paint rq

subtle hedge
#

the foot moves how is supposed to when i'm not adding the height offset

inner marsh
#

im referencing a public static bool from a helper script, but it says that the helper script doesnt contain a definition for that referenced bool public static class TargetInfo { public static bool isTargetInRange(Vector3 rayPosition, Vector3 rayDirection, outRaycastHit Hitinfo, float range, LayermMask mask); { return (Physics.Raycast(rayPosition, rayDirection, out Hitinfo, range, mask)) } } bool referenced

    {
        RaycastHit hitInfo;
        if(TargetInfo.isTargetInRange(cam.transform.position, cam.transform.forward, out hitInfo, hardpointRange, shootableMask))
        {
            //create laser hit particles
            foreach(var laser in lasers)
            {
                Vector3 localHitPosition = laser.transform.InverseTransformPoint(hitInfo.point);
                laser.gameObject.SetActive(true);
                laser.SetPosition(1, localHitPosition);
            }
        }``` where its being referenced
polar acorn
subtle hedge
inner marsh
cosmic dagger
languid spire
polar acorn
#

There's nothing in it

cosmic dagger
inner marsh
#

yea i forgot to save that, now i got 10 errors instaed of 1 💀

inner marsh
rich adder
#

is your IDE even configured ?

polar acorn
# inner marsh

Yeah there's quite a bit of syntax errors. Look at the stuff underlined in red, you're probably missing something

inner marsh
#

using vscode

#

no "ide" stuff works

rich adder
inner marsh
#

i followed the guide

#

as it stated

#

installed plugins as it said'

rich adder
#

followed the guide is vague

#

many people followed the guide and still did it wrong

summer stump
inner marsh
#

all three are installed

rich adder
inner marsh
summer stump
#

What does the External Tools menu look like in Unity

rich adder
#

ah so you skimmed thru it

summer stump
subtle hedge
rich adder
#

like everyone else

summer stump
#

Remove the Engineering package

#

Then you can update it

#

Needs to be 2.0.20 at least

#

Also, you do not need the Visual Studio Code Editor package. It may cause problems

Both IDEs use Visual Studio Editor

rich adder
#

"followed the guide"
does 1 step

inner marsh
#

ig ill go follow the whole guide again

#

fun

summer stump
rich adder
#

its like 2 more steps

#

you lucky it aint what vscode was like w unity

polar acorn
primal burrow
#

how do you make a brodcast audio/measage like recroom does when its going under maintnence

bitter carbon
#

are negative decimals always double or can u make it a float

rich adder
#

what does that even mean?

#

not everyone plays recroom

ivory bobcat
inner marsh
bitter carbon
subtle hedge
summer stump
primal burrow
polar acorn
rich adder
#

put some type of effort into your questions..

polar acorn
polar acorn
#

If you want offset in other directions, you're gonna need a vector that is in that direction

swift crag
subtle hedge
#

like this ?

swift crag
#

this does not make sense

#

it would add more and more height as you get further vertically from the origin

polar acorn
primal burrow
polar acorn
#

But it also sounds like you just want to play a sound

subtle hedge
primal burrow
swift crag
primal burrow
#

but how will they hear/see it

polar acorn
#

Position is where the foot is

swift crag
#

well, I guess it kind of does

polar acorn
#

footPosition is where the ray hits

swift crag
#

but I don't know how your multiplayer architecture works here

ivory bobcat
quasi rose
rich adder
primal burrow
bitter carbon
#

anyone know why this doesnt work

swift crag
polar acorn
bitter carbon
polar acorn
slender nymph
polar acorn
polar acorn
#

So just use footPosition

subtle hedge
polar acorn
#

You're currently adding an offset on the Y axis to where the ray hits

ivory bobcat
subtle hedge
bitter carbon
subtle hedge
#

the foot only moves on the y and not on the x and z

polar acorn
swift crag
bitter carbon
#

ok that is what it was siuppoised to be

rich adder
#

no operation there

polar acorn
bitter carbon
summer stump
bitter carbon
#

j = 9

polar acorn
summer stump
#

And that doesn't make much sense there either

bitter carbon
#

wait lemme think

rich adder
#

whats 9 -0.6 mean

primal burrow
bitter carbon
polar acorn
summer stump
rich adder
bitter carbon
summer stump
#

That just lists two numbers

subtle hedge
ivory bobcat
# bitter carbon wdym

If you placed i + 3 - z / x you'd still get an error. These aren't statements. Invalid mumbo jumbo.

bitter carbon
primal burrow
rich adder
summer stump
polar acorn
#

Is that what you want?

bitter carbon
polar acorn
summer stump
polar acorn
#

Two numbers standing next to each other is just a pair of numbers

swift crag
#

I'm not seeing what y'all are seeing. that is a valid expression

ivory bobcat
swift crag
#

it's just that you need a statement there

delicate lagoon
sturdy lintel
#

This is my script which is attached to a moving blue ball. I want it to cast projections as shown in the photo (black cylinders of S(0.02f,len,0.02f) ). I am trying to do something of that sort in the for loop line 39-50. But there seems to be some problem with my math.
This is a college assignment & we are not allowed to use raycasts to do our projections, but rather just pure vector math. Can someone please help me out? @slender nymph or anyone?

TravellingBalls.cs : https://pastebin.com/HPT09Y7U
Reference Script from Github: https://github.dev/Apress/basic-math-for-game-dev-w-unity3d/blob/master/Chapter-6-Examples/Assets/EX_6_4_MyScript.cs

primal burrow
subtle hedge
delicate lagoon
summer stump
bitter carbon
#

ok ill be afk for a bit

swift crag
#

this needs to go in a thread if it continues

slender nymph
#

also wtf. why ping me specifically?

sturdy lintel
summer stump
sturdy lintel
polar acorn
ivory bobcat
polar acorn
#

So, when you add height, the ray actually hits the ground

#

and therefore moves the foot to the ray's position

sturdy lintel
quasi rose
bitter carbon
#

my unitys been loading for 15 min💀💀

#

how can i restart my pc without losing my work

slender nymph
#

you probably have an infinite loop

sturdy lintel
slender nymph
#

what would make you think that was in reference to your issue?

bitter carbon
fickle plume
slender nymph
#

most likely in some object's Awake or Start method

ivory bobcat
sturdy lintel
fickle plume
bitter carbon
#

i think it is that cuz it sais waitign for code to exucute

#

but i am making all my code green with //

#

and it isnt fixing