#💻┃code-beginner

1 messages · Page 250 of 1

wintry quarry
#

It Checks for colliders that overlap a circle

rancid tinsel
last basin
frigid sequoia
#

Why is this causing my object to wiggle when it gets close to the target?

wintry quarry
#

do this instead:
transform.position = Vector3.MoveTowards(transform.position, objectToFollow.transform.position, speed * Time.deltaTime);

frigid sequoia
wintry quarry
#

it will clearly overshoot ¯_(ツ)_/¯

#

think about it

frigid sequoia
#

Why is that?

wintry quarry
#

Because it doesn't overshoot

#

also - you're using transform.Translate wrong

#

you're using world space positions and Translate works in local space by default

frigid sequoia
wintry quarry
#

your object is itself

#

once you translate, rotate, or scale your object away from the origin, they are completely different coordinate spaces

frigid sequoia
#

So... why is that .MoveTowards does not overshot?

wintry quarry
#

because it was written not to

#

they programmed it not to

#

the new position does not overshoot target

ember tangle
#

Oh nice I have a similiar question

wintry quarry
eternal falconBOT
frigid sequoia
#

I am kinda asking it more in depth cause I was trying to avoid the overshoot my self by applying a direct transform directly when being very near the target and couldn't make it work

wintry quarry
#

that's throwing EVERYTHING off

#

You can certainly replicate the MoveTowards behavior manually if you want

#

it's not complicated

#

but you do need to be using the correct inputs and working in the correct coordinate space

sterile moon
#

How could I allow something to freely flop around on the z axis based on movement around it, like gravity. Think antennas, or, towing arm that needs to be able to pivot loosely

wintry quarry
#

``` not '''

frigid sequoia
#

Ok, I will try avoidind tranlate in world space, and... kinda in general actually, MoveTowards looks way more usefull

ember tangle
#

I'm trying very modestly to make a game object rotate to an angle.

Vector3 to = new Vector3(0, 0, 18); 
transform.eulerAngles = Vector3.Lerp(transform.rotation.eulerAngles, to, Time.deltaTime);

works fine

Vector3 to = new Vector3(0, 0, -18); 
transform.eulerAngles = Vector3.Lerp(transform.rotation.eulerAngles, to, Time.deltaTime);

spins forever. I do not understand why.

wintry quarry
#

don't use them

teal viper
ember tangle
#

Its a 2d game

#

gimbal lock doesnt matter to me

wintry quarry
#

the problem of euler angles transcends beyond gimbal lock

#

you're seeing it now

ember tangle
#

Ok I believe you

sterile moon
wintry quarry
#

the joint

sterile moon
#

its all parented, but if i add rigid body, it falls off the truck when game starts. If i turn off gravity, it wont mvoe with truck

teal viper
sterile moon
#

I see

whole idol
#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Beginning_CSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World");
        }
    }
}

this might sound like a stupid question but why do you need to import all these frameworks and assets if the program works fine just like this:

namespace Beginning_CSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World");
        }
    }
}

???

wintry quarry
#

any other questions?

#

also this isn't a Unity question

whole idol
#

I know you dont have to but why?

wintry quarry
#

Why don't you have to?

#

Is that what you're asking?

#

DO you know what using does?

whole idol
#

the program works fine without it yeah but the IDE automatically loads these assets everytime right?

wintry quarry
#

It's very simple.

In your example you are using Console.WriteLine

#

that's a function in the Console class

#

the full name of the Console class is System.Console

#

the only thing that using System; does is let you write Console instead of the full System.Console

#

that's it

#

it does nothing else

#

you're not using the rest of them at all so you don't need them

fierce geode
#

Hey, how would you combine a camera's rotation along side the player's rotation. To do the whole camera-directed player. Like it goes in the direction the camera is rotated.
I did like
Quaternion yaw_rot = Quaternion.Euler(0, cam.transform.rotation.eulerAngles.y, 0);
move_vector = yaw_rot * move_vector;

and it worked fine for flat surfaces, but it caused issues when travelling up slopes, Like I needed the character to travel through a loop and the movement would always stuff itself up

wintry quarry
wintry quarry
fierce geode
#

Thanks man, been banging against this loop for like a week

young wren
#

Hi i start to work with scriptable object's and i wanted to use them as keeper of state of objects but im curious if thats possible to make it run an function or make script that would watch changes in attached value and then call funcion for example like active or disactive GameObject by value of that ScriptableObject

public class BoolValue : ScriptableObject, ISerializationCallbackReceiver
{
    public bool initialValue;

    [NonSerialized]
    [HideInInspector]
    public bool value;

    public void OnBeforeSerialize() { }

    public void OnAfterDeserialize()
    {
        value = initialValue;
    }

    public void Togglevalue()
    {
        value = !value;
    }

    public void Setvalue(bool newState)
    {
        value = newState;
    }
}
wintry quarry
ember tangle
wintry quarry
#

the fact that -5 and 355 are the same angle

#

your code doesn't account for it

#

I don't recommend euler angles and I especially don't recommend reading them back from a Transform like this

#

you never know if you'll get -15 or 345

ember tangle
#

alright I'll just learn to read them from the Quaternion although it scares me

young wren
wintry quarry
#

you shouldn't

#

that's the dangerous thing

ember tangle
#

Im trying to pull the z rotation value for some if statements

wintry quarry
wintry quarry
young wren
#

To call an function when value of exact ScriptableObject changes

ember tangle
#

private bools in the object that toggle based on the rotation angle.

wintry quarry
#

I assure you, you don't need the angle, and there's a better more reliable way.

tall delta
# ember tangle I'm trying very modestly to make a game object rotate to an angle. ```cs Vector3...

I find this question intriguing, because I remember dealing with this same 'eulerAngles' shit when I just started learning unity. I'll try my best to give a simple answer: when you try to set rotation to -18 degrees using vector.lerp, unity internally interprets this as +342 degrees (since 360 - 18 = 342) due to how it handles angle normalization. during the lerp process, instead of moving directly to the intended angle, unity recalculates the target as a positive angle. and so when you try to to "subtract" towards -18 degrees each frame, the interpolation actually "adds" a small increment towards 342 degrees due to unity's internal conversion to quaternions and back to Euler angles... so you spin ad infinitum.

#

that took waaay too long to write and I see that you have moved on 😄

ember tangle
near wadi
#

are these not valid?

            EnableDebugView(true);
            SetDebugView(DebugView.Normals);
supple night
#

Hi.
I'm trying to make a rigidbody move based on the movement of another rigidbody.
I'm using this logic:

_rb.velocity = attachedRigidbody.velocity;

But the rigidbody doesn't move at all. He just moves forward and back. I would like him to follow the other.

wintry quarry
#

what do you actually want

supple night
#

I want him to follow

#

But not in the same velocity, honestly

#

I want to do something like MoveTowards

#

But using the rigidbody physics

