#💻┃code-beginner

1 messages · Page 634 of 1

west sonnet
#
transform.rotation.y = object.transform.rotation.y
#

Would this work?

#

If the script was on the player

verbal dome
#

Well, you are supposed to replace object with an actual reference to the other object

#

Or just reference its transform directly

brazen pagoda
#

object is probably not an allowed variable name here

fast relic
verbal dome
west sonnet
limber flower
#

ok im getting a lot of different answers at once here

verbal dome
#

@limber flower Replace object.transform with a transform reference of the other object and use this

limber flower
#
{
    public Transform orientation;
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        Vector3 euler = transform.eulerAngles.y;
        euler.y = orientation.transform.eulerAngles.y;
        transform.eulerAngles.y = euler;
    }
}```
is this what i need to do?
verbal dome
#

Looks alright

#

orientation.eulerAngles is enough, no need for .transform.

#

It's already the transform

brazen pagoda
#

^ this. Otherwise looks good to me as well

fast relic
limber flower
#

orientation.eulerAngles.y has red squiggles under it

fast relic
#

you don't need the y

verbal dome
#

Ah yea

brazen pagoda
#

Oh good catch didn't notice that LuL

limber flower
#

ah ok

#

thank you everyone im going to test it now

verbal dome
#

Oh my bad it was in my example 😆

limber flower
#

that did not work

verbal dome
#

Did you aassign orientation?

limber flower
#

i did set the orientation object

verbal dome
#

If this doesn't work then likely something else is modifying its rotation

brazen pagoda
#

Did you put the script on the object you want to be rotated?

verbal dome
#

Could be a script, could be an animator

fast relic
#

is it just doing nothing or doing something that you didn't expect it to

limber flower
#

the model is always facing one direction, but the actual player object which has the movement script still faces the camera direction

fast relic
#

make sure that that code runs at the end of the frame, after the player's rotation gets set

limber flower
#

idk what that means

fast relic
#

if it runs before the player's rotation gets set it's gonna do nothing because it's overwritten right after

#

put that bit of code at the end of the script that's setting the rotation

verbal dome
limber flower
#

wait could it be that the armature's rotation is overwriting the rotation im trying to put on the playermodel?

verbal dome
#

Yes, I did mention that animator is possibly changing its rotation

limber flower
#

i dont have any animation on it

verbal dome
#

You have other code that rotates the player too, right? Show that

limber flower
verbal dome
limber flower
#
{
    public float sensX;
    public float sensY;

    public Transform orientation;

    float xRotation;
    float yRotation;
    private void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible = false;
    }
    private void Update()
    {
        float mouseX = Input.GetAxisRaw("Mouse X") * Time.deltaTime * sensX;
        float mouseY = Input.GetAxisRaw("Mouse Y") * Time.deltaTime * sensY;

        yRotation += mouseX;

        xRotation -= mouseY;
        xRotation = Mathf.Clamp(xRotation, -90f, 90f);

        transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
        orientation.rotation = Quaternion.Euler(0, yRotation, 0);

    }

}```
limber flower
verbal dome
#

If you have two scripts with an Update method, they run in a random order so don't rely on that. In one game session the other update might run first and vice versa
LateUpdate is guaranteed to run after all Updates though.

limber flower
#

actually i dont think the player is actually being rotated technically

#

its just applying a force in a different direction based on the orientation object which is controlled by the camera script

verbal dome
#

Very common mistake

#

You get smoother/more consistent mouse input if you fix that

#

But not related to your question

sour fulcrum
limber flower
verbal dome
sour fulcrum
#

per instance is more or less random

#

per type is controllable if defined and while it can shift between dev builds due to some things, it won't be random per session

limber flower
#

anyways this is what controls the movement relative to camera orientation
moveDirection = orientation.forward * verticalInput + orientation.right * horizontalInput;

verbal dome
limber flower
#

i cant tell if that is actually rotating the object or not

verbal dome
sour fulcrum
#

just being a nitpicky nerd dw

verbal dome
#

All good :p

limber flower
#

putting the script on the armature also didnt affect it

verbal dome
#

What objects are children of what?

limber flower
brazen pagoda
limber flower
#

heavyplayerWIP is the character model

brazen pagoda
#

Then there's either an issue with the script itself or the orientation object doesn't do what we think it does

verbal dome
#

Orientation is a child of the player so the player following its rotation would cause a feedback loop anyway 🤔

#

Because the child rotates with the parent

fast relic
limber flower
#

would it help if i found the tutorial i got the movement code from?

#

and then told you how ive changed it

limber flower
#

is that why its called yaw?

naive pawn
#

not because of "y", no

limber flower
#

oh ok

naive pawn
#

there's yaw, pitch, and roll

limber flower
#

yeah i only knew that because ps3 minecraft had pitch and yaw sensitivity instead of x and y

#

this is where the movement code is from

naive pawn
#

x/y sensitivity would refer to movement of a mouse, whereas pitch and yaw would refer to the actual rotation
assuming y-up, x-right, z-forward:

  • pitch is rotation about the x axis
  • yaw is rotation about the y axis
  • roll is rotation about the z axis
brazen pagoda
#

Usually aerodynamical terms referring to rotations along certain axes of a long object. Roll being rotation around longitudal axis etc.
It's not normally affiliated with world-space XYZ.

verbal dome
#

Really wish that "Dave" would pin a comment about the mouse deltatime issue on that video

#

Mate has 1.2mil views, that should bring some responsibility

naive pawn
limber flower
naive pawn
#

roll is around the "forwards" direction of the object

brazen pagoda
# naive pawn it isn't world-space xyz to begin with, in this context it's around the local ax...

Yeah I get that, but it's still not longitudinal, transverse and normal axes 😅 There's some language inaccuries by applying a physical inertia/velocity based naming scheme to an aiming context where Horizontal/Vertical is likely more accurate terms. Roll is the least effort rotation since it's longitudal axis is the axis with least angular intertia on airplaines, rockets, submarines etc. On a standing character, that would be rotation around the y-axis if accurate, thus ambiguity when putting it on the z axis that a plane typically has.

But it's all semantics so not super important. Just thought I'd mention.

naive pawn
limber flower
#

setting the orientation object to the actual player camera also doesnt work

naive pawn
#

(that's the interpretation i use, here i'm trying to challenge that to see if that holds up)

limber flower
naive pawn
#

not what we're talking about

#

"longitudinal axis" just means the long axis of some object
the longitude value used in geographical coordinates is also based on that, it's the long way around the earth

brazen pagoda
# naive pawn 🤔 but generally the longitudinal axis is the direction of travel, isn't it? sin...

A plane can be stalling or slipping/skidding, terms describing situations where direction of travel differs from the orientation of a plen. The three axes remains fixed to the plane in each of those cases afaik.

There's some science I'm thinking about back in the days about rotational stability where in mechanical physics we would describe the three axes of a wooden plank based on it's inertia. There's also a very interesting physics video by Veritasium about "The Bizarre Behavior of Rotating Bodies" describing how two of the three princple axes are stable axes when rotated, but instability around the other. Aka the "intermediate axis theorem". However I must admit "intermediate axis" isn't one of the 3 I mentioned so I'm now a little unsure what's completely correct here tbh LuL But a lot of axis talk starts at inertia. And a "long" axis tends to be the axis with leas angular inertia, i.e. the one that requires the least force to rotate.

#

TL;DR: I'm a bit unsure right now LuL

naive pawn
#

i mean the intended primary direction of travel lmao
this would get even more complicated with like, helicopters 😂

brazen pagoda
#

Haha yeah good mention

naive pawn
#

ive seen the veritasium video before, yeah. the intermediate axis would be either the vertical or transverse axis, wouldn't it? just depending on the craft

#

wait no

fast relic
#

is it common for this chat to start talking about like helicopters or something or is this just a one off lmao

naive pawn
#

the intermediate axis should always be the transverse axis, shouldn't it 🤔

naive pawn
limber flower
naive pawn
naive pawn
limber flower
#

I can't figure out how to set my player model to rotate with the camera (on the y axis)

brazen pagoda
verbal dome
limber flower
naive pawn
limber flower
naive pawn
#

!code

eternal falconBOT
brazen pagoda
#

ive seen the veritasium video before,

naive pawn
#

see the section on large code blocks

limber flower
#

oh ok

#

the movement script

naive pawn
limber flower
#

i can see the model below the camera in play (another problem i need to fix)

verbal dome
#

rb.freezeRotation = true;

#

👀

limber flower
#

oh my

#

why is that even there

verbal dome
#

