#💻┃code-beginner
1 messages · Page 309 of 1
just do
text = "Price " + merchantPrice
i can do that
i hope
boah i need to think of another name
No you don't
You don't have to store it in a variable
hmm MerchantDisplayPrice
thats overkill
No no. Look what nav just sent
Can someone help? The hurt animation wont play even with the correct parameters. The hurt state will be active but the animation its self wont play
interesting
thank
ok thats overkill
You have a line from Any State to the hurt animation, which includes from the hurt animation
so it'll start that animation every frame until the condition is no longer true
if you need the variable to be not at the end/begin of string or have multiple vars in string, use string interpolation
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated
kk
Oh I see, any fix like setting something to 0?
Generally don't have any transitions from the any state
That was a bad habit of mine for a while. I think it was Spazi that taught me not to, and animating became much easier afterwards
You could use a trigger parameter instead of a boolean
or you could just not use any state
MerchantPriceCounter.text = "Price " + MerchantPrice;
this right?
im scared to try it
whilts i was tryingto do the multiplications stuff
i input some wrong numbers and my pc went off
putting strings together should've been one of your first lines in c#
with variables
yes
bold of you to assume this person has actually bothered learning c#
i actually did
I'm gonna drop this here again
https://www.w3schools.com/cs/index.php
i watched a 5 hour long video on it
then i watched brackeys video on it
then game dev of brackeys
Think of 1.2f or "Hello" as implicit variables.
It's the same thing
where is the
"Hello world my name is " + firstName
I did NOT put hello world
Which, as we explained, is a really really bad course. And is likely the reason it is so hard
and i wil not say what i inputed there
Watching other people code is pretty much nothing. Especially if you're watching brackeys then you've probably learned less than nothing
alr well ima go to beed
Just try an NON-video lesson
It's like staring at the plumber fixing your bathroom, then thinking you're a plumber as well
No, extremely simple.
But so was the rest of all this today
increase the variable in Update

yes but i am learning