wintry quarry
#
Vector3 diff = attachedRigidbody.position - _rb.position;
Vector3 velocity = diff.normalized * speed;
_rb.velocity = velocity;``` as a basic starting point for example
dusky hazel
#

I am trying to use visual scripting for the first time, and this might be a dumb question but how do you move around in the editor? All I can do is scroll up and down and add nodes.

wintry quarry
#

I think it's middle click and drag?

#

something like that

dusky hazel
#

thank you!!

tall delta
#

#763499475641172029 might be a better place to ask, but it also sounds like you should maybe watch / read a few 'how to unity' tutorials

dusky hazel
#

it works

dusky hazel
supple night
wintry quarry
#

if you want to do it with actual forces it's much harder. You'll basically need to write a PID controller for that

supple night
#

Honestly, the result is a bit "strange". Could it be because I changed the object position using transform.position?

wintry quarry
#

which object

#

yes

supple night
#

If i drawline to see vector, they always are in the same position

wintry quarry
#

you should not be moving Rigidbodies with transform.position

#

maybe show your code

supple night
#

How i "teleport"?

wintry quarry
#

rb.position = newPosition

supple night
#

The same for rotation?

wintry quarry
#

There's also MovePosition/MoveRotation

#

what are you trying to do?

supple night
supple night
supple night
#

Is for a test

wintry quarry
#

Good news, the physics engine does that automatically

supple night
wintry quarry
#

I don't understand, nor do I understand why you're using Rigidbodies then

supple night
#

Without rigidbody i thought that not going to be possible

supple night
wintry quarry
#

you seem to be saying you're not allowed to but then you're using it anyway

supple night
#

No

#

Honestly, i think i can..

#

I'm not allowed to use joints, for example

#

Anyway, i don't understand why what i'm doing doesn't work

wintry quarry
#

well you've barely shared any details about it so nobody else is going to be able to understand either.

supple night
#

If i apply the same speed, shouldn't they at least move?

#
var velocityChange = attachedRigidbody.velocity - enemyCharacter.Rigidbody.velocity;
velocityChange = velocityChange.normalized * 10.0f;

enemyCharacter.Rigidbody.MoveRotation(attachedRigidbody.rotation);
enemyCharacter.Rigidbody.velocity = velocityChange;
wintry quarry
#

that's not applying the same speed

#

also this assumes either object is actually moving via Rigidbody velocity

supple night
#

Yes

#
var currentVelocity = _rigidBody.velocity;    
var targetVelocity = direction * speed;

var force = targetVelocity - currentVelocity;
force = Vector3.ClampMagnitude(force, maxForce);

var lookRotation = Quaternion.LookRotation(direction);
lookRotation = Quaternion.Slerp(transform.rotation, lookRotation, speed * Time.fixedDeltaTime);

_rigidBody.MoveRotation(lookRotation);
_rigidBody.AddForce(force, ForceMode.VelocityChange);
#

The other rigidbody movement

#

If i do this:

enemyCharacter.Rigidbody.AddForce(attachedRigidbody.velocity, ForceMode.VelocityChange);
enemyCharacter.Rigidbody.MoveRotation(attachedRigidbody.rotation);

Nothing happens

#

Except for the rotation 🤣

supple night
minor patio
#

I just thought I'd drop in to say I'm back on track
minor skill issue concerning properties vs fields XD

rancid tinsel
#

how would I make this instantiate as a child of the object holding the script: GameObject bulletObj = Instantiate(bulletPrefab, firingPoint.position, Quaternion.identity);

supple night
rancid tinsel
minor patio
rancid tinsel
fierce geode
#

Do you guys ever go back and refactor your code mid-problem? Thinking about going back and restarting my character movement code; starting from scratch with what I've learnt to maybe overcome and find out whatever rotation is doing to my movement code.

teal viper
teal viper
fierce geode
#

I'm 50/50 on understanding the problem

supple night
fierce geode
#

Honestly the second reason I'm refactoring, is doing a test where basically I'm removing elements of the code and breaking it down to it's bare essentials

#

and seeing if the problem still occurs or if it's affected by another area I didn't consider

teal viper
warm condor
#

Hey. I am having a problem where the animations that I want to play are overlapping. I can I stop this from happening?

        ChangeAnimationState(playerAnimations.AccelerationBeforeRunning.ToString());//the playerAnimations is an enum containing all of the animation                                                                                          //names 
        if (playerAnimator.GetCurrentAnimatorStateInfo(0).IsName(playerAnimations.AccelerationBeforeRunning.ToString())){
            ChangeAnimationState(playerAnimations.Run.ToString());
        }
    }```
teal viper
warm condor
#

meaning one animation is trying to play, but the other is trying to play as well. So they are both trying to take priority.

primal turtle
#

why does it not work if I add the code>

#

and spam clones?

teal viper
teal viper
primal turtle
primal turtle
warm condor
teal viper
primal turtle
teal viper
eternal falconBOT
primal turtle
#

why does the update code affect the clone spawning? Before you ask, logic.deleteSegment isn't used in the instantiate process

summer stump
#

Are you gonna show the logicscript?

primal turtle
#

and deletion is only used in this script

primal turtle
#

the bottum is the spawning

#

and a trigger tells it when to activate, but it should automatically stopped as soon as it's called as I do that before the cloning/spawning

summer stump
#

SegmentCreation

primal turtle
#

here's the trigger script aswell

primal turtle
warm condor
#

I want to be able to transition from the accileration animation to the running animation

teal viper
teal viper
primal turtle
primal turtle
summer stump
#

Which is a big issue

summer stump
#

Like checking what you are colliding with

#

Right now if ANYTHING hits the trigger you create that segment

#

I don't like the way everything is controlling varioua things in different scripts either

primal turtle
summer stump
#

The architecture is pretty dangerous

primal turtle
#

true

#

how would I make it only collide with a tag or smt?

#

cause you're right, that'd probably fix it.

silver timber
#

check the tag in OnTriggerEnter collider's gameobject and return early if it's not the right one

primal turtle
#

documentation?

summer stump
teal viper
primal turtle
primal turtle
warm condor
primal turtle
#

what's the difference between start and awake

teal viper
summer stump
silver timber
supple night
fierce geode
#

` Vector3 right = cam.transform.right;
right.y = 0;
Vector3 forward = cam.transform.forward;
forward.y = 0;

    //The horizontal and vertical speed values if accelerating/deccelerating.
    Vector3 hor_speed = (player_input.x * right) * (is_hor_accel ? accel_speed : deccel_speed);
    Vector3 ver_speed = (player_input.y * forward) * (is_ver_accel ? accel_speed : deccel_speed);`
teal viper
wintry quarry
#

it won't work for a loop though

#

you mentioned a loop and inclines so I mentioned using a surface normal

silver timber
wintry quarry
#

yep - might as well not have a Rigidbody if they're kinematic

#

(other than for collision detection callbacks)

supple night
silver timber
#

Kinematic = no physics movement
So kinematic ragdoll rigidbodies won't fall or do anything.

supple night
#

Even though I have another rigidbody that is normal?

fierce geode
silver timber
#

They should all be non-kinematic if they should all have active physics

wintry quarry
supple night
silver timber
teal viper
supple night
#

Sure

teal viper
#

Preferably showing the issue and all the details at runtime.

supple night
#

I have this structure:

EnemyBoy have the rigidbody that is in non-kinematic
mixamorig have the ragdoll rigidbodies that is in kinematic

silver timber
#

do you want the ragdoll to fall like a ragdoll? then make them all non-kinematic

supple night
#

Yes

#

They fall, then they get up

teal viper
#

Wasn't the issue being that enemy doesn't follow the player or something?

rich adder
supple night
rich adder
fierce geode
# wintry quarry Well you said my method "didn't work" I assume you didn't actually provide a cur...

It was probably just some other error from the weird ass way I've written my code, Like a comparison between moving forward between your solution(1st one) and mine. Also the white line sticking up is a line pointing in the direction of the ground normal so I'm like 10% sure its not me getting the ground normal wrong.

supple night
#
    public void SetKinematic(bool isKinematic)
    {
        _collider.enabled = isKinematic;
        foreach (var bodyPart in _bodyParts)
        {
            bodyPart.isKinematic = isKinematic;
        }
    }

    public void SetOnStack()
    {
        foreach (var ragdollCollider in GetComponentsInChildren<Collider>())
        {
            ragdollCollider.enabled = false;
        }

        Rigidbody.isKinematic = false;
        _collider.enabled = true;
        _animator.enabled = true;
        _animator.SetTrigger(OnStackHash);
    }

This peace of code make the logic. Before i apply physics, i call:

enemyCharacter.SetKinematic(true);
enemyCharacter.SetOnStack();
teal viper
# supple night Yes

Then the ragdoll is unrelated. Share more details on the root object as I suggested

teal viper
# supple night
  • Expand components
  • Record the object at runtime when the issue occurs
teal viper
# supple night

Like seriously, what kind of info am I supposed to get from that screenshot?

supple night
wintry quarry
#

my code assumed it would

#

what you actually want to do then is project the player's forward direction along the surface normal, not the camera forward

teal viper
#

You could keep the collider collapsed. That's about it

#

Everything else could be related.

supple night
silver timber
#

Are you disabling the animator after making it enter the ragdoll state?

supple night
#

The enemy that i catch, should follow player

fierce geode
supple night
#

I turn on

wintry quarry
teal viper
supple night
#

To use the "falling" anim

teal viper
#

Here's a tip: when debugging something, don't maximize the game view...

silver timber
#

Falling anim? is that different than the ragdoll state?

supple night
#

Yes

silver timber
#

Can you just breakdown in simple steps what you expect to happen so we're all on the same page?
Like

  1. Player touches enemy
  2. Enemy ragdolls
  3. Enemy gets back up and chases player
supple night
fierce geode
wintry quarry
#

I guess it really boils down to what you want

#

you will probably end up needing some special handling when the player gets on the loop

teal viper
# supple night
  1. Try disabling root motion on the animator and see if that helps.
wintry quarry
#

you want to be able to just hold W and go through the loop I suppose?