We should just always ask for the full script

#

Oh this is a completely different script

limber flower
#

if i turn that off, will it rotate in every direction?

verbal dome
#

You can freeze the X and Z axes only, if you want

limber flower
verbal dome
#

No need to do it via code tho, just set it in the inspecotr (Rigidbody > Constraints tab)

limber flower
#

that makes even less sense actually

#

why would they tell me to add that if you can just do it in inspection

#

well that still didnt fix it

naive pawn
#

tutorials aren't gospel

naive pawn
naive pawn
#

also, if you have an rb, that's gonna try to manage the rotation, so you'll have to tell the rb to rotate

limber flower
#

oh right

#

but it can definitely rotate now

#

the model fell over when i tried to move because i didnt lock x and z rotation

naive pawn
#

ok, then lock those axes lmao

limber flower
#

yeah still cant get it to work

#

the rotate script just doesnt do anything as far as i can tell

raw smelt
#

Hi why if i do that

                SystemAPI.SetComponent(BulletEntity, LocalTransform.FromPosition(localTransform.ValueRO.Position));
                SystemAPI.SetComponent(BulletEntity, LocalTransform.FromScale(bullet_size));

The size is corret but if i did that

SystemAPI.SetComponent(BulletEntity, LocalTransform.FromScale(bullet_size));
                
SystemAPI.SetComponent(BulletEntity, LocalTransform.FromPosition(localTransform.ValueRO.Position));
                

is not

limber flower
#

LocalTransform.FromPosition(localTransform.ValueRO.Position));

#

this just affects position

limber flower
#

LocalTransform.FromScale(bullet_size));

#

but this affects size

#

as far as i can tell

raw smelt
#

I know but why if i make
A ,B
i have dif effect than
B, A

limber flower
#

oh ok

#

no idea

verbal dome
#

I assume that's because the scale affects the local position

#

But yeah it's a dots question

limber flower
#

are there not any voice channels in this server where i could share my scree?

#

that would make this a lot easier

fast relic
#

just turn off your mic

limber flower
#

pardon?

naive pawn
limber flower
#

seems more effective than just guessing what might be helpful

raw smelt
naive pawn
#

it would not

raw smelt
#

Why not ?

naive pawn
#

everything you share is ephemeral

raw smelt
#

pair programming is greate

naive pawn
#

anyone trying to help won't be able to go back to see what you just showed

#

and anyone trying to help later, just won't be able to

limber flower
#

thats a good point

brazen pagoda
#

VSCode Live Share combined with screen shareChexxor
(Might be risky) - Allowing others to run code - don't do it if you don't know what you're doing

polar acorn
#

Because people just showing up partway who might have the answer won't be able to just scroll up and see what the question was

naive pawn
limber flower
#

i hadnt even considered that

raw smelt
naive pawn
#

that's also why text/images are better than video/audio explaning the issue (video demonstrating the issue is fine, describing the issue isn't great)

brazen pagoda
#

I think other than sharing individual scripts here the least effort on the end of those providing assistance is to provide a github link to a branch that has the issue in question, along with some pointers where to look.

naive pawn
polar acorn
limber flower
#

regardless, i still just need someone more experienced with unity to be able to see everything i can see because i have no idea whats important to share or what causes what reaction

naive pawn
naive pawn
#

you know your project better than we do

polar acorn
naive pawn
#

what are the relevant components you have? rigidbodies, colliders, etc
what's the hierarchy? etc

limber flower
polar acorn
limber flower
#

basically i need to add a script that turns the playermodel with the camera

#

and i dont know how to do that

polar acorn
limber flower
#

the playermodel is constantly facing the direction it started at, and the camera moves indipendantly from it

brazen pagoda
limber flower
#

i think i can do that

polar acorn
brazen pagoda
#

Is the camera following the player as well? If the player moves right, does the camera move right?

limber flower
#

it seems the code i currently have, rotates the camera, and moves based on that, without affecting what the camera is attatched to

polar acorn
#

Yeah, seems to me like you should have your controls rotating the player and then have code that moves the camera to be behind the player (or just let Cinemachine handle that)

limber flower
#

so take the y axis controls from this script

 {
     float mouseX = Input.GetAxisRaw("Mouse X") * Time.deltaTime * sensX;
     float mouseY = Input.GetAxisRaw("Mouse Y") * Time.deltaTime * sensY;

     yRotation += mouseX;

     xRotation -= mouseY;
     xRotation = Mathf.Clamp(xRotation, -90f, 90f);

     transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
     orientation.rotation = Quaternion.Euler(0, yRotation, 0);

 }```
 and put it in the playermove script?
brazen pagoda
#

There are many ways to approach this.

  • Cinemachine is the most elegant and powerful tool here.
  • Parenting: Make the camera a child of the player object, and give it some offset. This way it will rotate if the player rotates.
  • Constraints. You can add various constraints to provide offset and aiming directions without parenting.
  • Code everything
limber flower
#

im unsure how to proceed with this information, it could be very easy to do it wrong and undo a lot of progress

polar acorn
#

Sometimes the best way to learn is to irrevocably break things

limber flower
brazen pagoda
naive pawn
#

i'd recommend against the private support, as it negates the benefits of a community server existing, but if you want to do that personally, i can't stop you 🤷

naive pawn
limber flower
naive pawn
#

ah. mouseX is up-down, isn't it lmao

limber flower
#

yeah

naive pawn
#

wait no

#

mouseX is left-right and you use that to move around the y axis

#

ok

#

yRotation is the main one; you would remove that and stuff related to it
so that would be mouseX

limber flower
#

like this?

 {
     float mouseY = Input.GetAxisRaw("Mouse Y") * Time.deltaTime * sensY;
     xRotation -= mouseY;
     xRotation = Mathf.Clamp(xRotation, -90f, 90f);

     transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
     orientation.rotation = Quaternion.Euler(0, yRotation, 0);

 }```
naive pawn
#

you're still using yRotation

#

your ide should tell you about that

#

is your ide configured?

limber flower
#

ide?

#

oh ok i see what you are saying

#

yeah i got rid of the yRotations at the bottom

naive pawn
#

!ide

eternal falconBOT
limber flower
limber flower
#

but when i put it in visual studio it told me

naive pawn
#

you should just do it in your ide

limber flower
#

well now the model does turn with the mouse

#

but the camera doesnt turn left and right

naive pawn
#

ok, so now you just have to get the camera to follow the player

limber flower
#

couldnt i technically just have the same y axis script on the player and the camera?

#

or would that cause issues

brazen pagoda
#

Parenting it in the hierarcy is likely easiest if that works for you

naive pawn
#

you could, but you should just follow the player

#

either through hierarchy like chexxor mentions above, or through some follow script (of your own, or via cinemachine)

limber flower
#

i was told attatching a camera to a rigidbody would be problematic

brazen pagoda
#

I have never seen problems with that so far

raw smelt
#

Can I make the game always run at 60 fps, and if it can't generate 60 fps, make everything slow down but keep consistency, for example, the shooting frequency, intact ?

#

and still use Unity Physics etc

brazen pagoda
#

Might be some special case PepoThink Like large number positions due to floating point precision perhaps. Don't know what else should cause issues. I mean if you're doing a physics sim you could see some janky behaviour. But if you're doing a character controller and not a bouncing ball you should be fine

limber flower
#

i put the camera holder under the player and it still doesnt rotate on the y axis

brazen pagoda
limber flower
#

yes

brazen pagoda
#

Then you have a rotation freeze or rotation overwrite from code somewhere

naive pawn
raw smelt
#

or it will not be in exacly 1/10 s interval

naive pawn
#

if you have a framerate that isn't divisible by 10 then you won't get exactly 1/10 anyways

raw smelt
#

actually why not ?

#

i can save the "extra time"

#

for example

naive pawn
#

if you have less than 10 fps, you could just make it shoot every frame

raw smelt
#

but i can miss every 2 frame

brazen pagoda
raw smelt
#

if even frema will be faster that old frame

#

then i will get like
1 - shoot
2 -not shot (becouse is less that 1/10 s )
3 -shoot
4 - not shoot
...

raw smelt
#

so i will get 5 shoots in 1 s ineasted of 10 even if i have 10 fps

naive pawn
# raw smelt actually why not ?

if you have 60 fps, and shoot 10 times per second, you get 1 shot every 6 frames (60/10). 6 frames / 60 fps = 0.1s
if you have 59 fps, and shoot 10 times per second, you still get 1 shot every 6 frames, because you can't shoot between frames
so you get 6 frames/59 fps = 0.101... s