Do this
https://www.w3schools.com/cs/index.php
Then come back
yall tought i was a troll 3 hours ago
I need some help, how can i create such fields that i can expand like add one. I dont know What they are called so I cannot find any explain videos
Like in the image, when i tap + it adds one more input field
well now i can kinda programm
so i can finally say im a programmer!
wait a second
thats just a bigger nerd
eh its fine i dont have friends to make fun of me
yes father
I dont think this is specifically called anything. It's just a button, which adds to a list and a child of what seems to be a vertical layout group
i will do as you please
probably to do with content fitters, scroll view, and other #📲┃ui-ux layout groups. adding more is the easy part (it's just instantiate), formatting the UI to look good is the hard part
Ahh yeah i havent thought about that
well
Thanks guys 👌🏻
vertical stack layout group
show
#1180170818983051344 if you wanna show or see games
Hey why could it be that I can't see the "AddHeroesToSlots" function when I'm using a button?
public List<GameObject> heroesInSlots = new List<GameObject>(); // List to hold the heroes in slots
// Method to add a list of heroes to slots
public void AddHeroesToSlots(List<GameObject> heroes)
{
if (heroes.Count <= heroSlots.Count)
{
for (int i = 0; i < heroes.Count; i++)
{
heroesInSlots.Add(heroes[i]);
heroes[i].transform.position = heroSlots[i].transform.position; // Position the hero in the slot
}
}
else
{
Debug.LogWarning("Not enough slots to add all heroes!");
}
}```
because you have a List as an argument, the button probably doesnt allow that
oh
what could i use to make it work?
Why you need the list as an argument?
just GameObject itself?
you can but then you would only be able to add 1
Nima ^
does it change on button press?
no
you can use a separate list. you don't need an argument
👍 ty
like you did on top with public List<GameObject> heroSlots = new List<GameObject>();
just add another list and use that instead
alright thanks so much ❤️
so im trying to make a fps game in unity but im having troubleshooting with the movement. See, everytime my character Y position goes up for a bit, the player will elevate, and i also cant move in the air, i've tried many things but none of them seem to work, here's the code:
`private void FixedUpdate()
{
float horizontalInput = Input.GetAxisRaw("Horizontal") * Time.deltaTime * MovementSpeed;
float verticalInput = Input.GetAxisRaw("Vertical") * Time.deltaTime * MovementSpeed;
Vector3 cameraForward = Camera.main.transform.forward.normalized;
Vector3 cameraRight = Camera.main.transform.right.normalized;
cameraForward.y = 0f;
cameraRight.y = 0f;
Vector3 ForwardRelative = verticalInput * cameraForward;
Vector3 RightRelative = horizontalInput * cameraRight;
Vector3 MovementDirection = ForwardRelative + RightRelative;
rb.velocity = new Vector3(MovementDirection.x, rb.velocity.y , MovementDirection.z).normalized * MovementSpeed;
/*
Rigidbody values
0 = ground level. a single change in the y axis up or down will make it go that way until something blocks it.
1> = one or more. Going up until something blocks it.
<-1 = minus one or less. Going down until something blocks it.
*/
Debug.Log(rb.velocity.y);
}`
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
oh yeah forgot about that
show a video of the problem also maybe
The player goes back because i placed an invisible plane on top so it goes back
and it happens because if it changes from cube to cube, Even if they are in the same Y level
or its y level goes up for a bit
he said he put that there so it doesnt go up infinitely in the sky i think?
not that i bounce, I elevate, i elevate because the player's Y level goes up for a bit, Because there are 2 cubes in the area inside each other, but even though they are at the same Y level of position it goes up
And... you don't want that to happen?
What does "two cubes in the area inside each other" mean exactly
Are you using gravity on the player btw?
yeah
are you jumping or anything? or are you literally just pressing W
literally pressing w
i havent coded the jump function yet
You seem to use the previous rb velocity.y, but it is somewhat pointless, since you normalize the vector and multiply it by speed. The gravity just can't build up.
so what can i replace rb.velocity.y with? if i change it like using a number it'll either go up or down, if i use 0 it pretty much goes down slowly. but makes the player walk in solid terrain, im not really sure what to do..
just dont normalize it i think he means
not the actual velocity itself anyway
Yes. The issue is the normalization, since it modifies the value on the y axis along with the rest of the vector.
oh yeah those are the same but i accidentaly typed caps lock at the time of editing the message
ok thought so just wanted to make sure
well now pretty much when i removed the normalization the player walks much slower, and depending on the camera angle (I believe) it happens the same thing but MUCH faster
My previous reply was purely based on your initial code. After looking at the video I'm not sure what the issue is anymore.
a good thing to test always is just make a new scene, add one plain floor and your player
and see what happens
alr
Yes, because now you're not applying your speed multiplier. You need to rewrite that line entirely. Calculate the horizontal velocity first. Then add the vertical one.
still the same
on just one singular plain floor?
anyone have a beginner tutorial for how to code ai for the newest version of unity?
upload the full code on the website !code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Define "AI"
enemy ai literally everything about it
the whole script
patrolling, pathfinding, shooting, etc.
any1 know a good tutorial?
lookup llama academy
has good series on AI / Navmesh agents
k thanks
There are many ways to implement that. Did you try googling?
Define "good"
try removing the * Time.deltaTime on your inputs?
they're all pretty much the same, they just moved some packages n buttons
even still none use the newest version of unity
so what?
the one i used was very recent but still outdated so i need to find a new one
The only significant change in latest versions is the changes to the navmesh. Aside from that you can rely on tutorials from 10 years ago.
the things he was doing i was unable to
like what?
the tutorial i used was from last year
yeah its still happening
made the player's speed a lot more faster though
and it didnt have the issue when going fast
What changes? I thought there was nothing really about navmesh on the roadmap?
he went to window and selected ai but i dont have that and when i got it from the package manager it was missing some of the options he was selecting
the only change was navmesh agent was extracted into a separate package with extra components
idk what that means
oh wait i know navmesh
ye that was the thing that was different
meaning they put the navigation mesh system into its own package
They moved it from being built-in in into a package and made it more component based.
ik but when i got the package it had only agents and areas and on the tutorial he had those two and also bake and object which he was using
Sounds interesting, I’ll take a look
Of course that is the only change they mentioned haha.
Other than that, nothing much will be "outdated"
yes because now they have more options for baking, such as nav surfaces which can bake at aany angle/incline
at this point I think this issue may be a lot harder than I thought...
Previous baking method was limited to only baking on 1 axis
whats baking
At this point I recommend you look up a proper tutorial to see how they implement such movement.
Baking
ye whats that
Not backing
i said baking
like creating the navigation "mesh"
for the agents to walk on
the blue thing
Not when I responded. You edited it
saw that too
cap
so what im getting from this is that the mesh is the path that the ai follows to walk
the AI uses the mesh that was baked, to create a path from point A to B
pathfinding
yeah i've also tried that in youtube many times, my code is like a mix of that many tutorials, because none of them worked the way i expected
No. It is the area it can build a path FROM
Just to clarify. It is not the actual path itself
Yet your code doesn't work at all.😅
oh ok makes sense
yeahh... Im not even sure of what to do anymore man
Start from implementing it as in a tutorial and making sure there are no issues. Then move on to adjusting it to your needs.
delete your player, and follow a tutorial on a player
yes agents on mesh can also be moved directly without paths
@feral bluff i followed a good tutorial from natty gamedev on movement
like first person movement
ye
what were we even talking about in the first place lol
You were implying following tutorials from any Unity that is not "the newest" wasn't useful to learn navmesh / pathfinding
oh ye they changed the ai nav thing
as pointed out the difference is that now you usually bake with something like Navmesh Surface component, or volume ones..tc.
You should be able to adjust to the changes at this point.
ig ill try to still follow the tutorial and improvise
Learn about the thing that changed.
navmesh agents especially are the same exact code to move and assign paths
tutorial is too confusing ill come back to enemies when im more advanced
all these components were "Experimental" earlier so some videos even do have these
ive got a gameobject set up with a kinematic rigidbody however when i run into it ints not moving and i dont know why
Kinematic means it won't respond to forces
what but that makes no sense cause if u hover over it it says controls wether or not the object is affected by physics
so ticking it would mean yes
Incorrect
other way around
so tick for no and blank for yes
Correct
thats terrible
Ok 🤷♂️
It doesn't say select to be controlled by physics
Makes sense to me
Just says it controls whether it is
if i had a tick box and it said wehter or not you want ice cream you would tick for yes would u not?
Well that is not what it says when you hover
" I want this to be not effected by other physics object"
I simply also know what the word means
it syas controls wether physics affects it
Exactly
Fundamental difference in wording there
what no
this controls if OTHER physics objects/forces affect it
so you would tick for yes i want it to be affected
Incorrect analogy. It would say "controls wether you get an icecream"
yeah i know im not disagreeing but for someone who doesnt know the definition the wording is bad
still you would tick for yes
That's why you'd check the manual for more info on this setting.
Doesn't matter. Just google the word kinematic
It has a meaning outside of unity
Unity engine is a professional software. It's not meant to be used out of the bat. You need some learning to do before you can use it efficiently.
🤦♂️ no im saying that the wording is bad for people who are beginners coming into unity
IsKinematic - controls if its affected by physics
this setting makes it controlled or not, so then you find out what does Kinematic do and see if you want it On or Off, simple
And I'm saying that you shouldn't base your engine understanding on a tooltip in the UI as a beginner.
whats complicated about this ?
nothing just a bit misleading as reading that you would assume ticking the box means physics affects the object
I would not assume that. But then I would also never use a tooltip for the decision
I would look at the docs. Get in the habit of that
No, you would assume that toggling it altered whether physics affected it
It doesn't say in what state it would make physics affect the rb, so it is misleading in that way. But you made an assumption that checked == affects. That's the issue.
Luckily kinematic is also a real word
https://gdl.space/vahicugocu.php
I'm getting a null error on the 4th line of this method when I call CreateShapeFromPolygon
The error seems to say that it's looking for a ProbuilderMesh as a parameter, so i tried calling the script differently (second screenshot) but they both give the same null error
the whole code is
https://gdl.space/ogarodalay.cs
both should be valid ways of calling the createpolygon method, but I still don't know why the mesh I declared and assigned a new value to the line before is returning null.
ProBuilderMesh is a MonoBehaviour. you should not be calling the constructor for a monobehaviour, in fact you probably have a warning before this error telling you that
indeed apparently.
does that mean the mesh has to be added as a component?
yes, that is how all MonoBehaviours and components work
does anyone have a good reference to cinemachine 3d?
So far I have created an empty object and placed it on my player and created cinemachine to follow and look at that empty object
now im struggling to calculate player movement relative to the direction the camera is facing
):
^ newbie trying to create a game
there's documentation for cinemachine pinned in #🎥┃cinemachine
but if the issue is just getting the direction the object is facing, that would be its transform.forward
or you can use transform.TransformDirection to convert your input from local space to world space
ty ill look into that
this does work, (forward) tempRigidBodyBullet.AddForce(transform.forward * bulletSpeed, ForceMode.Impulse);
But its going on the blue line, instead of the green.
using System.Collections;
using System.Collections.Generic;
using System.Net;
using UnityEngine;
using static System.Runtime.CompilerServices.RuntimeHelpers;
public class Gravity : MonoBehaviour
{
public Rigidbody2D rb;
private bool canJump;
// jumpTime starts from bigger number and goes to a lower number
// jumpTime always wants to go negative but before it goes negative if it reaches anywhere near zero we want it to stop right there
// and not move anymore, jump will only be available if u wait for these 2 seconds to run out
public float jumpAgainInTwoSec = 2.0f;
public float speed = 0.0f;
void Start()
{
rb = GetComponent<Rigidbody2D>();
checkIfjumpPossible();
}
void Jump()
{
checkIfjumpPossible();
if (canJump && (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.UpArrow)))
{
rb.AddForce(Vector2.up * speed, ForceMode2D.Impulse);
jumpAgainInTwoSec = 0;
jumpAgainInTwoSec += Time.deltaTime;
}
}
// Update is called once per frame
void Update()
{
Jump();
Debug.Log("JumpTime is :" + jumpAgainInTwoSec);
Debug.Log("canJump?:" + canJump);
checkIfjumpPossible();
}
void checkIfjumpPossible()
{
if (jumpAgainInTwoSec == 2.0f)
{
canJump = true;
}
}
}
Rate my code
is there any way I could make this game any better?
whoops you waited 2.01 seconds to jump and now you cannot jump ever again
wdym, it always jumps
no matter what the time is
oh wait, you never even set it to false
so you have several variables that serve absolutely no purpose
oh and can jump infinitely since those variables that serve no actual purpose in this code were really meant to prevent that
isn't that automatically set to false if the condition jumpAgainInTwoSec is not 2.0f then the canJump will be false?
the opposite of true is false right?
how would it be set to false? you only set it to true
so if its not true then what else can it be?
Bools remain the value you set them to until you change it
You set it to true
btw i only set the truthies cause i thought i could save up some lines of codes that way text can be shorter to paste here
and be readable
show me literally anywhere that you set it to false
And it STAYS true until set false (which never happens)
i guess ill have to include a false condition here?
or do !JumpAgainInTwoSec == 2.0 then canJump = false
would that also work?
delcaring only the false case
please for the love of god go learn how code works
to save code space?
ok bro chill, ill include both cases
btw this works too on my game lol
i like my code that way and it works
Never ever do == with floats
ok noted!
I will fix that
Added >=
using System.Collections;
using System.Collections.Generic;
using System.Net;
using UnityEngine;
using static System.Runtime.CompilerServices.RuntimeHelpers;
public class Gravity : MonoBehaviour
{
public Rigidbody2D rb;
private bool canJump;
public float jumpAgainInTwoSec = 2.0f;
public float speed = 0.0f;
void Start()
{
rb = GetComponent<Rigidbody2D>();
checkIfjumpPossible();
}
void Jump()
{
checkIfjumpPossible();
if (canJump && (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.UpArrow)))
{
rb.AddForce(Vector2.up * speed, ForceMode2D.Impulse);
jumpAgainInTwoSec = 0;
jumpAgainInTwoSec += Time.deltaTime;
}
}
// Update is called once per frame
void Update()
{
Jump();
Debug.Log("JumpTime is :" + jumpAgainInTwoSec);
Debug.Log("canJump?:" + canJump);
checkIfjumpPossible();
}
void checkIfjumpPossible()
{
if (jumpAgainInTwoSec >= 2.0f)
{
canJump = true;
}
else
{
canJump = false;
jumpAgainInTwoSec += Time.deltaTime;
}
}
}
Well, that works.
Any recommendations on how to make it shorter or better? I guess
your 2 second jump timer is now more like 0.75 seconds
Naming leaves a lot to be desired. JumpDelay would be better than JumpAgainInTwoSec for example. What if you change it to 1.5 seconds at some point?
that is okay
Would rename the class something more fitting for jumping, rather than gravity'. MovementController or playerJumping.
Oh yeah, you are adding deltaTime in multiple places
noted and fixed, i renamed it to playerJumping
It would be fine if it were done properly, I would not call this fine
Good point, Ill fix that
using System.Collections;
using System.Collections.Generic;
using System.Net;
using UnityEngine;
using static System.Runtime.CompilerServices.RuntimeHelpers;
public class playerJumping : MonoBehaviour
{
public Rigidbody2D rb;
private bool canJump;
public float JumpDelay = 2.0f;
public float speed = 0.0f;
void Start()
{
rb = GetComponent<Rigidbody2D>();
checkIfjumpPossible();
}
void Jump()
{
checkIfjumpPossible();
if (canJump && (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.UpArrow)))
{
rb.AddForce(Vector2.up * speed, ForceMode2D.Impulse);
JumpDelay = 0;
JumpDelay += Time.deltaTime;
}
}
// Update is called once per frame
void Update()
{
Jump();
Debug.Log("JumpTime is :" + JumpDelay);
Debug.Log("canJump?:" + canJump);
checkIfjumpPossible();
}
void checkIfjumpPossible()
{
if (JumpDelay >= 2.0f)
{
canJump = true;
}
else
{
canJump = false;
JumpDelay += Time.deltaTime;
}
}
}
This is now my current code
Any further suggestions are welcome 👌
Fix the deltaTime issue boxfriend brought up
Only add it once
Remove the one closer to the top of course
thats what I was thinking
I removed it
Oh, the issue they meant is that you call checkIfJumpPossible twice actually
Just saw that
Once in jump and once in update
Ok, noted, Ill only call it in Update
and i think Ill remove the JumpDelay completelly because it makes my gameplay kinda shitty
using System.Collections;
using System.Collections.Generic;
using System.Net;
using UnityEngine;
using static System.Runtime.CompilerServices.RuntimeHelpers;
public class playerJumping : MonoBehaviour
{
public Rigidbody2D rb;
public float speed;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Jump()
{
if ((Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.UpArrow)))
{
rb.AddForce(Vector2.up * speed, ForceMode2D.Impulse);
}
}
// Update is called once per frame
void Update()
{
Jump();
}
}
this is now my current code
So just jump no matter what whenever you press jump?
Even in the air?
this is a flappy bird game
Has this bug been addressed? I get the same error when I have something selected in the hierarchy before running the game. It's not hard to work around, but it is annoying
Oh then yeah, a 2 second delay is massive haha
is there something I can do to stop it?
the only problem about this is that the bird gets exponential amount of force and just shoots up in a one-way ticket to space if you get the jump GetKeyDown triggered multiple times in one second it will eventually shoot up adding up all the accumulated force you gave it where I kinda want it to cancel out accumulated jump Added-force in case that happens so that I can have better control of my bird and not have it shoot up to the moon but rather have a more smooth flying and slow release of rigidbody jumpforce, so only when one jumpforce is done is when I wanna add the next one, which is why I added the timer in the first place, I had a big problem with this issue getting way too much jumpower if you press the jump button multiple times it adds up all the speed
Maybe just check the upwards velocity? If you are moving up very fast then don't allow moving up
rb.velocity.y >= someThreshold
ok
maybe like should i make a new method for that?
probably just another condition in your if statement
okay
( I haven't yet added rigidbody 2d to the pipes, or randomized the pipe positions )
I also want to do that later
are you happy with the jump timing?
The pipes should not have rigidbodies
no this is why I made this to show you how its bad when it multiplies the speed when you press jump input multiple times
Not that either
oh it'd just be a collider trigger to lose right?
The bird has a rigidbody
Only one object requires a rigidbody for OnTriggerEnter
is there any way I can take out this playerinput symbol from the screen?
its making it hard to see the actual bird
also the way the order of these layers are stacked up on top of each other it makes it look as if the wing layer is on top of the face of the bird, instead it should be underneath the player gameobject in this 2d perspective
I am using PlayClipAtPoint to play a small sound effect for all the stuff, but if the player (which has the audioListener) moves while the audio is played, it creates this really weird doppler effect that I don't want. Can I play this directly on the AudioListener without considering any position?
Is there something for that?
Thick back flappers.
Add a source to the same object as the listener and play it from that source
Then I would have like all sounds effects attached to the player and need to call a reference to the player wich each object than can produce sound. Isn't that like really convoluted?
Not really. Pretty common
What do you mean "attached to the player" though?
Just make an array or list of clips
I mean that if I want a shot to produce a sound when it ends, it would need to refer to the player object to produce the sound from there
Or use events. But yeah, things need to reference things. That is normal and fine
It's really the only way to do what you're asking either way
Alright, so I am able to create the objects I need to create, I've created the meshes, and I've added a meshrenderer and meshfilter
foreach (Vector3Int move in basicHexMoves)
{
GameObject movePoly = new GameObject("PolyMove");
movePoly.transform.position += boardCoord.CubeToQuad(move);
movePoly.transform.SetParent(transform, false);
MeshRenderer meshRenderer = movePoly.AddComponent<MeshRenderer>();
MeshFilter meshFilter = movePoly.AddComponent<MeshFilter>();
ProBuilderMesh proMesh = movePoly.AddComponent<ProBuilderMesh>();
AppendElements.CreateShapeFromPolygon(proMesh, uIPoints, 0.2f, false);
}
I just don't know how to actually connect them to get the visible object in my scene
Sure but having to call an event for something so common is a bit... why I cannot configure AudioSource.PlaySoundAtPoint() as I would with a normal AudioSource?
I cannot even attach it to a mixer
Because PlaySoundAtPoint creates a gameobject at a point with a sound source, plays the sound, then destroys it.
It is called AtPoint, because that is its reason for existing. Making a sound at a specific point.
I don't understand the reticence to just do it the normal way, but yeah, I have no idea how you could do it with PlaySoundAtPoint.
An alternative is to have a soundsource object that you child to the player and move around as needed
People often pool these sound objects and activate then as needed
I am just feeling that calling a sound at a point without even be able to place it on an audio mixer or configuring how do you want distance to affect the sound is superlimited
Cause I actually want it to be somewhat affected by distance but not this much
It is super limited. You don't really want to use PlayClipAtPoint except for its extremely limited use case. And it is not great performance wise
Anything outside that limit should be an actual object with a sound source
I once made my own implementation of PlaySoundAtPoint that uses object pooling and the ability to set which audio mixer its on
ProBuilder creates it's own MeshFilter, but the MeshRenderer isn't finding it:
protected void InstantiateMovePoly()
{
for (int i = 0; i < 6; i++)
{
float angle = Mathf.PI / i;
uIPoints.Add(new Vector3(Mathf.Cos(angle), 0f, Mathf.Sin(angle)));
}
foreach (Vector3Int move in basicHexMoves)
{
GameObject movePoly = new GameObject("PolyMove");
movePoly.transform.position += boardCoord.CubeToQuad(move);
movePoly.transform.SetParent(transform, false);
ProBuilderMesh proMesh = movePoly.AddComponent<ProBuilderMesh>();
MeshRenderer meshRenderer = movePoly.AddComponent<MeshRenderer>();
AppendElements.CreateShapeFromPolygon(proMesh, uIPoints, 0.2f, false);
}
}
Thank you is is exactly like i want , now I just have to alter the speed to make it look nice , I'll still peek at the tarodev video tomorrow. (Sorry didn't get that message before i left for work. so late reply)
Any specific reason the curve does that with no points in the middle?
The slope handles can be adjusted
I can't remember exactly but if you look up splines , basically the handle defines the angle at the point it's attached to, and the length is the strength of the slope so that angle reashes further. The middle of the curve is like as smooth as mathematically possible
freya holmer has a good video on it: https://www.youtube.com/watch?v=jvPPXbo87ds
why are splines? well my god I have good news for you, here's why splines!
if you like my work, please consider supporting me 💖
https://www.patreon.com/acegikmo
This project grew much larger in scope than I had originally intended, and burnout made it impossible for me to do more with it. It was already getting incredibly unwieldy, so I apolog...
A Bézier curve ( BEH-zee-ay) is a parametric curve used in computer graphics and related fields. A set of discrete "control points" defines a smooth, continuous curve by means of a formula. Usually the curve is intended to approximate a real-world shape that otherwise has no mathematical representation or whose representation is unknown or too c...
In geometric modelling and in computer graphics, a composite Bézier curve or Bézier spline is a spline made out of Bézier curves that is at least C0{\displaystyle C^{0}} continuous. In other words, a composite Bézier curve is a series of Bézier curves joined end to end where the last point of one curve coincides with the starting point of the ne...
Anyways I gotta go to sleep but if you guys happen to know what I'm messing up here feel free to ping me so I'll see it
pleas
Could anyone link me a guide to temporarily disable a script?
.enabled = false
It will only disable unity methods though. Like Update
Would something like
private void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Powerup"))
{
{ScriptName}.enabled = false
}
}
}
work? (im new to coding)
Would you care to elaborate?
Anything in the inspector I should look out for?
ScriptName
I changed it to the script name I want to disable, but it's giving me errors now.
errors?
object reference
so you didn't assign it?
when I do public {ScriptName} script; at the top, it goes away but has me choose from limited game objects
or is it only game objects that have a script applied?
or the certain script that i want to be disabled applied to that certain game object?
Uri u here?
it has to be presen yes
So will that only disable that exact game object
with the script attached to it?
cause I want to disable more
for like 3 seconds
(over 100 game objects to be specific)
what are u trying to do
disable my kill player script
kinda like an "invincibility" thing for a few seconds
my friends keep telling me to add it and i said "yeah okay ill try"
instead of disabling the other objects why don't you disable the damage or whatever on player itself..
so disable that part
"oart"?
oh alr
the thing is
it's just when it comes into collision it reloads the scene
To get the OnTriggerEnter2D message:
You need a rigidbody2d on one of the two objects
Collider2d on both objects, with one set to isTrigger
You need the other object to be tagged Powerup
1 done, 2 done, 3 done
would i assign the script to the player or the game object itself?
(the game object thats supposed to disable the killplayer script)
The script is evaluating whether or not the other is a powerup so I'd guess you'd put this on whoever is running into the powerups
i put it on the player
and it doesnt rlly disable the script
Can you post the exact code?
so skip that part when you have powerrup
The !code posting guidelines:
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
both KillPlayer and Powerup script
this is backwards
What is the killplayer script? Who has it attached?
over 100 game objects 😭
the pictures?
i mean the Player should be checking if it hits KillPlayer script
but skip it if you got powerup
i came back to coding for 1 more attempt 2 months ago
so i dont know much
anyways, ill be back later
lol
not much of a code issue, just flip the logic, it makes more sense inside player script to check if hits trigger with that KillPlayer script
eluded me for much longer than I want to admit 😅
break how
let me send video rq
thats how
but i need time.deltaTime for it to gradually go up to the aimed in position
it's not deltaTime that broke it
wym
you did transform.position instead of gun.transform.position
when i multiply by it it breaks.
that's a side effect of this #💻┃code-beginner message
huh
or rather - it's just making that mistake visible
string query = "SELECT * FROM `ifi-1-prod`.items WHERE playernumber = @playernumber AND itemid IN (@itemid1, @itemid2);"; MySqlCommand cmd = new MySqlCommand(query, connection); cmd.Parameters.AddWithValue("@playernumber", playerNumber); cmd.Parameters.AddWithValue("@itemid1", scrollItemId); cmd.Parameters.AddWithValue("@itemid2", equipmentItemId);
Is there anything wrong with the way I'm creating this database call?
Chat GPT is saying something about protecting against sql injection, but I'm doing that already not?
It's suggesting I do something like this:
string query = "SELECT * FROM `ifi-1-prod`.items WHERE playernumber = @playernumber AND itemid IN ({0}, {1});"; // Dynamically formatting the query with placeholders for item IDs query = string.Format(query, "@id1", "@id2");
Is there any difference?
save your code
the only other way that'd happen would be if aimHere is rapidly moving
i might have other ambigious references
Make triple sure unity picked up the changes
could that mess it up
not sure what you mean by that
other transform.position instead of gun.transform.position
they are not in any way related to moving the gun what so ever
er
It's best if you just understand the difference between those two things
and use the correct one in each case
that is legitimately the only area where i move the gun
the aimHere empty is moving with my camera
could you suggest any work arounds??
if its child maybe u want localPosition?
The aimed in empty is a child of the player capsule
is that what you meant?
doesnt seem to work...
Which object is this script on?
the gun script is on the gun
then I have a gamObject variable that allows me to access aimedin's transform
i know 100% it is related to delta time
So.. does that mean the gun script has a separate reference to ITSELF called gun?
when testing it
That's VERY odd
yea i started the script a long time ago before i knew what i was doing
but that means that it shouldn't matter if i just do transform.position right?
yes it shouldn't
but like
be consistent
use the same thing everywhere
otherwise it's ????? when reading the code
ok
anyway my guess is there's some other part of the script or something else entirely moving the gun
perhaps an Animator?
have you guys ever tried something similar to what im doing and had this sort of problem?
What you're describing doesn't make much sense unless this code is fighting some other code or component to move the object
deltaTime would then cause this because it means rather than instantly moving you move gradually which means you start to intermittently lose that fight to move the object
when I aim out
I dont
and when I tested
hipfire or neutral stance
is fine
but aiming in sinks out of the map
and it goes back to neutral stance when un aimed
ill look
would disabling a collider do anything
cuz I do do that
none of my otherscripts interact with the gun's position at all
why does it have a Rigidbody 😮
ok but surely when you're holding it... it should be at least set to kinematic
otherwise you'll be fighting that thing for positioning the object all the time
yea thats probably it lemme try to fix rn
I don't get why a gun needs a rigidbody component
to drop it
Yeah but you don't need it when you hold it
yup
I didnt know it would impact it at all
I only knew I had to disable the collider
Picking it up, remove it from the scene and just enable it under the player
because otherwise it would fling me when pushed into objects
Fair enough
that doesn't look good
But it doesn't mess with the perception of the weapon if you'd decide to use camera stacking
I dont use camera stacking at all. I use Renderer feature
camera stacking is resource intensive
If you use the same game object with the same layer, the difference in fov will be visible and ugly when it's on the floor
I correct that inside the Renderer feature
You can instead just use one "object" on the floor that acts as a pickup, and another one that actually functions as the weapon
That way they can separate layers
Makes fixing the camera clipping much easier
Fair enough
that has nothing to do with why OP put rigidbody on it
But it does still have some benefits, such as different fovs for the viewmodel
I understand that, but I just found the pickup system to be a little peculiar
again thats easily corrected in renderer feature
Nothing wrong with it
they mentioned for dropping looking good, not so much for pickup. Pickup was not mentioned
What? What are you talking about?
Ah my apologies then
Makes sense
I'm unfamiliar with it, is it something new or?
renderer feature is part of URP so you can add things like decals
or outlines
Yeah I just searched it up, SRP exclusive
camera stack sucks because shadows also don't affect the viewmodel
They do in URP
no they don't
if the camera is only rendering the weapon, where do you think the shadows from world come
I use camera stacking and the lighting works okay
I never said lighting
the outside world will not affect view model with their shadows
hence why I said its another drawback of camera stacking
I mean my laptop sucks so it's probably a good idea I stray away from it too
I noticed considerable performance drops
yeah having two cameras is expensive
I stick to srp only
Why?
birp is pretty much legacy
its barebones, SRP has too many good features that birp dont have
Yeah but the assets are lacking
There are like 4x more assets for BiRP
The post processing can be made up for quite easily
🤷♂️ i barely use any external assets
Fair enough
But for things like PSX-style games I haven't found any easy to use assets for stuff like texture warping for SRP
wdym decals for texture wrapping ?
Hey guys there is a weird bobbing when I jump around, any way to reduce that?
You just said I can use the renderer feature for PSX-style graphics
Show a video
alr
like this?
Texture warping is a graphics byproduct of old computers when they didn't calculate movement with floating point numbers, causing the textures to be out of place or jiggly
That isn't you shooting the gun?
I know what texture warp is, whats that got to do with decals
when i shoot rn its does no sort of animation
Idk you mentioned something about renderers and decals I got confused
I said something like decals is built in, rather than a shader that barely works like i had to do in Birp
"Projector" conponent dude
Is the gun's interpolation set to default or interpolate?
In the rigidbody
i figured out why, my character is moving faster than the speed that my gun is "moving toward the position", speeding that up a ton fixes it, but makes the aim in look janky
its garbage in comparison lol
also its Birp only
Check the interpolation of the gun
In the rigidbody
When you constantly move the gun next to the player, it might be jittery
you mean make it interpolate or extrapolate or none?
making it interpolate seems to worsen the problem
Make it interpolate
How so?
well it makes the overall speed slower, meaning that what I had it at before seems slower than before, thus worsening the problem
Also, I'm a bit late to the thread, why isn't the weapon under the player parent game object once you hold it?
i am unaware of the advantages of doing such things
hence why i am asking in coding beginner
I feel like constantly teleporting it next to the player is unnecessary
When it's under the player parent game object, it always follows the player's position and orientation
No need to modify the script to have the gun always teleporting to the relevant position
Especially if you move quickly, as you mentioned
interpolate did reduce the problem btw, i just upped the speed so it goes about as fast as before
Btw @rich adder what's wrong with the method I suggested? Pick it up, remove the pickup object from the scene, enable the actual shooting object under the player (a draw animation can help with the smoothness) and if you drop it, make a new pickup object with a rigidbody in the relevant position
The problem is if you exceed the speed
Then it will need to catch up to you again
How does OnTriggerEnter2D work?, cuz mine not working
When a 2D object enters the trigger it calls the code, just once
What's not working?
!vs
If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
For the people that have purchased/used the A* Pathfinding asset (arongranberg):
How do you restrict the AI to only move in 4 directions towards the target? I have it set up for an Enemy aggro AI, but it's allowing the enemy to move diagonally, which isn't something I want since I've restricted player movement to 4-directional only
using System.Collections;
using System.Collections.Generic;
using System.Net;
using UnityEngine;
using UnityEngine.UIElements;
using static System.Runtime.CompilerServices.RuntimeHelpers;
public class playerJumping : MonoBehaviour
{
public Rigidbody2D rb;
public float speed;
private bool isGoingUpwards;
// Minimum vertical velocity thresold to consider movement. When we have this player is basically stationary in the middle
public float velocityThreshold = 0f;
public float verticalVelocity;
public float RDV; //Rotate Downwards Velocity
//public float RUV; //Rotate Upwards Velocity ( faster )
void Start()
{
rb = GetComponent<Rigidbody2D>();
Quaternion localRotation = gameObject.transform.localRotation;
// Access individual local rotation values (Euler Angles)
}
void Jump()
{
float verticalVelocity = rb.velocity.y;
RDV = verticalVelocity / 10;
//RUV = verticalVelocity / 5;
if (verticalVelocity > velocityThreshold)
{
isGoingUpwards = true;
}
if (verticalVelocity < velocityThreshold)
{
isGoingUpwards = false;
if (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.UpArrow) && (isGoingUpwards == false))
{
rb.AddForce(Vector2.up * speed, ForceMode2D.Impulse);
transform.Rotate(new Vector3(0, 0, -RDV));
}
transform.Rotate(new Vector3(0, 0, RDV));
}
}
// Update is called once per frame
void Update()
{
Jump();
}
}
Hiya, it's me again (seems like I have a problem every day 😅 )
Anyway, I have a inventory system on scene1, which works perfectly fine and can pick up item, select item in the ui. The problem is when I just copy and paste the entire UI to scene2 it seems to not work, I can still pick up items and open up the menu, but I no longer can select the items I've picked up. Is it not possible to just copy and paste an entire UI over a scene or is there a better way of doing it?
do you have event system in the secene2?
and yes there is a better way
use Prefabs
wait prefab as in these blue thingy?
Hello, anyone who has worked with Oculus lipsync here?
Or is there any way to get characters compatible with Oculus lipsync by default?
can you see protected variables in the editor?
Why is the plus missing?
[SerializeField] and yea
why do you post such thing in code related channel?
Tbh
so can u explain the difference
between public and protected
and private
google can xplain it to you
I don't know anymore
in 2minutes
Yeah this channel is not exactly for these type of questions
and its visible in the editor
just use tool called google
real
its pretty much summarized here
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/accessibility-levels
using System.Collections;
using System.Collections.Generic;
using System.Net;
using UnityEngine;
using UnityEngine.UIElements;
using static System.Runtime.CompilerServices.RuntimeHelpers;
public class playerJumping : MonoBehaviour
{
public Rigidbody2D rb;
public float speed;
private bool isGoingUpwards;
// Minimum vertical velocity thresold to consider movement. When we have this player is basically stationary in the middle
public float velocityThreshold = 0f;
public float verticalVelocity;
public float RDV; //Rotate Downwards Velocity
public float RUV; //Rotate Upwards Velocity
void Start()
{
rb = GetComponent<Rigidbody2D>();
Quaternion localRotation = gameObject.transform.localRotation;
// Access individual local rotation values (Euler Angles)
}
void Jump()
{
float verticalVelocity = rb.velocity.y;
RDV = verticalVelocity / 10;
RUV = verticalVelocity / 10;
if (verticalVelocity > velocityThreshold)
{
isGoingUpwards = true;
positiveSpin_LookUP();
}
if (verticalVelocity < velocityThreshold)
{
isGoingUpwards = false;
negativeSpin_lookDownwards();
if (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.UpArrow) && (isGoingUpwards == false))
{
rb.AddForce(Vector2.up * speed, ForceMode2D.Impulse);
}
}
}
// Update is called once per frame
void Update()
{
Jump();
}
void positiveSpin_LookUP()
{
transform.Rotate(new Vector3(0, 0, -RDV));
}
void negativeSpin_lookDownwards()
{
transform.Rotate(new Vector3(0, 0, +RUV));
}
}
why is my shit only spinning towards one direction?
chat gpt code?
what do you mean?
no it's not
I literally changed this a thousand times to get here
Are positiveSpin_LookUP and negativeSpin_lookDownwards both being called?
how did you make sure they are?
Did you actually confirm this by logging a message or this an assumption?
That doesn't matter
crazy you need to tell people to check those things
That's the whole point of debugging, pinpoint the actual issue
wdym?
So let's see if your code is actually called in general
@rare basin
You can test this by logging inside the method or logging isGoingUpwards
im doing it rn
They are all being called
lol
I told you this is not the problem because I can literally see the player ball spinning towards only one direction
the problem isnt about the methods not getting called but the way transform.Rotate(new Vector3(0, 0, -RDV)); works
transform.Rotate(new Vector3(0, 0, -RDV));
I changed this a thousand times
nothing works
I googled it
asked chatgpt
How would you know? Perhaps one one method was called which causes the constant rotation
asked anyone
debug -RDV
I did
what's the value
I can literally see the value being changed in the transform inspctor
also I can literally see the value here
Write a debug log statement and debug both -RDV and +RUV. Place this log after you created the variables
ohhh I see what you're getting at
No conclusion, check this out
Vetical Velocity is positive when it's positive
and negative when it's negative
So what did you do wrong?
and the water here is made out of water
You manually set the rotation to a positive/negative value, that's the issue
I think its in the RUV
negative and positive
they're the same thing pretty much only one should be positive
and thats the issue im getting
it's never positive, it always thinks we're falling
You can just use a single variable
yep, tried that too
You don't have to set it negative yourself because it already is
ohhhh
shit
You might have to switch it around depending on if the rotation is inverted but other than that you don't have to control it
how did i not think of this earlier
That's the thing I'm trying to hint at
yeeeeee, thank you
imma try that now
so basically I only used one var
using System.Collections;
using System.Collections.Generic;
using System.Net;
using UnityEngine;
using UnityEngine.UIElements;
using static System.Runtime.CompilerServices.RuntimeHelpers;
public class playerJumping : MonoBehaviour
{
public Rigidbody2D rb;
public float speed;
private bool isGoingUpwards;
// Minimum vertical velocity thresold to consider movement. When we have this player is basically stationary in the middle
public float velocityThreshold = 0f;
public float verticalVelocity;
//public float RDV; //Rotate Downwards Velocity
//public float RUV; //Rotate Upwards Velocity
void Start()
{
rb = GetComponent<Rigidbody2D>();
Quaternion localRotation = gameObject.transform.localRotation;
// Access individual local rotation values (Euler Angles)
}
void Jump()
{
float verticalVelocity = rb.velocity.y;
Debug.Log("Vertical Velocity: " + verticalVelocity);
if (verticalVelocity > velocityThreshold)
{
isGoingUpwards = true;
positiveSpin_LookUP();
}
if (verticalVelocity < velocityThreshold)
{
isGoingUpwards = false;
negativeSpin_lookDownwards();
if (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.UpArrow) && (isGoingUpwards == false))
{
rb.AddForce(Vector2.up * speed, ForceMode2D.Impulse);
}
}
}
// Update is called once per frame
void Update()
{
Jump();
}
void positiveSpin_LookUP()
{
transform.Rotate(new Vector3(0, 0, verticalVelocity));
//Debug.Log("Look up is called");
//Debug.Log("Here's negative RDV: "+ -RDV);
}
void negativeSpin_lookDownwards()
{
transform.Rotate(new Vector3(0, 0, verticalVelocity));
//Debug.Log("Look down is called");
//Debug.Log("Here's positive RUV: " + +RUV);
}
}
Pretty much
You might still want to divide/multiply the velocity to have better rotation
It's not exactly a big number
okey does someone know why my game is fd, I can run it without any problems on my pc but when I build and run it on my laptop instead the movment gets messed up big time, like I get suuuper speed and the camera glitches
I've tried changing the code n stuff but nothing works
Changing the code n stuff sounds like you were just guessing. What debugging steps have you taken? Surely some value along the way isnt correct, maybe you are using magic numbers somewhere or incorrect use of deltatime
yeah I have no clue how deltatime works, I did look into it a but bc it seems like that should be the problem
found a forum abt the same thing
and they were talking about deltatime
but I have no clue how that works
and that forum was like 14 years old
Cant even send my code in chat it is too long aperently
If speed is different depending on device/ framerate you are very likely missing some deltaTime multiplication
If you for example add speed in update, it will happen more often on a higher framerate > faster
On a slower device update gets called less often -> less speed
hey peeps! is it possible to Use unitys tree editor via a script? cant seem to find anything on the docs? looking to call it to create random trees in real time?
im struggling with my inventory system. Im using prefabs to create the object when the player drops the item and im working on the pickup() now.
public void PickUpItem(GameObject prefab)
{
//AddToInventory(prefab); not working currently as the function requires a GearDefinition instead of GameObject
Destroy(prefab);
}
public void PickUpItem(GearDefinition prefab)
{
AddToInventory(prefab);
Destroy(prefab);
}
//ERROR FOR PICKUPITEM(GEARDEFINITION): ArgumentException: GetComponent requires that the requested component 'GearDefinition' derives from MonoBehaviour or Component or is an interface.
UnityEngine.GameObject.GetComponent[T] () (at <6c9b376c3fca40b787e8c1a2133bf243>:0)
InputManager.OnCollisionEnter2D (UnityEngine.Collision2D collision) (at Assets/PlayerScripts/InputManager.cs:156)
When I try to add each asset item i created via the menu I created, (create asset menu... etc), into the prefab of the SampleScene, it doesnt give me the red circle saying I cant add it to that gameobject, however it doesnt get added. When I try to add it in the project window itself of the prefab, I get that red circle meaning I cant add it. Basically Im not sure how to connect between the gameobject prefab and the gear definition the inventory functions require. Why is monobehaviour necessary as the error suggests ? I need these items to be inherited from all the definitions I set for it to work.
also, not sure if this is considered #💻┃code-beginner or should be in general or advanced, but lmk 🙂
show the declaration of GearDefinition, i think it is not child class of monbehaviour nor component
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(menuName = "Items/Gear")]
public class GearDefinition : ItemDefinition
{
/*
* https://forum.unity.com/threads/virtual-and-override-functions.314853/
*/
public virtual void OnEquip(Inventory target)
{
Debug.Log("Equipping item: " + itemName);
}
public virtual void UnEquip(Inventory target)
{
Debug.Log("UNequipping item: " + itemName);
}
}
oops lol
ah, is this scriptable object?
Can someone help me turn the currency Variable in to a string. ```using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class gorillaWorks : MonoBehaviour
{
[Header("Currency")]
public TextMeshProUGUI currency;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
not turn it into string, access it .text field to get the display text
currency.text
thanks.
also probably should not be using TextMeshProUGUI
TMP_Text
ohh
could u please expand. So in my inventory script, I should have a serialize field of like "item im currently trying to pick up" that is of GearDefinition, and apply THAT to the PickUp() ?
im not trying to drag all equipable items as a reference through serialize fields, trying more to do it programmatically, so im not understanding the serialize field part
you can only do this in a method
when you pick up a prefab on ground then get the scriptable object associated with it, and store it into your own inventory? i dont know how you write your inventory code
I don't know whats happening or how the error is appearing?
this code is correct, you have just put it in the wrong place. Move it into the Start method
OHHH
ok nvm, could u just be more specific? Reference "it"; gear definition, prefab, something else ?
prefab references the scriptable object
via serializefield? So I should add a script to each prefab that inherits from monobehavior, have a serializefield for the gear definition, then add each definition to each prefab item via that serializefield, am I understanding correctly ?
yes, since your gear definition is not component and you have to reference it (scriptable object) through serialize field
perfect, ty that makes sense
Yo I need help cause its saying I need a comma cause of syntax error?
money = 100
configure your ide
it is configured
it is not
see?
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
not related to have your ide configured
please configure it, it is required in order to get help here #📖┃code-of-conduct
irs configured
no, it is not...
then how does it say this
that's not related to have configured ide
its configured
your ide is not underlining errors and is not autocompleting code
wait
the error went away when i configured it
see
its configured
How do I convert Quaternion rotation to Vector3 direction? (not euler angle)
[I thought it was](#💻┃code-beginner message) Vector3.forward*quaternionRotation
but the compiler said it can't do that.
hmm perhaps I was making stupid mistake, but I don't know what it is.
you cannot multiply Vector with Quaternion types
It's the other way around. targetRot * Vector3.forward.
2x4 is the same as 4x2 lol
it doesnt matter
wow it works!!
whaaaaaaaaaatttttt..... howww...... maybe I should not sleep during math class.
thank you.
In this case, the multiplication is non-commutative.
huh, interesting
It depends on whether the type has defined what behavior multiplication does on it with another type
Seems like one way it exists but not the other way
Which indeed is confusing but I guess there is a reason for it
Matrix multiplication is non-commutative, vector * quaternion would have a different result (which would be even more confusing.) Theoretically they could have ignored "proper" maths and just swap the operands behind the scenes but who knows
Vector3 * Vector3 should return a quaternion.
No, why would multiplying 2 Vectors return a Quaternion?
Following the distributing property. And the properties of i, j and k.
What do you mean?
Quaternion is complicated shit but I might get this wrong.
Well, 2 Vector3s cannot be multiplied, as there is no operator for it
The 2 overloads for the * operator include (Vector3, float) and (float, Vector3)
There's actually a pretty good video that shows how you multiply Vector3 and end up with a quaternion.
Letting the x, y, z components be the i, j, k.
ijk = 1
ij = k
jk = I
ik = j
ii = jj = kk = -1 (I think)
Yeah I got these wrong pretty sure.
Just imagine a vector set be:
ai + bj + ck
And a, b, and c variables.
After simplyfing, you end up with Hamilton product which is what you also use with quaternion multiplication.
https://youtu.be/htYh-Tq7ZBI?si=HGAPKyl_ZrBRF__1
Title is odd, "Why can't you multiply vectors" then proceeds how to multiply vectors. I found this helpful to get a basic idea on what quaternion is.
..or can you? A deceptively simple question with a complex answer – come join a mathematical journey into madness and wonder, in search of answers that might just give you a new perspective on the mathematical constructs we use in our games
Recorded at Dutch Game Day 2023, October 4th
Timestamps:
00:00 Intro
04:34 Talk Start
05:17 Anatomy of a...
Hi. I decided to add dictionaries to my script and looked at what they are and how to add them on the Internet. I did the same thing, but nothing works. What's wrong?
I see, I have no idea about it, but you may be able to implement it
I was simply referring to Unity not having a built-in method to multiplicate Vectors, as there's no operator for it
Read the 2 similar errors you're getting. You're not supposed to call the methods, such as Add, in your case, directly inside of the class
I have a button that closes the dropdown menu. The dropdown chooses images, gameobjects to be loaded. I want the gameobjects to be loaded when the dropdown menu is closed. (it is not loading - what should I do)
Oh, make them higher than the main class. Thanks
No, not higher. Put them in the method inside of your class.
I get it now. That's how it seems:
you can initialize the dictioanry when declaring the variable
Yes, that's right. You can also initialize the Dictionary with the items without needing to add them via the method.
Dictionary<int, string> dict = new Dictionary<int, string>()
{
{ 1, "foo" },
{ 2, "bar" }
};
Additionally, you may also want to simplify the new()
Dictionary<int, string> dict = new() { } ...
almost like you did
or you can just use serialized dictionaries, so they would be visible in the inspector
this is Dictionary<enum, Vector2> for exmaple
Thank you very much. Now I understand )
I want it to run that code in the ground collision check only if the child named GroundCollider touches the ground and not if the other (larger) collider touchesd it, what am i doing wrong here?
Also consider using a List if you're simply going to use the indexes as the keys, as shown in the image
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
full code: https://gdl.space/ifesiyajay.cs
That's a thing now or are you just using an external package?
Consider calling the OnTriggerEnter2D method directly on the child
you need to make your own serialized dictioanry
or use some editor extension assets like Odin Inspector
You cannot serialize a dictionary directly. This may be possible creating a custom Editor
which is very easy with plenty of tutorials online
I haven't said it's hard 🤫
serialized dictionaries are life changers for me 😄
making the code architecture so much easier to maintain
Yes, you can also make a dictionary serializable by creating a custom Attribute
Nah, it's a massive hassle to manually space out fields.
The out of box methods makes it easy to work with with simple structures or something that appears when something is true or smth.
you can use GenericDictionary from github
it's free and with CC0 license
What do you mean with loading? The gameobject does not exist?
That's cool.
So then make it exist, the code you shared doesn't show what would make the game object
i would rather not have to create 2 extra scripts for this simple collision, any work arounds?
I think events exists that you can subscribed to. Not sure tho. 
The top left button is a button that toggles visibillity of the drop down menu (top right button). Inside the top right button, there are three options: the green image, the red image, the yellow image (originally set as false - where you cant see them). I want the user to choose an option and then click the button on the top left, which will then display the option that they have chosen
You can check that by iterating the images again and then checking which one is active
But perhaps you want to define a variable that represents an index, and set the image under that index as active. Then you can just check using the index
Yes, you can use the Collider2D.GetContacts method, which returns the number of contacts placed in the array.
You can create an array with 2 items, as this is the amount of children your object has, but the better option will be to create an array with the childCount items.
Iterate through every contact and find the desired one by e.g. checking its tag.
private void OnTriggerEnter2D(Collider2D collision)
{
var contacts = new ContactPoint2D[transform.childCount];
collision.GetContacts(contacts);
foreach (ContactPoint2D contact in contacts)
{
if (contact.collider.CompareTag("myCollider"))
// ...
}
}
I believe I am doing that
There are none
Real. That's sad.
Okay, I'm still dumb.: How do I use TMP_Text for a dictionary?
You cannot
Sadly. Thanks
I think it has something to do with buttonChecker.activeInHierarchy == false. But I am unsure why and how to fix this problem
what are you trying to do?
I'll just do it differently and that's it.
aight 🤷♂️
The TMP_Text is abstract and thus cannot be created.
Referencing the TMP_Texts above also won't work, because of the field initializer not being able to reference a non-static field.
You'll have to either set it directly in the Inspector or add via the method, as you've done previously
Why would you do this
TMP does not have any implicit conversion from strings so I think you're confused
you can use whatever you want as dict key if them have implemented GetHashCode and Equal, but the unity object hash code is unique that means you need the exact instance to get back the value.
If you want to bind a specific TMP instance to write text to then you should find the component and not whatever this is
The code is not accurate. You're activating the image if it's not active in the Hierarchy, but activeInHierarchy is not the same as activeSelf
activeSelfreturnstrueif theGameObjectisactive, regardless of any of its parents beingactiveor not. This means, theGameObjectmay beactiveSelfwithout being visible in theSceneactiveInHierarchyreturnstrueif neither of theGameObject's parents areactive. IfactiveInHierarchyisfalse, there's no way for you to see theGameObject
The code also deactivates the GameObject if it's already deactivated
How can we play this up so it's not used in the update?
Someone that can tell me if there's a prettier way to do this? the red ball is supposed to be a weapon that shoots randomly 1 of the 3 shapes. I want to display that shape above it in a frame (the red square). I thought maybe give every type of bullet a tag of its type/shape, and then compare its tag with bunch of if statements. but idk i really like this approach.. looks ugly idk.
public void displayTypeOfBullet(GameObject bullet)
{
if (bullet.CompareTag("CubeBullet"))
{
hideTypeOfBullet()
typesOfBullets[0].SetActive(true);
} else if (bullet.CompareTag("CapsuleBullet"))
{
hideTypeOfBullet()
typesOfBullets[1].SetActive(true);
} else if (bullet.CompareTag("CylBullet"))
{
hideTypeOfBullet()
typesOfBullets[2].SetActive(true);
}
}
public void hideTypeOfBullet()
{
for ( int i = 0; i < typesOfBullets.Length; i++)
{
typesOfBullets[i].SetActive(false);
}
}
save it as a Food in the first place rather than a GameObject
put a script on the bullet that has some kind of BulletType field on it
make a Dictionary<BulletType, GameObject> to note which type correspnds to which thing
then just look it up in the dictionary
no work
wdym "no work"?
Why are you trying to get the component from your OWN GameObject here?
In the first place, it looks like the whole first if statement could be moved outside of Update. There's no need to constantly check inHandItem, just do it once when changing the value, and in Awake() if there is a value attached in the inspector
You should probably have a general Item component on the object that has things like public bool IsUsable public bool IsDroppable etc.
you shouldn't be checking individual item types here
I need to make when I pick up food it shows its panel, if another item it shows another panel
First you called GetComponent on inHandItem, now you changed it and call it without it, what did you expect would happen?
my recommendation: #💻┃code-beginner message
btw inventory items are kind of the classic use case where people try to use inheritance and it goes wrong
because inheritance isn't really equipped for that
Fair I could use a map like that, but how would i know what type it is? Do I do it manually? or is there a command gameobject.getType of sum sort? Do I manually put a type of it in maybe in the map as a string?
As I said
in the first sentence
put a script on the bullet that has some kind of BulletType field on it
I have panels with information on what I can do with an item. Food has its own panel, items have their own.
Because of this I made such a check, but it's expensive in the update
I don't understand why you need it in Update
just puit it in the code when you pick the item up
Add to this interface:
public bool IsUsable { get; }```
and cs public bool IsDroppable { get; }
that will solve your problem
yes
continue implementing it
Do you understand how interfaces work? You need to now implement those properties on the class.
you can, why not?
Food?
especially with serialized dictionaries, you definitely can
or in the interface?
IUsable
the class implements the interface
so it has to implement all the things in the interface
finish doing so
okay ty
My bullet goes fast slow fast slow, how can I fix it?
presumably fix your faulty code
Without seeing the code, it's hard to say any more than that
I copied the same code that I used in another project (which worked fine) so I don’t know why it is not working now.
Ama send it
it's probably faulty in that project too. Likely an improper use of Time.deltaTime
i need some help trying to get this courite to work but it does not like the void
but my function seems to throw a error if i remove the void
coroutines need to use IEnumerator as the return type
this is like rule #1 of coroutines