fierce geode
#

Well I just want the character to be able to move around relative to the camera and go through loops.

wintry quarry
#

"go through loops" is super vague though

#

that's a complex interaction that you need to define in concrete terms

teal viper
fierce geode
#

I want the player character to run along the edge of a spiral, whilst sticking to the floor of said spiral until exiting the spiral.

wintry quarry
#

still vague

#

there's user input involved

#

and camera angles

#

how should those things interact with how the player moves through the loop

#

that's what you need to ask and answer before you can solve it

#

What happens when I'm halfway up the loop and I start pressing A instead of W

#

do I go right or left according to the camera?

#

If I hold W the whole way through what happens?
These all need to be defined

cosmic dagger
#

right, is it a spiral staircase, or a vertical loop (loop-the-loop) like sonic?

supple night
teal viper
fierce geode
fierce geode
#

I'm pretty satisfied with what I have now

#

I'm just happy I can go through the loop with minimal problems

teal viper
# supple night

Can you show the full rb inspector of the enemy? In the video the bottom part of it is clipped.

sterile moon
#

I feel like this was way to easy of a solution for what I need to do, so, someone tell me its wrong, won't work, and theres another/better way

    void Start()
    {
        foreach (Transform child in gameObject.transform)
        {
            Physics.IgnoreCollision(gameObject.GetComponent<Collider>(), child.GetComponent<Collider>());
        }
    }
teal viper
# supple night

I'm particularly interested in constraints at runtime when the issue happens. Are they the same?

teal viper
supple night
#

They start moving

#

I dont know

#

I disabled root motion on player

teal viper
#

Can you write a full sentence in one message? What start moving? Is the issue fixed? What does the player have to do with it?

supple night
#

Barely fixed. The enemy is moving now. Slowly but moves.

teal viper
#

After disabling root motion on the player?

supple night
#

Yes

teal viper
#

That would imply that the animator was overriding the player velocity. And if you debugger the velocity properly, you'd see that a long time ago.

teal viper
#

Is the player rb kinematic?

supple night
#

I "debuged" with an if (velocity == Vector3.zero) Debug.Log("Is zero");

supple night
teal viper
#

Well, that's not gonna help. What if it's a very small number, but not zero?

#

What if it's fluctuating back and forth?

#

If you were to debug the actual value, that would've been seen

supple night
#

With breakpoints?

teal viper
#

In the console. Debug logs print to the console.

supple night
#

Sometimes, i miss dd function of php codes

teal viper
#

Debug.Log("velocity: " + velocity);
Or
Debug.Log($"velocity: {velocity}");

supple night
#

I didn't know the log showed vectors

teal viper
#

It can show many things. And if it didn't, you could print each of it's components separately. Surely it would at least show floats.

teal viper
#

Well, now you know.

sterile moon
#

alright @teal viper, now that you got a second, think you can help my dumb ass? lol

teal viper
#