brazen pagoda
# limber flower i see

So assuming that the code you already have does the same thing to the "Player" rotation as I am doing through the inspector, you would have the same camera motion unless something else is interfering.

naive pawn
#

so just don't worry about getting exactly 0.1s per shot

#

just make sure it's >= 0.1s per shot, and everything will work out fine

raw smelt
limber flower
raw smelt
naive pawn
#

is your game gonna be multiplayer?

raw smelt
#

if i want make kind of TD defens
Then its importnat

#

becouse you will get for example +20 % dmg upgrade
and you lose it becouse of unlucky frame rate XD

naive pawn
#

no, that's not what will happen

naive pawn
brazen pagoda
naive pawn
#

it won't matter, but why it won't matter will be different

naive pawn
raw smelt
# naive pawn answer this

not It will not . Actually now I mainly learny how to use Unity etc
So I try make Protype of protype

limber flower
naive pawn
#

you shoot slower, but enemies also move slower

#

if you have a frame rate less than the fire rate, you can just make it fire multiple times per frame to make up for the lost frames where it shoudlve shot

raw smelt
naive pawn
#

your move system should already rely on deltaTime 🤨

raw smelt
raw smelt
limber flower
#

something in this is causeing the rotation lock

{
    //public float sensX;
    public float sensY;

    public Transform orientation;

    float xRotation;
   // float yRotation;
    private void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible = false;
    }
    private void Update()
    {
       // float mouseX = Input.GetAxisRaw("Mouse X") * Time.deltaTime * sensX;
        float mouseY = Input.GetAxisRaw("Mouse Y") * Time.deltaTime * sensY;

      //  yRotation += mouseX;

        xRotation -= mouseY;
        xRotation = Mathf.Clamp(xRotation, -90f, 90f);

        transform.rotation = Quaternion.Euler(xRotation, 0, 0);
        //orientation.rotation = Quaternion.Euler(0, yRotation, 0);

    }

}```
naive pawn
raw smelt
naive pawn
naive pawn
raw smelt
naive pawn
#

that the camera isn't rotating in pitch?

naive pawn
limber flower
raw smelt
naive pawn
#

which is why im saying to use fixedupdate for the weapons, too

raw smelt
brazen pagoda
naive pawn
#

is it rotating with the player or not?

brazen pagoda
#

It's a common mistake

brazen pagoda
#

So if you only want to set a single axis of rotation the general process is:

  1. Copy existing rotation
  2. Change only the axis you want to change
  3. Set the modified rotation
naive pawn
#

the entire point of deltaTime is to keep everything consistent in time

brazen pagoda
#

If you forget step 1. then you will not be preserving the other axes, you will instead overwrite them, which I suspect you're doing right now.

raw smelt
#

it will fire only one becouse there is only 1 update ?

naive pawn
#

ah, ok

#

@brazen pagoda there's an easier fix

limber flower
naive pawn
naive pawn
brazen pagoda
raw smelt
brazen pagoda
#

Good point

raw smelt
#

The time will slow down ?

naive pawn
#

(wrong reply, sorry; meant to reply to my own message)

raw smelt
naive pawn
limber flower
# naive pawn just use localRotation instead of rotation, so the yaw is inherited from the par...

where do i use localRotation here

{
    //public float sensX;
    public float sensY;

    public Transform orientation;

    float xRotation;
   // float yRotation;
    private void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible = false;
    }
    private void Update()
    {
       // float mouseX = Input.GetAxisRaw("Mouse X") * Time.deltaTime * sensX;
        float mouseY = Input.GetAxisRaw("Mouse Y") * Time.deltaTime * sensY;

      //  yRotation += mouseX;

        xRotation -= mouseY;
        xRotation = Mathf.Clamp(xRotation, -90f, 90f);

        transform.rotation = Quaternion.Euler(xRotation, 0, 0);
        //orientation.rotation = Quaternion.Euler(0, yRotation, 0);

    }

}```
naive pawn
brazen pagoda
raw smelt
naive pawn
#

@raw smelt if your game is going to 10 fps regularly, you have more pressing issues

naive pawn
raw smelt
naive pawn
#

you're worrying about issues that don't really exist

brazen pagoda
#

The thing that was freezing the camera rotation is the 0's you added in Quaternion.Euler(xRotation, 0, 0); which would always set that rotation to 0, which would reset any value that was not 0 from before.

But with localRotation, setting to 0 just means "0 degrees difference from the player" since "local" means it's rotation relative to the parent/player.

cosmic dagger
raw smelt
raw smelt
naive pawn
#

it's an insanely unrealistic scenario, you won't be able to learn anything from that lmao

#

fixedupdate runs at 50 Hz by default. if you have 25 fps, then it'll run fixedupdate twice per update (or per frame)
does that make more sense?

raw smelt
#

Man i can if you really wany i can give you example of losse 49% dps for 120 fps too XD but it will be harder to make example

naive pawn
cosmic dagger
#

It compensates for the drop in fps to match your number of updates (from the project settings), that's pretty much it . . .

raw smelt
#

What do you thing about make no deltatime and make max fps 60 ?

#

and no deltatime at game at all ?

naive pawn
#

@raw smelt are you actually worrying about a potential issue, or are you curious about the system? you're giving very mixed signals here

naive pawn
naive pawn
#

deltaTime is for keeping game time and real time consistent

#

if you think updates won't happen frequently enough, then use fixedupdate

raw smelt
#

so i know that i can shoot him exacly 5 times before it will move 0.4 m

naive pawn
#

so you still have deltaTime

#

you just hardcode it instead

cosmic dagger
naive pawn
#

deltaTime is just the time between Updates or FixedUpdates

raw smelt
#

i can make just 60 fps game ?

naive pawn
#

then you're just hardcoding a deltaTime of 0.016

#

you still have a deltaTime

raw smelt
#

and if you can have 60 fps game work good and if you have less than 60fps your game will slow down (and in game time too )

naive pawn
#

you can't not use deltaTime if you have anything in your game that relies on time

fast relic
raw smelt
#

To make consistance DPS of weapons for example

naive pawn
naive pawn
fast relic
naive pawn
#

that's a terrible experience

#

and that's what dynamic deltaTime fixes

cosmic dagger
raw smelt
fast relic
#

not 60 frames

raw smelt
#

in game secend

naive pawn
#

getting consistent in real time is more important for player experience

raw smelt
#

DPS of weapon is actually Damge Per Secend (in game secend)

fast relic
naive pawn
raw smelt
#

So if you have weapon X
it will kill enamy before it will kill you ALWAAYS
And not only if you have more that 68 fps ?

naive pawn
#

i have no idea what you're talking about anymore

fast relic
naive pawn
#

deltaTime makes things not reliant on framerate

#

so if you use deltaTime properly, fps just doesn't matter

raw smelt
fast relic
raw smelt
#

and you call it not more time that a number of updateds

naive pawn
#

and, like ive mentioned, you can call it multiple times per frame

naive pawn
cosmic dagger
#

Either way, there isn't an actual problem here. You're just describing how you want to shoot and potentially damage an object . . .

naive pawn
#

if you want to shoot 80 times per second, and you have 60 frames per second, you will have to shoot twice on some of those frames
same if you want to shoot 20 times per second and you have 15 fps

#

so, just shoot multiple times on those frames

#

or if it's less than 50 (or the physics tick rate, if you've changed it), you can just use fixedupdate

wintry quarry
#

The really clutch thing is positioning the projectiles as though they were fired inter-frame too

raw smelt
naive pawn
#

either way, in the original scenario where you have weapons in update and enemy movement in fixedupdate, that's the issue, not a difference in framerate
if you want them to interact well, put them on the same loop. either both on update or both on fixedupdate.

raw smelt
brazen pagoda
# raw smelt To make consistance DPS of weapons for example

So I think the issue you're thinking of is "critical numbers". As an example I wanna suggest an analogy just to explain what I mean by critical numbers:

A common example is if a little change in one number causes a big (critical) change in something else.
This typically occurs as a side-effect of discrete numbered systems - like "Frames" in this case.

But another discrete case example is "number of shots" or "number of sword swings" etc.
In a game you might have enough damage to kill an enemy in 2 hits. Let's say an enemy has 51 HP and you have 50 damage. But if you get +1 damage you can now do it in 1 hit.

So a +2% damage increase made you 100% more effective in combat.

So I think Piodd here is thinking about the scenariou where a change in FPS might change the number of Bullets are fired for a number of times.

raw smelt
#