To be correct, the debug log is showing strings. The above snippets just convert vector to a string(use it's ToString method under the hood)

carmine turret
#

I have a weird issue where I built my game, and now either in editor or ingame the space bar just randomly isnt doing anything for a solid few seconds.

sterile moon
#

I'm clashing with colliders like its WWII, but this time I think the Germans are winning lol

supple night
carmine turret
sterile moon
#
    void Start()
    {
        foreach (Transform child in gameObject.transform)
        {
            Physics.IgnoreCollision(gameObject.GetComponent<Collider>(), child.GetComponent<Collider>());
        }
    }

This was my attempt at taking my vehicle, and all of its movable towing arm parts and making sure none of them can collide with eachother

#

It does not work it appears, the arm falls, and stops at a floating point before it hits the terrain layer

#

Now I know for a fact I'm f'ing stupid, so save me the lecture and just tell me how stupid I am, I'm sure there is a smarter way to do this lol

carmine turret
#

Ehh weirdf. nevermind, the spacebar isnt the issue. as it prints when I press ahaha.

teal viper
carmine turret
teal viper
carmine turret
#

Oh sorry no

#

the sapcebar check is in update

#

but the movement is in fixedUpdate

#

the sparebar check seems to work fine though. Im just making the jump bool public so I can see it in editor

teal viper
#

Do each of those colliders need a separate rb?

sterile moon
#

Im unaware of that component and how it works could you enlighten me?

#

I think they will need s eperate RBs because its going to be moving based on physics

teal viper
#

Google composite colliders.

sterile moon
#

Will do some looking. In the mean time, do you know a quick script for "if you hit somethings collider, tell me what you hit"

teal viper
carmine turret
#

Ehhh im very confused

#

Sometimes it works sometimes it doesnt, yet it ALWAYS prints regardless...

#

It was perfectly fine before building the game though

#
    void Update()
    {
        if(Input.GetKeyDown(KeyCode.Space) == true)
        {
            _jump = true;
            print("Jump");
        }
        else{
            _jump = false;
        }
    }
#

the print ALWAYS prints

#

but the bool doesnt always change

#

I built the game, got one error in an entirely unrelated file, fixed that errot then this started happening

teal viper
#

How do you know that?

carmine turret
#

How do I know what?

teal viper
#

That the bool doesn't change

carmine turret
#

I set it to public and Im watching it on the editor

teal viper
#

That's unreliable

carmine turret
#

sometimes its flicking on and off, sometimes it does nothing

#

I see

teal viper
#

Print it instead

#

And print it when it goes off

carmine turret
#

As in, print in the section where jumping checks if its activated?

#

Okay

teal viper
#

And print where you expect it to be true too

teal viper
teal viper
carmine turret
#

nah if I print false, then ill never see the other prints since its printing every frame 😛

teal viper
#

You can scroll the log. Do it

#

It's important, trust me.

carmine turret
#

Oke

#

The jump script just sometimes isnt activating

#

Even when it absolutely should

wintry quarry
#

delete this whole part:

        else{
            _jump = false;
        }```
carmine turret
#

If I do that, then _jump will always be triggered no?

wintry quarry
#

no

#

only when you press the key

#

FixedUpdate should consume it and then set it to false

carmine turret
#

Why would it?

wintry quarry
#

because that would be the right way to program it

carmine turret
#

I see okay.

teal viper
#

Damn, I wanted them to empirically learn that updates can run several times between fixed updates...

wintry quarry
#

oh sorry

#

i just kinda popped in

teal viper
#

Praetor spoiling the learning process mad

carmine turret
#

but this error only happened after building

#

it never ever happened in 7 hours of building and testing 🥲

wintry quarry
#

framerate dependent code issue

carmine turret
#

I see

#

But it doesnt explain why the issue happens in the editor too no?

wintry quarry
#

it does explain why it happens everywhere

carmine turret
#

I see okay. well it IS fixed, so I appreciate it

#

just gonna test it out a bit then buildd

#

Yup works in every situation where spacebar is needed! Thank you

teal viper
# carmine turret

If you were to print where you expect it to be true(in the fixed update), your log would look like that:

Space
No Space
Check the bool

Sometimes it would look like

Space
Check the bool
No space

Your code would only work correctly in the latter case.

carmine turret
#

ahh I see.

#

Oh, as a side question, if I want to make a button that basically just moves the player to the starting location (reset button), does the teleport need to be in fixedupdate, or is update fine

teal viper
#

Depends

#

Depends on how you teleport the player.

#

Also, it might not need to be in any of the updates.

#

And on your player controller as well.

carmine turret
#

Are there other ways to check input?

#

currently Im just putting it next to the space check and instead of going through the bool stuff and fixed update check, Im just calling the reset function immediately.

teal viper
#

Well, does it work?

carmine turret
#

Its mainly for testing, But i wanted to know for future referall

#

Perfectly

#

But I mainly want to know for code etiquette, I imagine in multiplayer you would want it to be fixedUpdate though?

teal viper
#

Then keep it as is. If it doesn't work, debug it.

teal viper
sterile moon
#

I dont think its collisions doing this actually. I wonder why its stopping at this position

carmine turret
#

Alrighty

sterile moon
#

if I manually put the arm lower than that then hit play, it sends the arm 180 degrees into the cab on the hinge rotation point

teal viper
sterile moon
#

i dont even know how to describe whats happening at this point. getting this damn tow truck working sucks lol

acoustic sun
#

I am having issues with my game

#

For some reason its not showing the ground and it is not working properly

rich adder
# acoustic sun

not sure where the code question is, looks like your player is not on any ground

acoustic sun
#

Its not when I play and I am trying to figure it out how to fix the issue

rich adder
#

what is " not working properly" then

acoustic sun
#

So when the I am playing the game, the character is falling through the terrian. I had added box collider but it is not working

rich adder
#

and where is the player collider

acoustic sun
#

It should be attached to the ground, but when I press play it is now showing

rich adder
#

why does the ground have a rigidbody

acoustic sun
rich adder
#

you're showing the ground selected and I see Box collider + Rigidbody

acoustic sun
#

I am not sure what I should do then. I have the both added on the ground and its still making the character fall into the ground

radiant frigate
#

yo navarone whenever you are finished helping him can i also get some help? (dont want you to feel forced so say no if you dont want to, there is no prob with it)

rich adder
#

dude just ask your question, there are prob other people

acoustic sun
#

So it waas supposed to be for the wall but its on the ground instead

#

Thats interesting

rich adder
#

ground and walls should not have rigidbodies

#

why are you putting physics objects on walls / ground ?

radiant frigate
#

okay, so how can i make a script instantiate a gameobject a certain amount of times?

radiant frigate
#

oki! ty!

wild fox
#

i need some help with understanding and making changes in the template from unity asset store, can anyone help me with that?

acoustic sun
#

I was told that I had to add a rigid body for the ground. "This will now include the Ground object in any physics simulation, however, we don't want to have the Ground object be moved by the simulation, instead it is a solid, unmoving, object. To do that in the Rigidbody component check the IsKinematic property so it doesn't move with gravity or collision."

acoustic sun
rich adder
acoustic sun
wild fox
rich adder
#

anyway that mesh collider has a mesh inside?

acoustic sun
acoustic sun
teal viper
rich adder
acoustic sun
#

Oh so like something touching it?

radiant frigate
#

i cant manage to make it spawn enemies, is there something im missing?

#

i think the for loop is written correctly

keen dew
#

it's not

#

0 >= enemies is never true if enemies is positive

radiant frigate
#

that makes enemies = 2

#

0 mus be more or the same as enemies to stop

#

and each loop i take 1 from enemies

keen dew
#

The condition in the for loop tells it when to continue, not when to stop

radiant frigate
#

OH

#

true

#

i mixed things up

#

KEWK

#

ty my man

#

you really saved me

next ledge
#

hello i need help. how i can make hold mechanic button in rythm game?

radiant frigate
#

does someone know why the code seems to hate number 4? i dont know if its possibilities but i have let the code loop for more than 100 times and unless i write at the start choosenSpawner = Random.Range(4 , 4); it seems to just not use it

keen dew
#

because Random.Range is max exclusive, i.e. 1, 4 chooses 1, 2 or 3

radiant frigate
#

ty!

fringe plover
#

I send big code yesterday, some people recommend me to change it and use await, is it good this time?

burnt vapor
fringe plover
#

but, is it enough to work?

burnt vapor
#

I generally don't advice using async void unless there is no other choise, but I would advice you wrap it in a try-catch block to avoid having an silent exception possibly breaking your game

burnt vapor
# fringe plover but, *is it enough to work?*

There's not much to say about that. You'd have to share more of the code. The only thing I can say is that writing async-awaitable code is better over Coroutines, if that's your question.

#

But even then this heavily depends on use case

#

The main question would be what the old code was and why async would be better? It's not like Coroutines are bad

fringe plover
#

it was just bunch of ifs yesterday

burnt vapor
#

So what is the reason all those methods used to take in a callback?

#

Is it some IO operation that is blocking?

#

Would be nice if you shared at least one method

#

Async code is definitely a solution to fix the callback hell you introduced initially, to answer your actual question

fringe plover
#

i wanted to use return value;, but because of API that i use (GameJolt) i didnt, ofc i was able to but i was lazy

burnt vapor
#

Right so DataStore fetches data from a file or database?

fringe plover
#

GameJolt.API.DataStore, idk tbh, it gets and sets data on GameJolt account

#

ofc its online operation and i had bugs with it... when i stop runing while entering code, i didnt recorded use promo and etc stuff

burnt vapor
#

So how did you fix this particular method to be asynchronous? Did you wrap it in a Task?

fringe plover
#

i didnt..

#

but i wrap everything in task, didnt tested yet

burnt vapor
#

What does it look like?

fringe plover
#

what look like?

#

oh i got it

#

no i didnt lol

#

still using normal method

burnt vapor
fringe plover
#

ah ye i did same

burnt vapor
#

C# like this is a little rusty. This might also work:

public Task<bool> CheckForPromoUses(string promo)
{
    var taskCompletionSource = new TaskCompletionSource<bool>();
    DataStore.Get("PROMO" + promo + "Uses", true, (string value) => {
        taskCompletionSource.TrySetResult(value != 0)
    });
    return taskCompletionSource.Task;
}
burnt vapor
#

Anyway this is definitely better off as a Task, even if the method you use takes a callback. The whole callback hell issue is avoided and it just makes the code more readable

#

If you expect these methods to pass positively, you could even have it return an exception on them. Rather than checking for positive return values you can just throw an exception and have a main try-catch block in UsePromoCode to catch any issues

#

It would make it all a lot more readable and it ensures the code doesn't silently fail in general

fringe plover
#

ok, thanks for saying

#

i may will use it, thx again.

stuck jay
radiant frigate
#

does someone know how i could make a timer in time ( seconds,not frames) between each instance?

halcyon geyser
#

Time.deltaTime

burnt vapor
radiant frigate
#

yea i know that but i cant manage to think of the way of doing it

burnt vapor
#

This way you can specify seconds specifically, and generally it reads easier

radiant frigate
#

i think i will go with couroutine since i remember having used that

#

coroutine was a ienumerator right ?

burnt vapor
#

Yes, it returns that

radiant frigate
#

that had yields inside

burnt vapor
#

Every yield takes an operator specifying how long it should wait before stepping into the next piece of code

radiant frigate
#

yeah i will do it with taht

#

and just call the courutine the amount of times i need

#

right ?

neon ivy
#

I've been using transform.rotation = Quaternion.Euler(0f, angle, 0f); to rotate my player but now that my gravity isn't always down I don't know how to set the rotation from this "local" rotation to the correct rotation based on the gravity direction.
anyone know?

teal viper
#

Share the relevant code.

neon ivy
#

to rotate the player's down to the gravity's direction I'm doing transform.up = usingPlanetGravity ? planetGravityDirection.normalized * -1 : finalGravityDirection.normalized * -1;

#

trying to find it xD

#

so I have a vector3 in the direction of gravity and multiply it by some variables to get the final vector and then to apply it I do

if (finalMovementVector.magnitude > terminalVelocity)
            {
                finalMovementVector = finalMovementVector.normalized * terminalVelocity;
            }
            velocity = finalMovementVector.magnitude;
            rb.velocity = finalMovementVector;
#

sorry I'm confusing myself let me rephrase

#

this is my movement code

private void Move()
    {
        Vector3 direction = new Vector3(moveDir.x, 0f, moveDir.y).normalized;
        if (direction.magnitude >= 0.1f)
        {

            float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
            float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime);
            transform.rotation = Quaternion.Euler(0f, angle, 0f);
            Vector3 moveDir = (Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward);
            playerMovementVector = moveDir * movementSpeed; //WIP accelerate
            playerMovementVector.y = rb.velocity.y;
        }
        if (direction.magnitude < 0.1f)
        {
            playerMovementVector = new Vector3(0f, rb.velocity.y, 0f); //WIP decelerate 
        }
    }``` and I need to change it so I can move in the correct direction now that I have a different "down".
teal viper
neon ivy
#
private void FixedUpdate()
    {
        rb.velocity = playerMovementVector;
    }```
just in fixed update
teal viper
#

Okay. One thing you could do is get a quaternion from the new up direction, and rotate the moveDir with it before applying it to playerMovementVector

#

Quaternion representing rotation from old up to new one

#

Or down

neon ivy
#

do I just multiply the 2 quaternions then?

visual hedge
#

can I ask like really stupid question?
I watched like 6 guides about this one and still got no proper answer.
Say I have system that bans player for using certain "actions" here:

[System.Flags]
public enum BannedActions
{
    CAN_ACT = 1,
    CAN_MAGIC = 2,
    CAN_MELEE = 4,
    CAN_ITEM = 8,
    CAN_COUNTER = 16
}

very long time ago I can definitely remember I was using this system in setting up some private gameserver and to determine the enums from the list I would simply use the sum of the numbers:
Like 16+8+1 = 25.

Anyways... I haven't found a really elegant solution to determine which enum values are used.

Let's say I choose 1, 8 and 16 values. How shall the code determine which actions are banned? in elegant way...

neon ivy
#

how do you rotate a rotation xD

teal viper
teal viper
burnt vapor
#

Iterate flags and use this

#

& operator filters them out

#

Also, HasFlag is a thing on enums that consist of flags, which does the same thing

neon ivy
#

I have the local rotation which is quaternion.euler(0,angle,0);
and the rotation from gravity

visual hedge
#

is it a huge rabbit hole? 🙂

burnt vapor
#

No, I just explained it

teal viper
#

Not really if you know binary math.

visual hedge
sterile moon
#

Im working on getting a configurable joint made into a 3d slider joint set up for a part on the tow truck, but when I start the game it moves the highlighted part to a totally different position.

teal viper
#

That's usually the first thing you learn in computer science, so should be pretty simple to most people

visual hedge
#

I will try to find some documentation about this though, at least got good direction, tyhank you

teal viper
visual hedge
neon ivy
#

alligning the transform.up is easy, any other rotation I have no clue

teal viper
# neon ivy yes

Then you just need to multiply it by the rotation representing the change in gravity direction.

visual hedge
# burnt vapor What is the confusing part?
public class PlayerController : MonoBehaviour
{
    [System.Flags]
    public enum BannedActions
    {
        CAN_ACT = 1,      // 0001
        CAN_MAGIC = 2,    // 0010
        CAN_MELEE = 4,    // 0100
        CAN_ITEM = 8,     // 1000
        CAN_COUNTER = 16  // 10000
    }

    public BannedActions bannedActions;

    void Start()
    {
        // Assume the player can perform magic and use items
        bannedActions = BannedActions.CAN_MAGIC | BannedActions.CAN_ITEM;

        // Check if the player can perform magic
        if ((bannedActions & BannedActions.CAN_MAGIC) == BannedActions.CAN_MAGIC)
        {
            Debug.Log("Player can perform magic!");
        }

        // Check if the player can use items
        if ((bannedActions & BannedActions.CAN_ITEM) == BannedActions.CAN_ITEM)
        {
            Debug.Log("Player can use items!");
        }
    }
}

is this how it should be done? 🙂

burnt vapor
#

What this does is it checks 0101 against 0001 and it basically returns the equality of the two binary numbers

#

So 0001

#

And I check if 0001 == CAN_ACT, and CAN_ACT is also 0001

#

0001 is 1 in this case, hence the equality

#

This is how you can check it. Notice every jump doubles

visual hedge
burnt vapor
#

You also have binary OR which returns the opposite, which in my example would have been 0100

#

Does this make sense then?

visual hedge
#

yeah, makes sense

burnt vapor
#

One nice thing worth learning is also bitshifting

#

0001 << 1 is 0010

#

So 4 (0100) << 1 is 8 (1000)

#

Also works in reverse (>>)

#

Not as useful, it's mostly for writing efficient networking code because it allows you to fit data in small containers

visual hedge
#

I will try to put this a bit differently:
This is the "frontend"
Kinda easy, I just check the values I need.
Basically have none, all, and singles... now I am asking here cause I need to put some code on the backend so I can turn those flags into some logic.
And here's where I struggle.

#

but I guess this is how it should be on backend:

    void Start()
    {
        // Assume the player can perform magic and use items
        bannedActions = BannedActions.CAN_MAGIC | BannedActions.CAN_ITEM;

        // Check if the player can perform magic
        if ((bannedActions & BannedActions.CAN_MAGIC) == BannedActions.CAN_MAGIC)
        {
            Debug.Log("Player can perform magic!");
        }

        // Check if the player can use items
        if ((bannedActions & BannedActions.CAN_ITEM) == BannedActions.CAN_ITEM)
        {
            Debug.Log("Player can use items!");
        }
    }

and I guess that's what you suggested, right?

#

I just use same approach for each case, right?

burnt vapor
#

Pretty much

visual hedge
#

okay, so it's how it works. I just thought there might be a more elegant way

teal viper
#

That's bit masks for you. There's not any more elegant than that.

burnt vapor
#

You can also do this

if ((bannedActions & BannedActions.CAN_ITEM) != 0)
#

Perhaps more readable

teal viper
#

If you feel fancy, you could use a list of enums instead.

burnt vapor
#

But back to my initial point, HasFlag is a thing you know

teal viper
#

Unless you write a utility/extension method.

burnt vapor
#

if (bannedActions.HasFlag(BannedActions.CAN_ITEM))

visual hedge
timber tide
#

HasFlag is only one case though and if all bits are set right

visual hedge
teal viper
timber tide
#

wonder why there's not more utility for bit checking

burnt vapor
#

That would be up to .NET devs because everything useful in enums is internal

#

Just check HasFlag implementation

visual hedge
#

because at this point it looks pretty much like passing a list of enums... and other side has to kinda determine which one is present in there which I thought is silly and somehow clunky so I came here... just to hear that it's the only way

sterile moon
eternal needle
visual hedge
timber tide
#
public enum BannedActions
{
    CAN_ACT = 1,      // 0001
    CAN_MAGIC = 2,    // 0010
    CAN_MELEE = 4,    // 0100
    CAN_ITEM = 8,     // 1000
    CAN_COUNTER = 16  // 10000
    CAN_MELEE_AND_MAGIC = CAN_MELEE | CAN_MAGIC //would be the combine bits
}

can do stuff like that too

#

but probably better to just use flags at that point

burnt vapor
#

To avoid having to count your enums:

public enum BannedActions
{
    CAN_ACT = 1 << 0,
    CAN_MAGIC =  1 << 1,
    CAN_MELEE = 1 << 2,
    CAN_ITEM = 1 << 3,
    CAN_COUNTER = 1 << 4,
    CAN_MELEE_AND_MAGIC = CAN_MELEE | CAN_MAGIC,
    CAN_ALL = CAN_ACT | CAN_MAGIC | CAN_MELEE | CAN_ITEM | CAN_COUNTER,
}
sterile moon
visual hedge
#

anyways that's how I implement this, right?

    [SerializeField]
    protected BannedActions bannedActions;

    public virtual void Activate(UnitStateMachine target)
    {
        if ((bannedActions & BannedActions.CAN_MAGIC) == BannedActions.CAN_MAGIC) 
        {
            target.canUseMagic = false;
        }
        if ((bannedActions & BannedActions.CAN_ACT) == BannedActions.CAN_ACT)
        {
            target.canAct = false;
            target.canFlee = false;
        }
        if ((bannedActions & BannedActions.CAN_MELEE) == BannedActions.CAN_MELEE)
        {
            target.canUseMelee = false;
        }
        if ((bannedActions & BannedActions.CAN_ITEM) == BannedActions.CAN_ITEM)
        {
            //target.canUseItems = false;
        }
        if ((bannedActions & BannedActions.CAN_COUNTER) == BannedActions.CAN_COUNTER)
        {
            target.counterAttack = false;
        }
    }

and selecting the node "Everything" would mean that all those if's would 'fire', right?

#

yeah... gonna try that 🙂 thanks 🙂 time to get to testing part 😄

#

btw am I missing something maybe?
Sometimes inspector jumps right to the file folder I click on... and then it's some sad time going thru the folders to the folder I was working in before that... so if someone knows how or where to submit that suggestion: would be great to have that BACK button so it would get me to the previous folder.
And MAYBE I am missing something and such a thing actually exists?

timber tide
#

You can also make the enum type long for 64 entries over 32

stark marsh
#

im new to unity and have a question. how to i tag something multiple times? example. i have fruit. and want to tag them by their actual names, like apple oranage etc. but also want them to be tagged at fruit. how do i do this?

north kiln
burnt vapor
north kiln
#

Modern .NET has solved the problem for a while

burnt vapor
#

Oh I guess they updated that in newer .NET versions, I remember how the code was very different

#

Yeah

#

Ok don't use HasFlag

visual hedge
stark marsh
#

im not understanding how i would edit a png image, to have code x.x

eternal needle
sterile moon
timber tide
#
public enum BannedActions: long
{
  ...
  CAN_COUNTER = 1000000000000000000000000000000000000000000000000000000000000000,
}

;)

#

may more may not be the right amount

visual hedge
sterile moon
visual hedge
#

how about making a Fruit class : Monobehaviour and that would mean something is actually a fruit?
And naming gameObject.name by their names? 🙂

#

just a silly idea

stark marsh
#

i appriciate the ideas, cause, idk how to approach that thought, me being a baby dev, what comes to mind first is just a simple tag

sterile moon
#

You may also want to

public class FruitData : MonoBehaviour
{
  [SerializeField] //So you can view it in the inspector
  private String fruitName;

  public String getFruitName()
  {
    return fruitName;
  {
{

You can expand on this too, for further data if you ever need it, for example

public class FruitData : MonoBehaviour
{
  [SerializeField]
  private String fruitName;
  [SerializeField]
  private float restorativeHP;

  public String getFruitName()
  {
    return fruitName;
  {

  public float getRestorativeHP()
  {
    return restorativeHP;
  {
{
stark marsh
#

like im doing a snake game off a tutorial, and im now building it to where im expanding on it on my own, and i got fruit to spawn, but i wanna make it to where some of the fruit give speed buffs while others, (like a watermelon) will make them go slower

eternal needle
visual hedge
burnt vapor
visual hedge
#

I could also use list of bools? 🙂

burnt vapor
#

Yes

timber tide
#

but otherwise for small cases like this bools would be fine

burnt vapor
#

The whole point is having the data available already, so a struct/class/list/array all do this

visual hedge
#

I guess list of bools is what I ahve to go for. Especially nicely will be just looping thru the lsit at the end and setting the ones which are true to true

#

great, than kyou for the ideas

burnt vapor
#

In my opinion you should just use an enum because in terms of what your code does it's really no difference. An enum would even be more readable.

#

Do whatever you want, this really only matters with networking or when your code execute very (very!) often

eternal needle
sterile moon
burnt vapor
#

If you're going to use methods that grab a private field, just use a property with a getter

public string FruitName => this.fruitName;

No difference, just generally expected.

visual hedge
stark marsh
#

cool, thanks for the help @sterile moon @visual hedge and @burnt vapor , i did copy that last code snippet from you hailey and ill work on that when i get back from work today

burnt vapor
#

The benefit would be less allocation, and therefore I doubt this is something you should look into at this stage.

sterile moon
#

Your welcome to it, since you plan to have water melon give slow speed (which in snake might actually be a positive buff, more time to think, think about that), you can just use a negative float value to dictate a negative buff

stark marsh
#

the reason i was thinking a watermelon would actually slow it down, is because a watermelon is a lot larger, and weighs more than an orange, or apple

sterile moon
#

Understandable, I'm just thinking in terms of the mechanics of Snake, the big challenege is quick reaction times to get those narrow misses, and a slower movement speed would be a benefit way more than a hindrance, so you may want to make watermelons a good object, versus a bad one, and maybe use things like lolipops (sugar rush) to speed the snake up, thus making it more challenging because you have less time to think about your movements

stark marsh
#

private void HandleInput()
{
if (Input.GetKeyDown(KeyCode.W) && direction != Vector2.down)
{
direction = Vector2.up;
}
else if (Input.GetKeyDown(KeyCode.S) && direction != Vector2.up)
{
direction = Vector2.down;
}
else if (Input.GetKeyDown(KeyCode.A) && direction != Vector2.right)
{
direction = Vector2.left;
}
else if (Input.GetKeyDown(KeyCode.D) && direction != Vector2.left)
{
direction = Vector2.right;
}
}

#

thats my movement code. i also have a variable called public float updateSpeed = 0.15f;

#

the lower i go with update speed, the faster the snake goes

sterile moon
#

I dont know that I would run all those with else ifs as its not needed, could clean it up a bit

#

could even potentially run that as a switch case

stark marsh
#

so use switch instead of else if?

sterile moon
#

I would at least remove else if for just stacked ifs, less extra to read

#
        if (Input.GetKeyDown(KeyCode.W) && direction != Vector2.down)
        {
            direction = Vector2.up;
        }
        
        if (Input.GetKeyDown(KeyCode.S) && direction != Vector2.up)
        {
            direction = Vector2.down;
        }
        
        if (Input.GetKeyDown(KeyCode.A) && direction != Vector2.right)
        {
            direction = Vector2.left;
        }
        
        if (Input.GetKeyDown(KeyCode.D) && direction != Vector2.left)
        {
            direction = Vector2.right;
        }
#

I don't know if you can switch case over key press, but it would clean up WASD style games. You could also use input manager for this, but personally I still like hard coding my key interactions like your doing too

stark marsh
#

thanks again, lots to learn it seems XD

modest dust
#

Direction check everywhere is kinda wasteful, you could just do

Vector2 newDirection = ...;
if (newDirection != -direction) {
  direction = newDirection;
}```
#

To check if it's the opposite of the previous one or not

sterile moon
#

I tend to stay away from the else statement unless I absolutely need to stop code from continuing the code, but even then I can just C# return: out of an if to prevent the code from continue for that frame loop

eternal needle
# visual hedge In few hours I will get to really test each of the approaches. Gonna see which i...

Thinking of it more, I think a struct is better here than enum by a lot. Your unitstatemachine can store the struct itself instead of each bool. Right now you have this artificial link between enum and bool. Selections in the inspector for the enum are parsed, then bools in another class are assigned based on this. It just so happens that these bools have the same name as the enum values.
With a struct, you dont need this artificial link because you can just copy the values over. A struct is better than a class here because you dont need a specific instance, you just care about the data only. Same like for vector3, you dont care about it being a certain instance

sterile moon
stark marsh
#

as a new dev i have no idea how to read "vector 2 newDirection = ...;" @modest dust what is ... supposed to represent?

visual hedge
sterile moon
#

vector2 just takes 2 coordinate positions on the game screen

modest dust
stark marsh
#

i do get the vector2 part just not the rest

#

ah ok, i thought maybe it was a internal thing like int float bool etc

#

i only have a week maybe at C# - so i appriciate all the help

sterile moon
#

What type of variable is your direction

modest dust
# stark marsh private void HandleInput() { if (Input.GetKeyDown(KeyCode.W) && dire...

In your if/else, you seem to prioritize up/down movement, so it could just be:

Vector2 axisInput = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
Vector2 newDirection = axisInput.y switch {
    > 0 => Vector2.up,
    < 0 => Vector2.down,
    _ => axisInput.x switch {
        > 0 => Vector2.right,
        < 0 => Vector2.left,
        _ => direction
    }
};

if (newDirection != -direction) {
  direction = newDirection;
}

// Now the rest
sterile moon
#

Damn, throwing Lambdas at the new kid?

modest dust
#

Ah, right, we're in the beginner channel

sterile moon
#

lol

modest dust
#

Well, maybe he'll learn something new

sterile moon
#

Lambdas are fucking clean tho, I love how much they clean up code

stark marsh
#

vector2 is the variable type

sterile moon
#

im stuck on physics bullshit so I'm happy to find someone who needs help that I know how to do lol

stark marsh
#

ill copy it and put it my code for later

sterile moon
#

As a note, from someone who was once new to code, never just copy it and put it in

stark marsh
#

naw this is so i can look at it with more depth later

#

i dont know how active this channel is, and dont wanna be scrolling for 15 minute trying to find it in 9 hours

sterile moon
stark marsh
#

question, what is lambdas?

visual hedge
sterile moon
#

A lamda is essntially an anonymous function

modest dust
sterile moon
#
Enumerable.Range(2, 100).ToList().ForEach(n => Console.WriteLine(n))

This is a good basic example of a lambda right here

stark marsh
#

im not gonna "use" it per say, i copied it along with your name so i can look at it later, and know who posted it

visual hedge
#

I am working on a turn-based game. Very advanced one (it feels like this to me). And there are vaarious things I need to implement and I haven't figured out how do I enable passive skills that have a certain moments where they kick in.

sterile moon
#

My entire game is going to need physics to a high level because its designed to be an intensive simulator involving hydraulic equipment

stark marsh
#

sounds intresting

sterile moon
#

I hope it will be, but Physics makes me 🍺

modest dust
sterile moon
visual hedge
#

The game I want to make is way more advanced than my skills. And My skill level increases based on how advanced mechanics in my game are getting :)) It's like digging into sand and then hitting harder layer. One has to get oit, bring more advanced equipment to dig further. Rinse and repeat

sterile moon
#

lol, kidding, kindof, I run my own business, so, I essentially do that

visual hedge
sterile moon
modest dust
sterile moon
#

id rather die slowly, with pain and anguish through Physics

visual hedge
sterile moon
#

ive thought about taking the project to unreal, but idk

#

unity has better support groups imo

#

By the time Im finished with this I think ill need a few different support groups too, tired dev support group, hates the world support group, why the fuck do I do this to myself support group

#

im not intested in making things unless it challenges what I already know, and in doing that, I remember why I hate that about myself lol

modest dust
sterile moon
#

Hey caesar, are you good at Physics?

modest dust
#

Not one bit, thinking of physics gives me flashbacks of my high school teacher


sterile moon
#

Good, your now my employee, here's some problems to fix

#

ahhh i cant post the gif

modest dust
#

lol

sterile moon
#

bastards, ruined my joke

modest dust
#

You're in the no fun zone

sterile moon
#

check your dms. That meme is getting delivered dammit

modest dust
#

Meme received and approved by the fun council

sterile moon
#

chkkk Mission success, I repeat mission success, joke has landed

modest dust
#

Well, either way we're getting out of track here, I need to go back to my actual job before my boss notices that I'm suspiciously dormant for a while now

sterile moon
#

lol

queen adder
#