becouse maybe enamy get into range in 0.000001 ms before frame XD so it shoot get only 1 shoot not 2

naive pawn
#

this is a problem that doesn't exist

wintry quarry
naive pawn
#

but if you're hellbent on making it one, just use fixedupdate

wintry quarry
#

can be solved with some raycasting

brazen pagoda
#

This is a real issue if you're developing a game where determinism is important, and also if you have a multiplayer game where staying in sync is real.

#

This is why some games, specially RTS games (my speciality) used a method called "Lockstep" which among other things ensure fixed time steps with fixed delta times.

#

I recommend looking that up to understand the problem space more deeply.

brazen pagoda
#

No Fixedupdate is just an approximation

raw smelt
brazen pagoda
#

If FixedUpdate was 100% fixed, you wouldn't have FixedDeltaTime

naive pawn
naive pawn
cosmic dagger
#

None of this is actually true, as it has yet to happen. It's all circumstantial. What's the point?

brazen pagoda
#

"Pretty much" does not meet the standard of "determinism"

naive pawn
#

you can configure how often fixedupdate runs

raw smelt
naive pawn
raw smelt
#

And that will be like 20% dmg

brazen pagoda
#

If you run multiplayer games that need to stay in sync, then you need 100% perfect sync because any error will accumulate over time. So you need every single calculation to be the same even if they are running on different machines.

#

Or you need to constantly be fixing the desync

wintry quarry
brazen pagoda
#

^ Fixing desync is fine in some cases

naive pawn
#

i don't know if it's even possible to change at runtime lmao

wintry quarry
#

fixedDeltaTime is indeed changeable but if you don't change it it's a constant

brazen pagoda
#

So for starters, a fixed step game doesn't use float for time

wintry quarry
naive pawn
#

you might get issues if you mix fixedupdate with update for stuff that should be in "lockstep"

#

but that would just be a mistake

brazen pagoda
#

Let me just re-iterate that in a fully deterministic system, even the fact that time is measured as a float would cause issues.

#

A "lockstep" should use a fixed long interval

wintry quarry
brazen pagoda
#

^ And that is not always the same hardware

naive pawn
#

float has a spec

#

im pretty sure it's deterministic always

brazen pagoda
#

As mentioned, online RTS games is where the Lockstep process comes from

naive pawn
#

if it's implemented to spec, at least

wintry quarry
#

not really because different hardware uses different numbers of bits internally for floating point math

#

They still abide by IEEE 754

naive pawn
#

shouldn't the result be the same, if it's following the same spec?

wintry quarry
#

no because you end up with different amounts of error based on the precision. The spec doesn't dictate how many bits of precision to use in the floating point math module

brazen pagoda
#

There's something correct for both here. But that's because of efforts that .Net has put into it. But either way - the problem is a real one. And even if a float is to spec - the developer still has to operate correctly around that and use that float correctly.

OP is asking questions about a real problem with real research and I think it's incorrect to dismiss that if they want to learn.

naive pawn
brazen pagoda
#

Just because "most games" or "singleplayer games" often don't need to care, that is not a good reason to dismiss it as "there's no problem here"

raw smelt
#

@brazen pagoda I think you undrestand my problem have you any sugetsion ? Make game frame fixed ? so i will count time by frame or something ? (i am new at game develpoing XD )

naive pawn
#

Make game frame fixed
no

brazen pagoda
#

All of the RTS games in the 90s had to deal with this problem. And there's tons of research into it.
The separation between a simulation loop and a rendering loop was to solve a problem with speed between hardware and different segments of code - not to solve determinism.

naive pawn
#

cool, not old enough to have experienced that

wintry quarry
#

Making game frame time fixed only works when you have complete control over the hardware on which the game will run

#

That's how OG arcade games in the 80s worked

raw smelt
# naive pawn > Make game frame fixed no

Why are you so "NO " XD
I know that SC2 if someone PC is too slow game actually give you information that is "slow down" (for everone) becouse of that And in game time is slower

naive pawn
#

your actual game won't have any issues relevant to this

#

if you're curious to learn in chexxor's direction, then separate that from your game

wintry quarry
naive pawn
raw smelt
#

and you will achive 1 secend and 1 in game secend if you have 60 fps

#

if you have only 50fps just game slowdown

raw smelt
#

Yep but you still don't understand XD

naive pawn
#

i do

raw smelt
#

i thinkg about fix a max fps

#

and then calculate everything per fps

naive pawn
#

you're thinking about a static deltaTime

#

and there's already a static deltaTime

#

it's called fixedDeltaTime

#

you're just making the experience worse for not much gain

raw smelt
naive pawn
#

good lord

#

exactly

#

that is my point

#

if the game can't run at 60 fps, you make the experience worse
instead of just... simulating at 60Hz and then showing it at 30 fps

raw smelt
#

if i paly game and for some reason i get like 5 fps becouse some update (not in game )
i hate when game just teleport me and i am dead becouse i see like 5 screen shoot and have no controll and enamy did hit me 10 tiems and i didn't see that

naive pawn
#

are you going to make a game that's so unperformant that it's 5fps though

#

there are easier ways to solve that

raw smelt
#

Chirs i can give you fps numer and attack speed
So i will lose for example 20dps even with 100fps XD and

naive pawn
#

i give up

raw smelt
#

becouse i will miss 1:5 frame

naive pawn
#

that just isn't an issue with a fixed time step

#

realistically you don't have to get that specific

#

you're worrying about a problem that hasn't presented itself yet

#

get your game actually working first before worrying about the details chexxor mentioned

#

realistically fixedupdate might not be perfect but it's way easier and will work fine for now

raw smelt
#

bad numbers XD

polar acorn
#

You know, the best way to explain to them why this is a terrible idea is to just let them do it

#

Have fun. Knock yourself out kiddo

naive pawn
#

someone's about to discover the law of diminising returns

raw smelt
#

did i made a mistake in calculation ?

#

4 times *

naive pawn
#

what is that intervar counter lmao

#

should go to 35 on frame 3

raw smelt
#

you check
deltaTime - lasthitTime > Attack Speed

#

if yest
lastHitTime=Time

#

or shoot time sorry

neon forum
#

for the c# language if I modify an array within a foreach loop, does the array not actually remember the modifications after the loop completes?

raw smelt
#

I probably made i wrong example XD OK i will go and thinkg about that
(but i am sure that there is non cosistency I just feel it in MATH XD )

wintry quarry
#

note that you can't modify the array by modifying a foreach iteration variable though

#

you can't modify the foreach iteration variable at all

#

unless you mean it's a class and you're changing some field in it

#

but that's not modifying the array itself

#

modifying the array would be something like myArray[someIndex] = someNewValue;

#

otherwise you aren't modifying the array

neon forum
#

That's what I thought, yeah.

Main issue I'm experiencing is that I DO modify the array correctly, but seemingly it shifts back into it's previous state post-completion of the foreachloop

wintry quarry
#

otherwise we're just speaking in vagueries

#

because it's not clear what you mean by "modifying the array" here

naive pawn
# raw smelt I probably made i wrong example XD OK i will go and thinkg about that (but i am...
frame 1
  timeSinceLastShot += 25 (now 25)
  timeSinceLastShot = 25 -> don't shoot
frame 2
  timeSinceLastShot += 25 (now 50)
  timeSinceLastShot = 50 -> shoot once
  timeSinceLastShot -= 40 (now 10)
frame 3
  timeSinceLastShot += 25 (now 35)
  timeSinceLastShot = 35 -> don't shoot
frame 4
  timeSinceLastShot += 25 (now 60)
  timeSinceLastShot = 60 -> shoot once
  timeSinceLastShot -= 40 (now 20)
frame 5
  timeSinceLastShot += 25 (now 45)
  timeSinceLastShot = 45 -> shoot once
  timeSinceLastShot -= 40 (now 5)
```you just counted wrong
wintry quarry
#

there are all kinds of pitfalls with value types vs reference types for example that could be tripping you up

brazen pagoda
# raw smelt <@166960888283267072> I think you undrestand my problem have you any sugetsion ...

First of all - I just want to voice that - if you just want to make your game, as the others said, this topic does pause your progression on that game - if you want to understand how this works, then looking at history and existing research is great. I spent some time making games in C++ by coding pixels into DirectX and building systems from scratch on that. I learnt a ton from doing so. But I didn't produce games very fast compared to what I can do in Unity by just using the existing features.


You might have a concern with the number of bullets fired over a time interval. And I wanna address that first.

A typical way of doing a cooldown system of a TD game is like the following:

public class ShootingTower
{
    public float CooldownMaxTime;

    private float _currentCooldown;

    private void Update()
    {
        _currentCooldown -= Time.deltaTime; // Or fixedDeltaTime or whichever time step you want to use

        if(_currentCooldown <= 0)
            Shoot();
    }

    private void Shoot()
    {
        // Spawn projectile and send it at an enemy

        _currentCooldown = CooldownMaxTime;
    }
}

The problem here that would cause you to loose DPS is that shooting resets the cooldown completely.
A better solution is to keep track of how much extra time has passed. I.e. "how far below 0" is the cooldown right now.
This is quite simple as you can just modify the Shoot method as follows

_currentCooldown += CooldownMaxTime;

This way, if there was extra time that will now contribute towards the next bullet being fired sooner since the new cooldown will include the negative value from before and the new value would thus start at something that's smaller than the Max Cooldown. An unlucky frame time won't delay the next bullet unless you have a really low frame counter.


Part 2 follows LuL

neon forum
#

what is the name of that sight to upload code into so I don't flood the chat?

eternal falconBOT
neon forum
#

thanks

naive pawn
brazen pagoda
#

Good point

#

Will do

neon forum
#

am I screwing up the values and refernce types?

wintry quarry
neon forum
#

ah, right, let me add the class code for that

raw smelt
neon forum
#

added tileHolder class code as well as the stringToTile method

wintry quarry
neon forum
wintry quarry
#

I still don't see what tileHolder is

neon forum
#

ah

#

That's a 2d array of TileStorages

#

it's x and y are always equal to the size of the grid on gamestart

wintry quarry
#

ok so what's going wrong with this exactly?

naive pawn
neon forum
# wintry quarry ok so what's going wrong with this exactly?

Oddly enough, when I run the game, export a map json, and then load it during the same instance, everything is fine.

When I close the game and reopen it, then load the file, the array seemingly forgets the modified tiles post foreach loop

#

and I do not know why

#

it literally says in the debug.log that it HAS them, but then when I go to the add tile section, it forgets them

wintry quarry
#

sounds lioke probably a bug in your saving and loading logic somewhere? Most likely in the saving logic

raw smelt
neon forum
wintry quarry
#

Or maybe it's not actually doing that

#

and it's just correct in memory

#

Anyway a scary part of all of this is the manual JSON parsing/manipulation stuff

#

all kinds of things could be going wrong there

wintry quarry
#

veriufy the data is being written corectly to the file,
verify it's there in the loaded string,
verify it's being parsed correctly

neon forum
#

I already did that

wintry quarry
#

verify the x/y and all the rest are being parsed correctly

#

if you did you would have found where the discrepancy is being introduced

neon forum
#

I can show you my debug.Logs that literally even after the insertion mod foreach loop the array shows that it has been updated

wintry quarry
#

yes I would like to see them

brazen pagoda
#

First of all - I just want to voice that

wintry quarry
#

make a thread

stiff mirage
#

Im looking to make a 2d game (kind of like those business games you see lol, just smthn ive enjoyed so prob the best idea to start with that), do you guys recommend any tutorials for 2d style games like that

neon forum
# wintry quarry yes I would like to see them

okay, for the sake of not making 1 billion lines, I will create a if statement that checks to see if the tile is modified(if the tileType != 1, post the log),
I will also debug.log the fixit string, which is the string that is parsed by my stringToTile, as well as the result of stringToTile's parsing before it is converted into a tileStorage object.

winter glade
#

Hello.
I'm trying to do a top down movement in 3D in Unity, and my player got a rotation where it looked. I have only the 8 directions.
The problem is when I walk diagonally, the player is looking in the right direction, but when I release the keys sometimes the player realign in one of the other two directions when they should stay facing the diagonal.
I imagine that I'm not releasing the keys at the same frame and therefore I have something like (0, 1) at the last frame.
How can I fix this?
I'm not sure what this problem is called, so I didn't find much on Google.

        Vector3 movement = new Vector3(moveInput.x, 0, moveInput.y);
        
        // Movement
        rb.linearVelocity = movement * moveSpeed;
        
        // Change rotation of the player
        if (movement != Vector3.zero)
            transform.rotation = Quaternion.LookRotation(movement);```
brazen pagoda
# winter glade Hello. I'm trying to do a top down movement in 3D in Unity, and my player got a ...

I think your theory is accurate on the release timings.

The first idea that comes to mind is to not do the rotation instantly. Maybe do a "rotation-over-time" approach, this way if you release both keys quickly it won't have time to do the full rotation to the 90-degree angles.

Another approach could be to add a delay - say rotations only happens 0.1s after a key change, but gets ignored if both keys are released by then.

#

Normally I would see a variation of this problem when an analogue stick was released and when it almost reached 0 I would get some odd inaccuracy behaviours. The solution then was to increase the deadzone (Input Settings) of the stick or the threshold of when to ignore stick input (Code). (Instead of Vectro3.zero, check if the ABS input is greated than 0.0001f)

errant shore
#

I use a event system in the sample scene and in the main menu. when i turn it off its inpossible to click the start game button. So why cant i have 2 event systems? Or can I have 1 event system for every scene and how do i do taht

wintry quarry
#

If you're additively loading scenes you could either not include one in the additive scene or use a singleton pattern for it to ensure there's only one at a time

errant shore
#

ooooooooooooooooh

#

thank you very much

#

but i need to inlcude one

rocky canyon
#

yes u do..

#

id keep 1 with some type of master scene.. or in ur DDOL (dontdestroyonload)

errant shore
#

waittttt i made a mistake

rocky canyon
#

i have a GameCanvas

#

i always have.. none of my other canvas' have an eventsystem

#

they'll all work off that 1

errant shore
#

niceeeee, I had a event system in the sample scene and it was completely useless

#

so now it works

rocky canyon
#

samplescene is completely useless

#

there i fixed that for ya

#

lol

errant shore
#

where do you guys upload your finished games? so friends or other people can just download and play or something like that

rocky canyon
errant shore
#

whoa thank you

rocky canyon
#

on itch u can post both executeables (installed games)
and webGL (games played in the browser)

errant shore
#

oh thats good but I need a tutorial for exporting, ill search on yt

#

exporting from unity

#

yo there are coool games

errant shore
#

guys my head is exploding,I ve done something and now they load both at once

cosmic quail
errant shore
pure pike
#

So I have a script so when I press and hold a certain button, a thing activates, but how would I make it toggle so I press it once it pops up, then press it again to close it

rich adder
pure pike
errant shore
#

guys please , i have only the main menu scene in the build settings, why does it load the level

rich adder
#

what is "the level"

errant shore
#

level scene

#

so i have 2 scenes main menu and level, mainmenu is in buildsettings, but both get loaded

whole osprey
#

Are you accidentally calling whatever you do when you press play at some other time?

rich adder
edgy radish
#

Hi. I just started trying to integrate my MySQL database into my game on Unity 2022.3.53f1. I understood the dangers of connecting a database directly to the game, but I decided to do it anyway, to test. I took a look at the MySQL Connector, and saw that each version was compatible with a version of Unity's .NET. However, I don't know which .NET version my Unity has, as it no longer appears. How will I know which version of the MySQL Connector is compatible?

#

I didn't see .NET Standard in the list of MySQL Connector versions.

errant shore
rich adder
rich adder
edgy radish
rich adder
#

.NET Framework can add a bit of "bloat" but gives you more compatibility

edgy radish
#

thx, I'll test it

edgy radish
#

I placed MySql.Data.dll in the Plugins folder, and the following error occurred:

Unable to resolve reference 'Google.Protobuf'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Unable to resolve reference 'ZstdSharp'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Unable to resolve reference 'K4os.Compression.LZ4.Streams'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Unable to resolve reference 'BouncyCastle.Cryptography'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.```


Do I download whatever he asks for on Google?
#

I left Unity on .NET Framework, and downloaded MySQL Connector 9.2.0.

rich adder
edgy radish
#

Oh, then version 8.0.20 should work. I'll test it.

rich adder
#

or use SQLite

#

though I would not use MYSQL locally at all. No point

edgy radish
#

If it still doesn't work, I'll try all of your options. Thanks.

rich adder
#

unlike SQLite which can be portable, this would not even run on anyone who doesnt have sql server

molten cipher
#

Made this simple c# Scrip where. Player Looks at the Target's position and Moves towards it when you press Forward..
it is a Simple script. i'm just learning and did this as a practice...


using UnityEngine;

public class LookRotation : MonoBehaviour
{
    public GameObject target;
    public float lookSpeed = 2f;
    public float moveSpeed = 5f;


    void Update()
    {
        FollowAndLookAtTarget(); // Call the method to follow and look at the target
    }





    void FollowAndLookAtTarget()
    {
        // Get the target position
        Vector3 targetPosition = target.transform.position;
        // Get the target position in the world space
        float moveVertical = Input.GetAxis("Vertical");
        // check if Target is attached 
        if (target != null)
        {
            Vector3 moveDirection = (targetPosition - transform.position).normalized; // Normalize to prevent faster diagonal movement
            transform.position += moveDirection * moveVertical * moveSpeed * Time.deltaTime; // Move the Player

        }


        //  Get the Gameobject to LOOK AT Target object
        Vector3 lookAt = new Vector3(targetPosition.x, targetPosition.y, targetPosition.z); // Get the target position
        transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(lookAt), Time.deltaTime * lookSpeed); // Smoothly rotate towards the target direction
    }
}
keen owl
rich adder
molten cipher
molten cipher
rich adder
molten cipher
#

i'm reading

rich adder
#

but yeah lerp is least of the problems, so normally you want to move a rigidbody or character controller directly

molten cipher
#

i just made this code based on what i know ( i don't know much) started coding 4 days ago

#

haven't gone to Character Controller part yet. i'm practicing on cubes and spheres

rich adder
#

mhm and now you learned a few new things

molten cipher
#

tbh i didn't it's too complicated to me.. like Wrong-Lerp? it says that it is it's own thing... i don't like to rush things . i only want to learn step by step and make sure to understand what i'm doing.. my goal there was to Make the cube's Z (forward) Value to rotate towards the Target's Position..

#

it does do that

#

i'll get better eventually

rich adder
#

I'm just pointing out what was wrong, but its very unlikely anyone is at all going to use this

#

lerp is the least part that is wrong

molten cipher
#

i never said to use it.. i said " you can do this and that" as in, it is possible...

#

oh nvm i did say that

#

lol

#

my fault

rich adder
#

this is a null ref waiting to happen

 Vector3 targetPosition = target.transform.position;
        // Get the target position in the world space
        float moveVertical = Input.GetAxis("Vertical");
        // check if Target is attached 
        if (target != null)
        {```
#

do you know why?

#

the last line is hint towards what's wrong

molten cipher
#

target position is a tarrget Gameobject's position data.
float is a data -1 or 1 based on Vector3(data, 0, 0

#

and

#

if target is not null

#

then should the following code happen

#

meaning if the Target is assigned

#

don't see any errors here

rich adder
#

look careful.

#

in order to access the position vector3 data as you said, where are you accessing that

#

its just an order issue mainly.

molten cipher
#

Vector3 targetPosition = target.transform.position;

#

here

rich adder
#

yes that comes from the component transform

#

but on target

#

do you see where i'm going ?

#

if target is ever not assign aka null, what do you think its going to happen

molten cipher
rich adder
molten cipher
#

oh you mean it'll freeze in one space

#

meaning it's direction will be 0

#

that's what you're saying?

rich adder
#

no

#

you are accessing transform component from a target gameobject

#

if you don't have target assigned, aka its NULL. How would access a transform component on a Null object ?

molten cipher
#

if ( Target is not Null) then the code will happen...

#

if it's null

#

it won't

rich adder
molten cipher
#

in the Void function

#

which then goes to Update

rich adder
#

I am aware, I can see it

#

you're not understanding
that one is unrelated to the line i pointed at

molten cipher
#

well you're not saying what the issue is so. how can i understand it.. idk what you mean

rich adder
molten cipher
#

i don't have it dude i just started

rich adder
#

well perhaps start with the basics of c#

molten cipher
#

first steps and ongoing.

#

and tried to make a script based on my knowledge

rich adder
#

its good site but you still need to check individual c# basics

rich adder
molten cipher
#

up to down.

rich adder
#

okay good

#

so given that order, what do you think its going to happen here on this line
Vector3 targetPosition = target.transform.position; if target is not assigned

#

your null check is where?

#

before or after?

molten cipher
#

are you saying that it should be inside of the if statement?..

rich adder
#

if you want to test it go ahead, remove the reference(in the inspector) from the target field see what happens

molten cipher
#

sec

#

so i had to place everything inside of the if statement and it has no issues now, with or without target attached.

#

understood ! thank you

rich adder
#

yup mainly anything that has target reference, moveVertical never needs to be in if statement, but it can if you want to

molten cipher
#

thank you, will note that.

native widget
#

Does unity expose any information for the last time the player did a full click (mousedown, mouseup)?
I want to do something when the player did a click, followed by a mousedown+drag

#

I want to do something when the player did click-drag

sour fulcrum
#

i don't believe so but it should be pretty easy to manage yourself

native widget
#

Seems like it, I just made all my images to hold the time they were last clicked

sour fulcrum
#

do the images need to know that?

#

whatever is managing your input stuff can probably right?

raw smelt
#

Is there any implementet function for finding (k) biggest elements ? k<< n

var closestGameObjects = gameObjects
            .OrderBy(go => (go.transform.position - origin).sqrMagnitude)
            .Take(5)
            .ToList();

that pard of code have O(n) or O(nlogn ) ?

earnest wind
#

is this the way one should copy the values of a script to another script?

#

or is there a better way only to copy the public variables

native widget
eternal needle
earnest wind
#

i guess it would be okay for the manual work?

#

since if i would do some tricks by copying it might not make new lists, but just make pointers

eternal needle
slender nymph
#

whatever this component is, also seems like it is doing way too much

slender nymph
#

i meant the component being copied

earnest wind
#

it holds all the data for the component

eternal needle
#

it seems to hold literally everything lol

earnest wind
#

yep

eternal needle
#

color, rigidbody, shader details, lights??, input

slender nymph
# earnest wind it holds all the data for the component

and "the component" has too many responsibilities and should realistically be broken up into several. and if this is some sort of data storage object, why not just copy it with the MemberwiseClone method which makes a shallow copy of the object (which this seems to be sort of doing)

earnest wind
#

no need to anyways

eternal needle
#

you 100% can, you just dont want to

#

theres also no need to do it the way you are currently doing it

earnest wind
slender nymph
#

it's also objectively worse if it is all in 1

#

you're creating a nightmare to debug

eternal needle
#

might as well make your entire game in one file too

earnest wind
earnest wind
eternal needle
#

🤷‍♂️ all youve shown is a bunch of lines assigning a field to another field. I dont know what you actually intend to do with this in the first place. Maybe take a step back and see what problem you're actually solving here

earnest wind
#

it doesnt have icons yet sadly but i will do that later

slender nymph
earnest wind
slender nymph
#

sure, jan

earnest wind
#

wat

eternal needle
# earnest wind level creator

could you possibly be anymore vague? i think i got too much information out of this. Seriously, take some time and actually think about what you're doing here. how am i supposed to say anything based off this message and the code above

earnest wind
slender nymph
#

what you are currently doing does not create new lists either

eternal needle
earnest wind
earnest wind
#

i just wanted to know if there are ways to copy

lean steppe
#

Anyone know how to swap layers in runtime?? Ite giving me this issue here

slender nymph
lean steppe
lean steppe
eternal needle
eternal falconBOT
woeful locust
#

hey have i problem that i feel the solution i srelatively simple i just dont understand how to fix it exactly

#

so basically i am trying to make a 2d top down game.. but my character controller doesnt work

#

(i copied it form this one minute video)

slender nymph
#

show code (see bot message above)

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

public class playerController : MonoBehaviour
{


    public float movSpeed;
    float speedX, speedY;
    Rigidbody2D rb;
    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();  
    }

    // Update is called once per frame
    void Update()
    {
        speedX = Input.GetAxisRaw("Horizontal") * movSpeed;
        speedY = Input.GetAxisRaw("Vertical") * movSpeed;
        rb.velocity = new Vector2(speedX, speedY);
    }
}
#

error is

#

Assets\playerController.cs(13,27): error CS0246: The type or namespace name 'RigidBody2D' could not be found (are you missing a using directive or an assembly reference?)

fast relic
#

it's Rigidbody2D not RigidBody2D

slender nymph
#

then you need to save your code again because you don't have RigidBody2D aywhere in that snippet you posted

woeful locust
#

thank you

#

i knew it was relatively simple

verbal pollen
#

Does anybody know why physics isn't working for unity dots, when I create a sphere, and I place a rigidbody it doesn't fall

woeful locust
#

but i couldnt see it for some reason..,

fast relic
verbal pollen
#

first time

#

trust me