hey im still confused on how i would make the cube move to where i want it to

ivory bobcat
visual hedge
# eternal needle Thinking of it more, I think a struct is better here than enum by a lot. Your un...
public class SealEffect : StatusEffect
{
    [SerializeField]
    protected bool BanMelee = false;
    [SerializeField]
    protected bool BanMagic = false;
    [SerializeField]
    protected bool BanItemUse = false;
    [SerializeField]
    protected bool BanFlee = false;
    [SerializeField]
    protected bool BanCounterattack = false;
    [SerializeField]
    protected bool BanEverything = false;

    public override void Activate(UnitStateMachine target)
    {
        AllowedActions allowedActions = new();
        allowedActions.canUseMelee = !BanMelee;
        allowedActions.canUseMagic = !BanMagic;
        allowedActions.canAct = !BanEverything;
        allowedActions.canFlee = !BanFlee;
        allowedActions.canCounterattack = !BanCounterattack;
        allowedActions.canUseItems = !BanItemUse;

        target.AllowedActions = allowedActions;
    }
}

decided to go with class for now

#

thank you, that was a great suggestion

#

gonna set up some things and will test that today 🙂

warped ginkgo
#

Library\PackageCache\com.unity.test-framework@1.1.33\UnityEditor.TestRunner\UnityTestProtocol\UnityTestProtocolStarter.cs(18,36): error CS0246: The type or namespace name 'UnityTestProtocolListener' could not be found (are you missing a using directive or an assembly reference?)
What is this.

hexed terrace
#

a compile error!

wintry quarry
hexed terrace
#

Which you wouldn't expect from a Unity package

tall delta
finite sorrel
#

Hello, I’m playing around with inputs and have a question that might seem very simple..
Does the code in green achieve the same as cyan, but without the need for extra function?

wintry quarry
#

Best practice here would be unsubscribing in OnDisable():

void OnDisable() {
  blahblahblah.performed -= ChangeTarget;
}```
finite sorrel
#

So it’s not “free” and I’m better off using proper function

wintry quarry
#

Yeah I would say best practice is using a proper function

finite sorrel
#

Thank you

honest vault
#

i have got a problem with my code whenever i shoot the enemy he hust starts circling around and doesnt take any damage or die.

rocky canyon
#

well first off he's wobbling around because u apply forces to it w/ the bullet impact..

#

if u dont want that to happen on the rigidbody u need to uncollapse the Constraints section and lock it so it doesn't

#

shouldnt need to rotate on the x and z axis

honest vault
#

Yeah but whenever i shoot it i dont want it to go away i just want it to die after it's health is 0

#

whenever i shoot it just doesnt take any damage

sterile loom
#

any help? Getting this error message "Assets\Scripts\PlayerController.cs(13,26): error CS0266: Cannot implicitly convert type 'UnityEngine.KeyCode' to 'float'. An explicit conversion exists (are you missing a cast?)"

sterile loom
#

honestly no idea, new to unity. i think it's saying that I can't make the binds a float property? but I just wanna be able to have public display bind that can be changed on the inspector

languid spire
#

what it is saying is that you are trying to change a KeyCode into a float but C# cannot do that automatically for you. But you can ask it specifically to do so with a cast

wintry quarry
#

Start by looking at line 13 of PlayerController.cs

#

Always look at the mentioned line of code when you have an error (and the surounding context)

#

to make a public KeyCode field it would simply be:

public KeyCode myKeyCode;```
sullen rock
#

Hello! can somebody please help me optimize this https://gdl.space/ipidoyofus.cs

the script is basically supposed to recognize if a shape drawn (and displayed by a line renderer) is a T, U or something entirely different. T works, U isnt implemented yet. Before doing the U I would like to see if I can make the recognition any faster, since this feels a little slow

Edit: I have just realized that the last check makes no sense and I need to rewrite that

sterile loom
wintry quarry
#

There's no float involved

#

If you share your code maybe we could be on the same page here

sterile loom
#

1 sec

wintry quarry
#

right now all you shared was an error message

sterile loom
#

https://pastebin.com/iL6PTwDP

Basically what I'm trying to do is this, I need to have an animation for all 8 directions Idle1 -> 8, and I'd like to set a sprite anim for each of those directions when the player presses a direction. I'd like to have those keys be rebindable in the unity inspector. The code is a mess as I used youtube tutorials and chatgpt to string it together

wintry quarry
#

You can just write Input.GetKey(KeyLeft)

#

other than that - the code as you shared would not give the error you shared

#

did you change something since then?

sterile loom
#

no that's about it other than putting in what you guys said to put at the start

wintry quarry
#

anyway it should generally "work" this way

wintry quarry
sterile loom
#

but I am getting a new error saying "Direction does not exist"

#

but the character does move

#

just doesnt cycle through the animations

wintry quarry
#

there's a bunch of stuff you'd need to do in the animator state machine to make the animator work with this

sterile loom
#

sec lemme try and figure it out

warped ginkgo
#

Bruh, what the hell is this: JSON parse error: Invalid value. (Packages/com.unity.ads/Tests/Runtime/Advertisement/UnityEngine.Advertisements.Tests.asmdef)
Im getting back to unity after 6 months of break, and they are throwing me the most out of place errors ever lol, its really frustrating.

#

i probably need this package though, since that game is using advertisements (legacy)

#

but idk where this thing comes from

#

also the file they are referencing is a very weird file, im not sure what its called... maybe hex

wintry quarry
#

it's an assembly definition

#

when are you seeing this?

#

Have you tried updating your packages?

warped ginkgo
warped ginkgo
wintry quarry
warped ginkgo
wintry quarry
#

To update a package you select it from the list (from the "In Project" tab) and it will have an Update button (and a little arrow) if there's an update available

warped ginkgo
#

And what if theres no such button there

wintry quarry
#

then there's no update for that particular package, or the package version is locked due to being part of a collection

twilit pilot
# sullen rock Hello! can somebody please help me optimize this https://gdl.space/ipidoyofus.cs...

fwiw this is a known hard problem in the general case, especially if your plan is to add recognition support for more characters down the line - code like this will inevitably approve drawings that don't really look like T's or U's at all. I'd suggest looking up some tried and tested methods of general recognition if you need to go that route (Tesseract OCR maybe, or some other unity friendly CNN)

As for optimisation I imagine you'll only analyse drawings infrequently like this, and the number of points for each one wont be too high, so iterating through them several times really shouldn't be a big deal. Computers are fast.

pulsar creek
#

Unsure if this should go to code beginner or code general, but when using GetComponentsInChildren the parent object itself counts as a component.

#

Is there any way to avoid that?

wintry quarry
pulsar creek
#

How would I do that without LINQ?

wintry quarry
#

which one

pulsar creek
#

The first one

wintry quarry
#

well you'd use a for loop

#

and an if statement

pulsar creek
#

Seems a bit inefficient, but I'll try that

#

Would it work if I used .Skip(1)?