verbal pollen
#

im sorry 😭

lean steppe
eternal needle
#

dont spam please, just delete the crossposted messages and leave it in the dots channel

woeful locust
fast relic
lean steppe
#

Wait no not channel. Whatever the chat thing is called

woeful locust
slender nymph
woeful locust
#

wait

lean steppe
woeful locust
#

ok

#

its fixed

eternal needle
# woeful locust yep

if you really did, then maybe just a rare bug where unity didnt pick up the changes and didnt recompile

#

ive had that happen once a blue moon

woeful locust
#

i made a space adn then saved

#

and it worked

lean steppe
slender nymph
lean steppe
#

Sooooo any updates is it working yet

#

Sorry just nosy lolz

slender nymph
lean steppe
#

? Ok im confused now

slender nymph
#

that is a link to a specific message. you know, the one where they said "it worked"

lean steppe
#

OH I thought that was a ref to a previous experience oops

celest ridge
#

The number references upfront of the variable is very annoying how to disable it it reduces the beauty of my script..😅

slender nymph
celest ridge
#

Then what to do ? Do every one use it they are usefull but annoying they create a extra space between two lines isn't any option to see them and also they don't create space ??. Do you use them as it is ??

lean steppe
timber tide
hollow quest
#

maybe if codebase was 1 million lines sure

lean steppe
#

Anyway. Anyone know how to do Additive Blending? I’m pretty much nearly clueless about Shaders lol I was wondering if Unity has a preset one or something…

sweet lantern
timber tide
#

Some of Unity shaders provide it, otherwise shader graph it

#

The particle shader I know for sure has options for it

#

Oh wait, lit already provides additive

sweet lantern
#

Imagine you have 1000 lines of code and the compile says, "There's an error somewhere." Now, you have to search through 1000 lines and check each one just to try and see where the problem is, let alone what it is. Versus if it just said, "Null Ref on Line 42," then you know something specifically on Line 42 is null. Much easier.

#

The numbers can also help inform you of when your class is getting too big and it might be time to refactor and split things off. If it starts going above 500, that might be a good time to consider that your script could be doing more than it should.

celest ridge
#

I was thinking that when I see some of the old tutorials they write code and they don't have this refrences resulting there code is look preetier and I also want to disable that but now I realised that is not annoying that is usefull..

lean steppe
hidden fossil
#

guys how do i fix this glitch? once the enemy reaches the end, the enemy disappears but the healthbar stays there?

celest ridge
#

@lean steppe yeah i turned off and re on them.. I'll use it whenever I want which thanks...

rich adder
hidden fossil
#

!code

eternal falconBOT
hidden fossil
rich adder
#

a glitch would be if it was unexpected behavior

hidden fossil
#

oh i have to implement a destroygameobject?

rich adder
#

if you want to get rid of it

hidden fossil
#

ok

celest ridge
#

Hey I'm writing some of my first scripts in the game I want to create a script for player movement where I can go forward backward with keys and rotate around with mouse but confused what to do while I'm using rigidbody's add force fucntion I hold the key force adding on it continuesly.. and having abnormal behavior if I use linearvelocity function it oppose all the other velocities applying on the object for transform.position it going beyond the wall and penetrate the wall.. what should I took approach..

cloud walrus
#

I'm having some weird unexpected behaviour, i can't modify Y Axis in real-time it's like that i could modify it but i only see the change when i'm in game mode and even when i'm in game mode i can't change it, watch the video to understand

What i'm trying to fix is to make it modifiable in real-time where i see the changes immediately

slender nymph
#

you need to use something like OnValidate to do that

cloud walrus
#

this is my code btw


public class Level2Position : MonoBehaviour
{
    [SerializeField] GameObject theObject;
    [SerializeField] GameObject minPosition;
    [SerializeField] GameObject maxPosition;
    [SerializeField] float yAxis;
    [SerializeField] float zAxis;
    void Start()
    {
        Vector3 midPoint = GetMidPoint();
        theObject.transform.position = new Vector3(midPoint.x, midPoint.y * yAxis, midPoint.z * zAxis);
    }

    void Update()
    {
        
    }
    Vector3 GetMidPoint()
    {
        return (maxPosition.transform.position + minPosition.transform.position) / 2;
    }
}
cloud walrus
slender nymph
#

you also only ever use the value of that variable inside of Start which runs a single time in the object's lifetime (during runtime)

rich adder
#

but yeah you could put that offset pos logic in OnValidate

cloud walrus
#

so i need a new method called OnValidate so the changes happens in real-time? that's it?

cloud walrus
#

thx a lot guys I appreciate your help!

cloud walrus
#

Thanks guys! it's totally working fine now! @rich adder @slender nymph


public class Level2Position : MonoBehaviour
{
    [SerializeField] GameObject theObject;
    [SerializeField] GameObject minPosition;
    [SerializeField] GameObject maxPosition;
    [SerializeField] float yAxis;
    [SerializeField] float zAxis;
    void Start()
    {
        UpdateObjectPosition();
    }

    void OnValidate()
    {
        UpdateObjectPosition();
    }
    Vector3 GetMidPoint()
    {
        return (maxPosition.transform.position + minPosition.transform.position) / 2;
    }
    void UpdateObjectPosition()
    {
        Vector3 midPoint = GetMidPoint();
        theObject.transform.position = new Vector3(midPoint.x, midPoint.y * yAxis, midPoint.z * zAxis);
    }
}
vagrant wolf
#

I'm a begginer in unity for some reason when i type debug on script editor it doesn't show me the complete word how can i fix that i looked up a lot of tutorials and didn't find a solution

eternal falconBOT
acoustic belfry
#

Hi, i been wondering, how i can make a character/enemy do specific kind of movements in a 2D plataform setting. I mean, like a boss or smt

cuz for example i want my enemies that when the player is too near of them, to jump upward and fordward (right or left). or another enemy that when spots the player it jumps towards it. The thing is, how i manage to do so?

i tried using the pushforce but i feel like is too "unstable" for the job

eternal needle
acoustic belfry
eternal needle
#

i havent played either of those games

acoustic belfry
#

oh...

well, what i mean is like, enemy is in place A, it moves to a place B inside it own area

eternal needle
lunar coral
#

Hey guys, I am trying to get the arm to point to the location of the mouse, and it works as intended except for when the mouse position gets too close to the arm. When it gets too close, the arm rapidly rotates up and down.

Link to a video showing the issue here: https://youtu.be/9aqUBjuiTs4

The arm sprite uses a custom pivot point at the edge of the arm.
Code for the rotation of the arm and the gun here:

Transform parentTransform = this.transform.parent.GetComponent<Transform>();
var lookDirection = Input.mousePosition - Camera.main.WorldToScreenPoint(transform.position);
float angle = Mathf.Atan2(lookDirection.y, lookDirection.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
parentTransform.rotation = Quaternion.AngleAxis(angle-90, Vector3.forward);

The gun is a child of the arm, so parentTransform refers to the arm.

Pretty new to Unity/game dev so thanks in advance! And ignore my bad placeholder art haha.

hexed nymph
#

Yooo I want a animated button but the animator component does not work

#

I clicked on the "auto generate animation" and doesn't work either

#

does anyone knows how to solve this?

#

I also have the update mode in Normal

#

I did the animation in Adobe Animate

pulsar creek
#
private void TriggerExplosion(Vector3 explosionCenter)
    {
        GameObject explosionInstance = Instantiate(explosionPrefab, explosionCenter, Quaternion.identity);
        
        GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
        GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy");

        
        GameObject[] enemiesAndPlayers = new GameObject[players.Length + enemies.Length];
        players.CopyTo(enemiesAndPlayers, 0);
        enemies.CopyTo(enemiesAndPlayers, players.Length);
        List<Life> lifeInRange = new List<Life>();

        
        foreach (GameObject obj in enemiesAndPlayers)
        {
            Life targetLife = obj.GetComponent<Life>();
            
            Rigidbody targetRb = obj.GetComponent<Rigidbody>();

            
            if (targetRb != null)
            {
                
                Vector3 directionToTarget = obj.transform.position - explosionCenter;

                
                float distance = directionToTarget.magnitude;

                
                if (distance <= explosionRadius)
                {
                    lifeInRange.Add(targetLife);

                    
                    directionToTarget.Normalize();

                    
                    targetRb.AddForce(directionToTarget * explosionForce, ForceMode.Impulse);
                }
            }
            DealDamageToLife(lifeInRange);
        }
    }
void DealDamageToLife(List<Life> lifeList)
    {
        foreach (Life life in lifeList)
        {
            if (life != null)
            {
                life.LoseLife(damage);
            }
            else
            {
                Debug.Log("Life is null");
            }
        }
    }```

Is there a reason why I'm always getting Life is null logged? I'm certain I have a LifeManagerEnemy method in every enemy, which inherits from Life.
#

Nevermind, I think I figured it out

#

The life component wasn't in the object I'm checking, but in its child

naive pawn
shy pollen
#

so... quaternion * vector3 isnt working for me.. im trying to rotate a vector3, and i swear i've done this before this way.... :/

pulsar creek
#

If I recall correctly, it should be the opposite, no? vector3 * quaternion

shy pollen
#

neither way works :/

pulsar creek
#

Can I see the code?

#

Like, just that part?

shy pollen
#

flipping the quat & vector3 wont compile either

#

i swear it should be working, something with unity 6?

pulsar creek
#

It might not be this, but try capitalizing Quaternion

shy pollen
#

oh wow...

pulsar creek
#

I'm rotating objects just like that, and for me it works in Unity 6

shy pollen
#

yeah that was it..

#

and its quat * vector3

#

Thanks unity for that near invisible tripwire 🫠

hexed nymph
#

Yooo I want a animated button but the animator component does not work
I clicked on the "auto generate animation" and doesn't work either
does anyone knows how to solve this?
I also have the update mode in Normal

#

Idk if this helps but the animation isn't just scaling the button or moving it, its another sprite

#

I created the anim in Adobe Animate and but it in the game as a animation with a controller but for some reason the button does not animate

stark burrow
#

If movement is updated in fixedupdate and camera in update in fps. Does it mean that movement can have different delay based on fixedupdate timer and player could move to different angle compared to camera rotation

pure pike
#

Mb

spiral quest
#

can anyone help me out how to use smartphone camera as real time video streaming to unity

subtle osprey
#

how would i modify an achievement so that it changes the popup depending on the level

#

like my game runs off a game manager and the achievement conditions are stored there

rocky canyon
#

well wouldnt u just check the level w/ the gamemanager and change it

vagrant wolf
#

I have a variable for sideway when i put it on the addforce it doesn't work but if i put a number it works

rocky canyon
#

its probably not enough force then

edgy radish
# rich adder <https://github.com/Hanslen/Unity-with-MYSQL> this one has a perfectly working D...

The DLL problem was solved, but now there is this other error when trying to connect:

Error connecting to database: Client does not support authentication protocol requested by server; consider upgrading MySQL client
UnityEngine.Debug:LogError (object)
MySQLConnector:Connect () (at Assets/Scripts/Others/MySQLConnector.cs:37)
MySQLConnector:Start () (at Assets/Scripts/Others/MySQLConnector.cs:22)

I have already tried changing the database name, changing from localhost to 127.0.0.1, changing the order of the access credentials, but it did not work.

#
connection = new MySqlConnection(connectionString);```
red igloo
rocky canyon
#

well. since ur camera is already moving.. u can just use the cam's directions multiplied w/ ur input

#

if(w)-> movePlayer with cam.transform.forward * input;
if (a)-> movePlayer with -cam.transform.right * input; etc

red igloo
#

Thanks I will try it 👍

rocky canyon
#
        Vector3 moveDirection = (cameraTransform.forward * vertical + cameraTransform.right * horizontal).normalized;``` something like this
#
        characterController.Move(moveDirection * moveSpeed * Time.deltaTime);
noble cedar
#

is there anyone willing to check my code and help me also teach me how to optimize correctly my scripts in unity like what to do or what not to do I have self learnt unity. I am asking this because sometimes when I am testing my game in editor it just freezes idk if I somehow made infinite loop or just my PC isnt strong enough for rendering it sometimes

red igloo
#

How would I control the mouse sensitivity? Is there a setting in cinemachine 3?

rocky canyon
#

how is it set up? are u controlling the cam w/ code?

naive pawn
#

well, same in most if not all programming languages

rocky canyon
#

big red squigly != tripwire

brazen pagoda
#

At least you get big red squigly - unlike Python that will pretend everything's fine, and send you on a 3-hour journey to find out why stuff don't work

naive pawn
noble cedar
rich adder
vagrant wolf
#

i feel like c++ is easier than python no?

rich adder
#

hell yea

#

python stinks

umbral rock
#

so i have a movement script here with a character controller and i would like to be able to jump, how can i implement this with a character controller? or do i need a rigidbody to do it?

eternal falconBOT
vagrant wolf
#

What is the easiest language?

rich adder
#

subjective

vagrant wolf
#

nah Luau

rich adder
#

math heavy people like functional programming (haskell, clojure, lisp) or like pythony ones

#

arguably C# is one of the easiest langs

tight inlet
#

Imo python is just english with extra steps

#

But c# is quite beginner friendly as well

hexed nymph
#

Yooo I want a animated button but the animator component does not work
I clicked on the "auto generate animation" and doesn't work either
does anyone knows how to solve this?
I also have the update mode in Normal
Idk if this helps but the animation isn't just scaling the button or moving it, its another sprite
I created the anim in Adobe Animate and but it in the game as a animation with a controller but for some reason the button does not animate

wintry quarry
hexed nymph
#

Oh sorry!!

lean steppe
#

nvm wrong chanel

ashen wind
#

I'm making a mobile game and when I play the build on my phone, the physics feel fine, but on my friend's phone it seems like the player is accelerating way too fast

#

I'm guessing it's a lag thing

#

my physics code is this:

            if (rb.velocity.y < 10)
            {

                rb.AddForce(new Vector3(0, gs.upwards_thrust, 0), mode: ForceMode.Force);
#

I know that sometimes lag issues are normalized by multiplying by time.deltatime, so I also tried this

rb.AddForce(new Vector3(0, gs.upwards_thrust * Time.deltaTime, 0), mode: ForceMode.Force);```
#

but it didn't seem to make any difference

wintry quarry
#

We need to know if this is happening in Update or FixedUpdate

#

AddForce should only go in FixedUpdate generally

ashen wind
#

update

#

got it

wintry quarry
#

Yeah that's your problem

ashen wind
#

i'll try that first

wintry quarry
#

And get rid of deltaTime

ashen wind
#

is there anything that as a rule shouldn't go in fixedupdate?

wintry quarry
#

Input handling

ashen wind
#

but the force is only added when the player gives input

#

so isn't this input handling?

wintry quarry
#

Yes

#

It's fine if it's like GetButton or GetAxis

#

Not ok if it's GetbuttonDown or GetKeyDoen

#

In general the ideal approach is to handle the input in Update and the physics in FixedUpdate

#

You would communicate between the two with variables

#

But for this simple case it's ok to read the input in FixedUpdate as long as it's not a GetKeyDown situation for example

ashen wind
#
if (Input.GetKey(KeyCode.Space) || Input.GetMouseButton(0) || Input.touchCount > 0)```
#

so what you're saying is this would be fine to put in fixedupdate

wintry quarry
#

That will work fine

ashen wind
#

thanks so much

formal valley
#

hi how can I spawn the white circle in random position but not in at a specific height from floor and platforms.

wintry quarry
formal valley
#

ok wait

rich adder
#

do you mean like not spawning it inside the platforms?

formal valley
#

yeah and not in the air that the player can't reach it.

rich adder
#

hmm probably some type of while loop then do some Casts to check if its blocked, for height you can take into account the Player jump height / max reach (need a bit of maths) and keep the iteration until you find suitable place (throw a max iterations for not endlessly finding)

naive pawn
#

you could randomize only the x position and then if it's in the platform area, displace it upwards

rich adder
#

yea that could be simpler actually

naive pawn
#

or randomize the x position but y above everything, and then raycast down to displace it downwards appropriately

#

though both of those solutions wouldn't let it spawn in the space under the platform

formal valley
#

can I do it here or do I need to write new script and make Tag.

#

thx

naive pawn
formal valley
polar acorn
formal valley
umbral rock
#

i dont understand, i am working with a character collider and whenever i stand still on the ground he doesnt say he is on the ground and when i start moving then he says im on the ground, how is this possible?

#

i wanna implement a jumping system so i can only jump when my character controller is on the ground

#

and now i can only jump while my character is moving lol

rich adder
polar acorn
rich adder
#

isGrounded only works while .Move is called iirc

umbral rock
umbral rock
umbral rock
#

is it bad to call the move more then once in the update method?

cosmic quail
rich adder
#

combine your Move call into 1 operation

polar acorn
#

Grounded gets set only when _the previous _ move call hits ground