wintry quarry
#
foreach (Example x in GetComponentsInChildren<Example>()) {
  if (x == myOwnInstance) continue;
}```
wintry quarry
pulsar creek
#

ah, right

sterile loom
# wintry quarry no you can't depend on any ordering

Hey man, could you take a look at this video? https://www.youtube.com/watch?v=NQN3rYGqqP8 so he's using a public to input the sprites but is it possible to tell the code to reference the animator state instead of it being a public drop down?

Heya Pals!

This is a followup video to the previous pixel art class series on isometric and top-down animations that will let you bring your pixel art creation to life in Unity in just 30 mins!

Enjoy :)

Chapters:
0:00 - Intro
0:47 - Importing Your Sprites into an Empty Unity Project
5:30 - Setting Up the Character Object
10:00 - Setting Up th...

▶ Play video
wintry quarry
sterile loom
#

so he's using "public List<Sprite> nSprites" (for north facing sprites) and then dropping the sprites on the inspector. basically referencing that telling the game to use those sprites when player faces north. is it possible to instead of using that, can I tell the game to look for the name of the animation through the animator instead? Like say I have an animation that is is called "Idle1" for north facing

wintry quarry
sterile loom
#

its just a placeholder for now as I drop all the sprites in

sterile loom
polar acorn
#

That's just a variable

#

If you don't know how variables work you should really be doing !learn to pick up the basics

eternal falconBOT
#

:teacher: Unity Learn ↗

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

polar acorn
#

Also you are literally already doing that in the code you shared earlier

polar finch
#

Any idea what's going on here? Just started to happen and I have no idea why.

polar acorn
#

What file is throwing the error?

polar finch
#

it's gone now okiedokie

#

power of questioning

desert flume
#

!code

eternal falconBOT
desert flume
#

1s

desert flume
#

W moves you to the right/down direction

#

instead of up

wintry quarry
desert flume
#

ill just use the properties window

polar acorn
#

Logs tell you what it is at the moment the log is executed, not what it is when you look at it later

desert flume
#

oh

wintry quarry
ivory bobcat
ivory bobcat
#

Was input properly acquired?

#

Is there a consistent pattern?

desert flume
#

now it works!

desert flume
#

Changed nothing afaik 💀

spring storm
#

Hey is there someone I can talk to for some help? I spend 5 hrs yesterday on a tutorial just to get this error code I spent hours trying to figure out and havent gotten anywhere

wintry quarry
spring storm
#

okay sorry had to figure out how to share the code.

polar acorn
#

!code

eternal falconBOT
spring storm
polar acorn
#

doorObject is null

ivory bobcat
spring storm
#

how would I fix that, cause I know what line but I can't figure out how to fix it. I followed a tutorial and triple checked everything so

ivory bobcat
#

Make it not null either through the inspector or code

spring storm
#

i guess it didnt set doorObject anywhere

ivory bobcat
#

A minor concern: Capitalization is important - name case sensitive

#

Where start isn't referring to Unity's Start

ivory bobcat
spring storm
#

KeyLockController is a script

#

thats where im confused

ivory bobcat
#

Not really a code question (looks like a build question). Try #💻┃unity-talk (delete the message/post here to not cross post)

fleet breach
#

okok thank you

ivory bobcat
spring storm
#

I genuinely dont know what you mean by it. the class im taking is a very poorly done online class so they dont really explain anything

ivory bobcat
spring storm
#

was it really just the lowercase s?

ivory bobcat
#

I'm assuming the problem has been resolved

spring storm
#

oh ym god it was

#

thank you

ivory bobcat
#

Yes, the Unity callback method is Start and not start

spring storm
#

okay ill be sure to keep that in mind next time, thank you so much again

honest vault
ivory bobcat
#

Where the script in question would have the OnCollisionEnter callback method

honest vault
ivory bobcat
#

Where it'd destroy the target

ivory bobcat
#

So it isn't on the bullet though. Consider sharing code.

#

You've got to provide it if you need help with it not working properly

honest vault
#

public class Health : MonoBehaviour
{
    public int maxHealth = 100;
    private int currentHealth;

    void Start()
    {
        currentHealth = maxHealth;
    }

    public void TakeDamage(int damage)
    {
        currentHealth -= damage;

        if (currentHealth <= 0)
        {
            Die();
        }
    }

  
    public void Heal(int amount)
    {
        currentHealth = Mathf.Min(currentHealth + amount, maxHealth);
    }

   
    void Die()
    {
     
        Debug.Log(gameObject.name + " has died.");
        Destroy(gameObject);
    }


    public int GetCurrentHealth()
    {
        return currentHealth;
    }

  
    public int GetMaxHealth()
    {
        return maxHealth;
    }
}
#

thats the health code i have it on both the enemy and the player

honest vault
ivory bobcat
#

So where is your script for the physics interaction and where you call the take damage method on the target?

honest vault
ivory bobcat
#

So when the gun touches the enemy, they'll lose life.

honest vault
queen adder
#

I suggest ya using some kind of code sharing website for not to block other's questions

queen adder
#

Uh !code one of those links would be okey

eternal falconBOT
ivory bobcat
honest vault
#

heres the gun script

honest vault
ivory bobcat
#

The On...Enter method needs to be on the bullet

honest vault
#

i have also created public variables soo i can attach the bullet

wintry quarry
cosmic dagger
# honest vault

the gun checks if a collider that enters its trigger has a Health component, then attempts to damage it. a bullet is what does the damage, not a gun. the bullet should check if it collides with a game object that has a Health component . . .

honest vault
honest vault
cosmic dagger
honest vault
#

i put the gun scipt on the bullet prefab and removed it off the gun model

cosmic dagger
honest vault
#

im sorry ifs its a silly question but if i have only been learning for like 2days.

honest vault
#

not the gun

ivory bobcat
cosmic dagger
ivory bobcat
#

The gun needs the spawn bullet logic

#

If you just put the script on the bullet as well, you'll get the bullet firing bullets

honest vault
ivory bobcat
#

But it'll destroy the enemy like the gun does so, at the very least UnityChanThink

honest vault
ivory bobcat
honest vault
#

will do

wintry quarry
#

A bullet is not a gun

#

Gun should have gun script
Bullet should have bullet script

#

Make things simple and logical

ivory bobcat
#

Note that OnTriggerEnter only occurs if the interaction should be a trigger interaction. Use OnCollisionEnter if it isn't a trigger interaction.

honest vault
#

got it working

honest vault
#

it was easier than i thought it was

modern smelt
#

Hello everyone. How would you code a jump as Mario in 3d ?
Using forces ?

ivory bobcat
modern smelt
#

With using unity input manager i Can détect when player triger thé jump and cancel it,but how Can i apply the stop jumping and instant fall

#

Classic Mario jump that go higher depend of the time that the Burton is pressed

ivory bobcat
#

You'd use rigid body physics if you want your system tied to the rigid body physics system.

#

Character controller or Transform/Physics-casting would be your other alternatives

keen bramble
#

I learnt roblox coding during lockdown for 2 years, and I have grown up and roblox is out my interest however coding still is, I learnt coding with the Roblox LUA Documentation however I cant find a documentation for unity step by step from start to finish

eternal falconBOT
#

:teacher: Unity Learn ↗

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

ivory bobcat
keen bramble
honest vault
# keen bramble Ok, but as a beginner should I start with this

Xsolla: https://xsolla.pro/Blackthornprod

Olobollo on Steam: https://store.steampowered.com/app/1592650/Olobollo/

0:00 - Intro
0:50 - Xsolla Promo
1:24 - Variables
4:17 - GetComponent()
6:08 - Instantiate()
7:52 - Destroy()
9:27 - Loops
13:35 - If/else
16:04 - Input.GetAxisRaw()
18:59 - Vector2.M...

▶ Play video
keen bramble
#

Ill give it a watch

ivory bobcat
keen bramble
#

ok sorry

summer stump
modern smelt
keen bramble
keen bramble
#

Yeah I know

summer stump
#

So if you want to use unity, you use c#. Not sure what you are saying then

#

It uses pure c#

keen bramble
#

What I mean is like, in python u can script in just lines as in it only has an output or u can make 2d/3d which is somewhat different

#

Its fine I get u

summer stump
#

I recommended those courses for the benefit you would gain in game development

keen bramble
#

Ok

ivory bobcat
modern smelt
#

yeah to start , cancel the jump could be a first step

ivory bobcat
#

For example, if the value is greater than zero.. divide it by five or something.

red scarab
#

why does this code not run in FixedUpdate? it works fine within Update, but since its physics I thought I should put it in fixed

#

to be clear the debug does print

modern smelt
wintry quarry
#

what makes you think it's not running?

red scarab
#

nothing happens

#

meanwhile in update, it does

wintry quarry
wintry quarry
#

moveSpeed isn't a great name for what that is either

#

more like - forceAmount or thrustAmount

red scarab
#

why does being in update vs fixedupdate change the required force? also, that worked, thanks

wintry quarry
#

so you needed less force

#

Also doing it in FixedUpdate guarantees that your force is properly expressed in Newtons and that it will be consistent regardless of framerate