#💻┃code-beginner
1 messages · Page 235 of 1
Open Sample Scene
thank you
how can i invert this 180 degrees? float yTargetRot = climbingWall.transform.rotation.eulerAngles.y;
if i add a - it doesnt work properly
lmao
yeah it works
thanks
also is there any way to make smoothdamp run at the same speed regardless of the fps?
because there is a masive difference to the point where it breaks the game
How can I implement acceleration without using AddForce. I want a custom acceleration amount. Here is my code currently: ```cs
void FixedUpdate()
{
Move();
}
void Move()
{
Vector3 desiredVelocity = transform.TransformDirection(moveInput.x, 0, moveInput.y) * speed;
rb.velocity = desiredVelocity;
rb.velocity = new Vector3(Mathf.Clamp(rb.velocity.x, -speed, speed), rb.velocity.y, Mathf.Clamp(rb.velocity.z, -speed, speed));
}```
As you can see I've already clamped the velocity to the speed.
increase velocity over time instead of just assigning it
How to I decrease it afterwards?
the same way you increase it
also that's honestly a pretty terrible way to clamp the velocity. just clamp the magnitude of the desiredVelocity vector before applying the Y velocity
is there a good gun tutorial
So when would I decrease it? because if I do cs rb.velocity += acceleration; rb.velocity -= acceleration;the player wouldnt move
just use Mathf.MoveTowards to move the current velocity towards the desired velocity
then when there's no input the desired velocity will be 0,0,0
just don't include the Y velocity in that calculation if you want normal gravity
like this? ```cs
void FixedUpdate()
{
Move();
}
void Move()
{
Vector3 velocity = rb.velocity;
Vector3 inputVelocity = transform.TransformDirection(moveInput.x, 0, moveInput.y) * speed;
velocity.x = Mathf.MoveTowards(velocity.x, inputVelocity.x, speed / acceleration);
velocity.z = Mathf.MoveTowards(velocity.z, inputVelocity.z, speed / acceleration);
rb.velocity = velocity;
}```
sorry, Vector3.MoveTowards instead of doing each axis individually
or you could try it like that if you'd like and see if it works 🤷♂️
Both seem to work well, but using Vector3.MoveTowards gravity is very slow.
This is what I did: ```cs
void FixedUpdate()
{
Move();
}
void Move()
{
Vector3 inputVelocity = transform.TransformDirection(moveInput.x, 0, moveInput.y) * speed;
rb.velocity = Vector3.MoveTowards(rb.velocity, inputVelocity, baseSpeed / acceleration);
}```
remember how i said not to include the Y axis in your MoveTowards calculation?
How can I use Vector3.MoveTowards while not including the Y axis?
does anyone know how to access Wwise using scripts?
i just set up better movement and when i press play i just get flung
how do i fix that
Doesn't sound better
I have a local variable which I initialize before it gets assigned in a following loop. However, after the loop, the compiler says that my variable is unassigned. How can I get the loop-assigned value to persist post loop?
Are you assigning it to a class-member variable, or a local variable inside the loop?
You should probably just show the code
Local variable (of a function) initialized, assigned in a loop.
ptpPath(Vertex a, Vertex v, int t){
Vertex current;
Vector2 d = b - a:
for(...){current = ...}
//Current is uninitialized here
}
If the for loop is skipped (meets exit condition), current will remain uninitialized . . .
How do u fix this?
problems, solve?
a powerful website for storing and sharing text and code snippets. completely free and open source.
Oh nevermind I found it
Ok so, I did update it. WHY AM I STILL GETTING THIS MESSAGE ???!?!?!?!?!?!?!
Edit: Nvm, I restarted it's all good.
Im on my first 2d map proj, stuck on combining procudural generation with chunk loading
how do i approach this
I have 3 errors of Player Animation.
Can someone help with it, its scripting?
a powerful website for storing and sharing text and code snippets. completely free and open source.
@sam you forgot a { after the SetMoveBool method
Also add some spacing to ur methods
which line?
Method signatures must have: MethodName(paramType paramName) { }
Both the errors and the code
also got a ; end of line 24
i think you should learn programing first
ok, the IDE broke again
its not the IDE
what is it?
Method signatures shouldnt have semicolons at the end
MethodName(paramType paramName) ;
Is wrong^^
Line 24 is just invalid syntax, as Vee said
I guess the IDE IS broken though, because it should be pointing this out
!ide
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
{ { } doesnt make sense to the compiler
sometime when i use vsc for unity only it randomly stop working also, no suggesting anything
just close and reopen every since, no clue what cause it
can you paint strike it Vee?
show me with paint where the incorrect portions are?
Vs code is not officially supported by Unity. MS is maintaining their own extension
Not to be a asshole
Just count the curly braces
But i like ppl to figure stuff out on there own
And remove the ; where they said
Otherwise they will be here all the time
you should learn the basic programming first sam
You cant have mutiple { in a method
if you get your !IDE configured it will show it for you
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
one moment im going to remodify my VSC2019
Like i said its MethodName(paramType paramName) { }
The { } define the scope of the method
ohhh ok
So its { = Start of the method. } = The end of the method
We cant help without seeing the code. Although i wish i was a master programmer and could just tell ur problems from just looking at the errors
link?
!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.
to the copy paste url
Just do one of these and send the link back here
Again
{ } Defines scope
Two { doesnt make sense to the compiler
Review ur code one more time
Take a look at this ☝️
Pretty neat ^^^
Thats why its important to have Matching { and } braces in ur code
{
{
}
}
You have scope issues on lines 24, 25, 27, 36
Did you look at the image I sent? Did you compare what vee has been saying to your code.
There are significant and obvious issues on the lines I pointed out. You need to just take the time to look while thinking about what you've been told.
The solutions are SUPER obvious and easy
Look at EVERY curly brace and ask yourself "does this one need to be here?"
Ignore the errors for now. The compiler is super confused by the mismatched scopes.
Fix those, THEN see what errors are left
Proper indentation would help too
i'll see what I can do
Make sure each "{" has a matching "}"
Thats it
And Method names cant have a ; at the end of them
Unless they’re abstract but that’s for a different lesson
All this was covered yesterday, how is it still a problem. 🤔
!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.
Use one of the provided links to post your code. Not everyone can see the script when dropped into Discord. . .
https://gdl.space/metuvesuta.cs 1 error left...what to do?
Hi I sent the code
Don't ping everyone.
That code doesn't make much sense. Are you following a tutorial?
I am yes sorry
Share the tutorial.
You have the word private inside a method
Because, again, the braces are messed up
i see that its in the tutorial I look at
You never close the ReadMovement method
I strongly doubt that
But it's possible 🤷♂️
If so, the tutorial is wrong
Learn How To Make an Endless Runner Game From Scratch With Blender And Unity. All code is written entirely in C#. https://play.google.com/store/apps/details?...
me?
Look at each brace and make sure it has a matching one in the right placa
Again, your ReadMovement method is not closed. You start OnEnable INSIDE of ReadMovement because of this
i shared the tutorial
They are probably looking at it now
ok
You've been told many times by now, that you need opening and closing braces. You must have the same number of open as close. They must encompass the code around the class, the functions and the if statements (in your code).
If you this is something you're going to keep asking, then you're going to need to do some basic C# learning.
@reef patio it is best to follow tutorials on Youtube
Actually, you also need to show that your IDE is configured with a screenshot of it underlining the error. Failing to do this will result in you not asking any further questions here. Enough is enough on that front.
That's not a great tutorial... Even their demonstration of the end result is jittery, meaning they're not moving the object correctly...
Didn't unity !learn have a course on endless runner?
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
okay I see
your IDE should immediately be able to identify curly brace issues, because everything will turn red lol
That’s how he got here in the first place.
ok @buoyant knot
in general, YT tutorials are great to show you install/setup, and show the different tools you can use
YT tutorials generally suck at style and code architecture
Strongly disagree honestly. At least until you understand unity and coding kinda well at least.
Best to do a c# tutorial like https://www.w3schools.com/cs/index.php or tutorialspoint or microsofts own guide first.
If not, then just !learn
I always recommend against youtube at first though
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
case and point: most YT tutorials spam public fields, which is very noobish
Okay thats how I learn @buoyant knot I see
To be fair public fields are the least of the problematic things. Much worse is if they use functionally incorrect stuff. Like moving physical objects via transform. Or querying input in fixed update.
I have 3 classes, Entrant, AbberationEntrant and GreyEntrant, both AbberationEntrant and GreyEntrant inherit from the Entrant class
how would I make an array, where each element can be any of the 3 classes?
Make a array that takes in the BaseClass type
I always forget the syntax for arrays for some reason hold on
Entrant[] entrants;
@final trellis
how would i declare the first element in the array to be a normal entrant, then abberation then grey during the initialization of the array? cant seem to get the syntax right
Are you doing it via the editor or via code?
@final trellis
Obviously via code if you cant the syntax right sorry im dumb
You assign a reference of a desired type to the array element.
A reference type array holds references to the objects, not the objects themselves.
Should be like any other type?
entrants[index] = entrant_reference
So, what matters is how you create the object and what type it is.
Share code as well
oh i meant something like this, but the current unity C# version doesnt seem to like it
!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 lol
No
Just make it the base type
You dont need the sub types in the declaration
Yes, that is unsupported by Unity's C# version
The issue is that that's not a correct syntax of a constructor.
It's the recently introduced collection initialiser syntax.
right i forgor the ()
itd be damn nice if it was 12 tho
In roughly a year's time it might be
Were talking about unity having nice features here... A.K.A Impossible
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
pastebin of the classes code
damn what'd I do
boobs are a real thing
you should be more concerned about the markiplier slider
i prob dont need a pastebin but my array declaration is just
[SerializeField]
Entrant[] entrants = { new Entrant(), new AbberationEntrant(), new GreyEntrant() };
Does that work? I thought that syntax was unsupported
its supported as soon as you replaces the square brackets with curlies
but theres an issue where, either its all being converted to just the Entrant class, or the variables for the 2 other classes arent serializing
Well, the array IS declared as Entrants, so it will only show the variables available from that class
is it possible for it to show me everything?
I am not sure how. It would probably take something like an editor extension
Maybe a serializable dictionary could do it?
Not sure
agh i should probably check odin serializer's legal stuff then
bc i have it im just anxious abt using it in this project since its for a gamejam where the projects gotta be open source
What are u trying to do exactly?
Having an array of multiple types is a code smell to me personally
basically, im tryna make a Papers Please inspired game where instead of determining if their papers are in order, its if theyre human or not. each "day" has an assigned list of Entrants. These Entrants can either be random human, random nonhuman, randum indeterminate, complete random, or compeltely scripted human/nonhuman/indeterminate
my idea is to make each day's entrant list an array it goes through
maybe, but then I cant change my mind on if the 2nd entrant is nonhuman or not that way
Instead of using the array to access them. Instead just make them public or have some form of Get And Set that handles retrieving the references
Then again i dont know ur project fully or your requirements. But theres always multiple ways to do the same thing
It seems like the Unity Editor doesnt like multiple types in the Array declartion so you could make a custom script or look into another way of handling the problem. Its honestly out of my expertise but i hope someone else here can help!
I appreciate that breast size is the first slider defined in your class
ay i aint the one down bad here!
tiddy size is a thing that varies between humans!
Is there a way to make the float less long?
You want the number itself to be rounded or just to show rounded?
If you just want it to show with less decimal use standard string formating
Ah sorry I just want this to show. 0.10
ideally ".1"
Else, multiply it and then divide it by the same number, since that would make it lose the last decimals since it can only store up to so many
{
value *= 100;
value = Mathf.Floor(value);
value /= 100;
Debug.Log(value);
return value;
}```
This seems to work
You could simplify it like this
Which, is also literally the first google seach I found
So... I don't mind answering, but next time if you think your question is generic enough pls search it fisrt
have u guys use Physics.SphereCast with both index layermask and float maxdistance ?
is there a way to force using access modifier for variables in vscode , sometimes i forget to put "private" and copilot always suggests variables without "private"
Variables with no access modifier are considered private by default
i understand, i was just reading on whether i should use private or without and settled on always using private (but sometimes i forget to do it and occasionally go thru my scripts to check if i missed it)
it's not a big deal, i can just keep checking scripts from time to time, ty
Hey guys, memory leak but idk where its happening, how do i check whats wrong?
Working on this drawing tool, I need it to be interactable with the player object. How would I go about that?
Drawing Tool Script: https://pastebin.com/wTWpLL4K
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
I currently have a problem with my movement code causing my player to move strangely. Here is my movement code: ```cs
void FixedUpdate()
{
Move();
}
void Move()
{
Vector3 velocity = rb.velocity;
Vector3 inputVelocity = transform.TransformDirection(moveInput.x, 0, moveInput.y);
velocity.x = Mathf.MoveTowards(velocity.x, inputVelocity.x * speed, speed / acceleration);
velocity.z = Mathf.MoveTowards(velocity.z, inputVelocity.z * speed, speed / acceleration);
rb.velocity = velocity;
}``` In this video I am moving back and forth, then I am spam tapping the forward move key to show how the player moves at a weird angle: https://streamable.com/mzdrv0
Could be related to the stack overflow that you have.
I fixed the problem anyway, was instantiating every single update and deleting the same thing because i was missing something that was crucial
Would it be better to lerp instead of using Mathf.MoveTowards?
Nvm, using lerp does seem to work better, and it uses the acceleration variable like acceleration should be used now.
Why is my spot light that im using for my flashlight making the terrian (floor) glow weridly once shined within range of it. If it goes close to the floor it lights a big area. Can anyone help me
trying to make missiles fly, with homing after reaching high(total trajectory is more like of mortar), in 2d by using
transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(dirToTarget), turnSpeedBase);
by default, up is Vector3.up, and when missiles flies vertically(diving), it does weird spiraling ang goes off my 2d zeroed z. So, when missile starts diving, i feed Vector3.right(or left) as up direction and it goes without spiraling. I don't think i get it.
So, the up direction's purpose is to control how the curve will go, right?
📃 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.
line 34, please pay attention to your code
im on line 34
the brace is the wrong way round
post code again
now count your braces, they need to be balanced
yes, you have 6 open and 8 close. you do understand wehat balanced means don't you
yes
so if you have 6 open you should only have 6 close
bar 6?
balanced as in 1 close for each open
or the sixth brace?
neither, look at your code from top to bottom, each section should have 1 opening brace and 1 closing brace, this is very basic C#, you should know this
like this {} ?
yes
in each opening section?
create a new c# script and look at it's structure
oh that part
what did you think I was talking about?
the top part to bottom
well, that is the bottom. Is your IDE even configured?
ya
show me, screenshot the complete ide window
So it is not configured
!ide
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
what's wrong with it?
this
it should say Assembly-CSharp
ok ill check
If I were to make a Doom 1993 style ammo system (touching ammo increases an ammo variable in an AmmoManager script) would the best way to do that is to use dictionaries and make an enum for each ammo type?
sure that can work.
No just have the pickup tell the AmmoManager how much to give.
Now you can have as many as you want.
Why not make an Enum for each ammo variable?
That way I can have a MaxAmmoCount variable
You will need enum anyway if you want to know what ammo type you picked up
But how would I define a maximum ammo cap?
Do I set it in the dictionary?
So it'd be
(PlasmaAmmo, 600)
store them inside fields like consts or yeah dictionary could work too
You can make custom class to store all that info in the value
Hey anyone know what this means?
So I can just make a class called Ammo and have it store the type (Enum,) max amount, etc?
the enum would be the Key
But then how would I initialize it? Dictionary's?
the class could be just the currentAmmo and maxAmmo
What's on line 213 of the movescript?
Done, again, thanks.
public Dictionary<AmmoType, AmmoInfo> AmmoInventory = new Dictionary<AmmoType, AmmoInfo>
{
{ AmmoType.Pistol, new AmmoInfo { MaxAmmo = 100, CurrentAmmo = 50 } },
{ AmmoType.Rifle, new AmmoInfo { MaxAmmo = 200, CurrentAmmo = 100 } },
};```
Just an idea, but obviously you can use other ways, like scriptable objects or just a bunch of fields or classes. Remember, there isn't just one way to do things as long as it works for you and easy to understand
Hmmm... Maybe check angle for NAN🤔
whats NAN?
Not a number
How would I check that?
AmmoType is the Enum, and AmmoInfo is the class, right?
Why not just make the class handle both the info and type?
Sure you could do it that way too
if (Timer > MaxTime)
{
Variation = Random.Range(0, Walls.Count);
Distance = Random.Range(3, 6);
Pos += Distance;
// Instantiate a random wall from the Walls list
GameObject NewWall = Instantiate(Walls[Variation]);
NewWall.transform.position = transform.position + new Vector3(Pos, Random.Range(-Height, Height), 0);
Destroy(NewWall, 60);
Timer = 0;
}
Timer += Time.deltaTime;``` ive made this script to generate objects and i (player) have a constant speed but no matter how mush i fiddle with it either the generator outruns me or i outrun it
you still need a collection to store them
I mean you could put a whole bunch of fields but that to me seems very code smell lol
Dictionary is neater imo
if you had 14 weapons you would have 14 fields 😵💫
No I meant why make the dictionary handle <AmmoType, AmmoInfo> when you could place AmmoType in AmmoInfo?
So it'd only be <AmmoInfo>
yes but now where are you storing AmmoInfo
and how are you going to know which ammoInfo you want?
a dictionary is a Key Value storage
like a real life dictionary , you lookup a word(value) by a letter (the key)
So we're basically assigning the enums values?
the first param/type is always the Key
WeaponType is the Key to find which ammoInfo you want to pullup
So uh... I added this little if statement to the code (I've probably done this wrong but whatever) and the error is gone. I took this line away and the error came back?
Does it print the log?
no
why would you test for something AFTER you have used it?
That's actually close to my original implementation, I just didn't know how to assign more than one variable to the Key
Good point I guess, still don't no why it fixed it self tho
So AmmoType.pistol would only have MaxAmmo, it wouldn't keep track of current ammo
Must be some specific case where the value is invalid.
OH wait I might have forgotten to trigger the spin thing while i was playing
hang on
Oh... so now my character just doesn't rotate at all
No Key has to be only 1 type.
Also you can make your own keys by using classes but you have to implement their respective methods for equality check
It doesn't run that spin code or the other one that goes at a different time
A thousand thanks for the help!
np! best of luck
Well, make sure what it runs first
... I don't know at what point I broke it, but after futher testing, it's barely functional
It can't even press the play button from the main menu anymore
!warn 880555918083903499 Configure your IDE to ask questions here as you've been told before, next time you will be muted.
sam_othman has been warned.
how to add a highlight made from shader to an object?
i know how to raycast, just confused with integration of two shaders 
or how they work together
ah wait I found out how 
https://www.youtube.com/watch?v=fJRtSSD32UE, but I think it is inefficient, it is making lots of materials with highlighted versions (1 object specific shader with fresnel, 1 object specific shader without fresnel) if it was 30 objects, it would reach 60 shaders, instead of using a transparent fresnel thingy and the object's shader (object specific shaders + fresnel (universal)) which would only be 30 shaders + 1 (fresnel), but I dont know how to do the second one
what would be the best approach to make highlights?
if you can manage it all in a single shader, why not
it uses 2 shaders, I dont know how they interact or how to make it work
Wouldn't it just be 2 Materials? One without fresnel and one with? Multiple objects with the same material will share a material instance by default.
But regardless, yes I would just use 1 shader.
Swapping between meshes is... hard to manage in some cases.
im still confused how materials work with unity, I might be misunderstanding how they work 
And you can't do a nice smooth transition between unhighlighted and highlighted either.
from the video, they made something like helmet texture and helmet texture with highlight, then wood texture, wood texture with highlight, instead of making something like helmet texture and highlight texture (universal) but I do not know how to make a universal fresnel work if it is also a shader (not sure if two shaders apply on one item)
- Offtopic from yoour Talk but Want to Share-
Ayoooo got my Essentials Badge , now up to the Junior Programmer Course 😄
Do you know anything about shaders or the Shader Graph?
I know shaders in blender, it is a bit similar in unity i think
but dont know how they interact with 3d space or code
or what limitations objects have when it comes to shaders, like, I know i just need to make a universal fresnel over an object to save shaders instead of making copies, but dont know if it would be possible to overlay that over a shader
if I could relate it to editing pictures, the video made something like pngs instead of layered psds
materials is unity's batching concept for shaders, but it's less of a thing in URP I've read (from the devs)
Hello
wrong channel, wrong place. Try the forums
The forums ?
Do you have any forums I can join ?
!collab
We do not accept job or collab posts on discord.
Please use the forums:
• Commercial Job Seeking
• Commercial Job Offering
• Non Commercial Collaboration
hey could someone help me with this error ?
i can send screenshot of the script
What's trajectoryline?
i basically want to make a ball that u can drag and shoot with your mouse and the line is smt that u will se on screen to indicate where you will really go
What you're trying to achieve doesn't matter here
your !ide is not configured. Do that before asking questions
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
its not that its not configured im just using notepad
well don't. you must have a configured ide to ask questions here
I'm speechless
ah k sry
Guys can someone lead me to a good projectile motion tutorial, i need help pls
YouTube those words
none of them are like i want 😭
How are we supposed to know what kind of tutorial you want?
What do you mean by "good projectile tutorial" then? If you want your projectile to work hyperspecific ways you won't find any, you have to create on your own
Or by modifying existing methods
like i have a target transform and i set the height, i want the object to go in a trajectory towards the target
any ideas
math
What does that even mean?
easiest way is to let gravity to it all for ya
Is this projectile idea of yours freshly cooked in your brain or did you see similar thing happen in any game?
I assume it means they have a target they want to hit, and an intended height the projectile should reach during the travel.
Which can be figured out using the kinematic formulas.
yes its not that deep
just mechanics?
Set height of what? Projectile? Target? Launcher? That may not be deep but vague as hell
It's not that vague.
If I'm being real these are the types of questions you'd get in physics classes a ton.
one second ill show you
question is. How do you want to move your projectile?
math
but how? Manually? Physics? Magic?
It is vague af
idk whatever works best
See?
there's no shortage of youtube tutorials on this
float targetThrowHeight = //provide your intended height here
Vector3 initialPos = //provide your initial position
Vector3 targetPos = //provide your target's position
float gravity = Physics.gravity.y;
float displacementY = targetPos.y - initialPos.y;
Vector3 displacementXZ = new Vector3(targetPos.x - initialPos.x, 0, targetPos.z - initialPos.z);
float time = Mathf.Sqrt(-2 * targetThrowHeight / gravity) + Mathf.Sqrt(2 * (displacementY - targetThrowHeight) / gravity);
Vector3 velocityY = Vector3.up * Mathf.Sqrt(-2 * gravity * targetThrowHeight);
Vector3 velocityXZ = displacementXZ / time;
In this tutorial students will learn about the parabola formed by projectile motion and use physics calculations to start programming an automatic attacking tank. Next, students will complete the programming of the AI tank by adding Unity physics back on the shells and automatically controlling when the tank shoots through code.
You really went ahead and spoonfed answer? 
Unity even made one
I've been fucking with Pikmin-esque arc throws for like, 2 weeks. Would you believe my throw code was open?
I don't mind it, but I don't think we are supposed to spoon-feed answers here
Oh well
if that was the case then all replies should be followed by "Did you debug your code at all?"
It's different helping figure out the issue, and totally different just straight up giving a codeblock for a problem but I digress
Nah, that's fair. My bad.
Hello can anyone help me with jaggy movement, I was using transform based movement but then I started using rigidbody based cuz the collisions weren't working but now it jags a lot
Also I have low fps cuz of OBS
post your !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.
assuming you changed all your movement methods to rigidbodies, it must be done in fixedupdate
Yeah I tried that as well
Hey is there any common reason fo rplayers/rigidbody 2D's to be bouncy? the physics object attached isn't, but for some reason the player is?
https://gdl.space/janoriyeta.cpp This is not the one I'm using in the video but it's jaggy as well
I saw the .cpp extension and got concerned
it's not cpp it's cuz of the website
dw I'm using cs extension
Also for some reason it's not jaggy when there is no rotation
When I add the player rotation it starts to be like that
Seems fine, I'd expect something more with the camera
you've got it following the mouse it seems or something (regardless, jitter with rb is pretty common)
Oh yeah
Hello, guys! I got a reference issue but I am not sure why? I have tried to add some debug.log statements to figure it out it says that the issue persists somewhere in my PlayerController script at the lines it says in console. Is someone available to help figure it out?
If you've not looked into cinemachine, it fixes a lot of stuff itself
Alright I'll take a look thnx
Surely you should know by now that you need to show the code
Hey! Do you want me to make a thread maybe?
however you want
Yeah the problem is the camera thnx for helping again
NullReferenceException
I know this probably isn't the right channel but idk where else to post it. Why does my material inspector look like that and how to change it back?
Oh alright. I tunred it on when working with animations. Thanks!
Hey there, I have some problems with the physics and the linear drag particularly.
So I adjusted the Linear Drag value of my rigidbody and I find it perfect for the X velocity but not for Y tho.
My object reaches its terminal velocity too quickly and that terminal velocity is too slow. I think the right thing to do would be to add some code to FixedUpdate but I don't know what to add without messing to much with the physics of my object.
How you send that?
!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.
https://pastebin.com/TP1FWfMh i have this script right here, its pretty messy so hopefully that doesn't get in the way too much.
I have this script on 2 objects and it should run on both objects when they collide. I want when they collide for an animation to happen and for a singular new piece to spawn in.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Right now, I can only get 2 pieces spawning at the same time with some experimentation, ive been looking at this code for like over a month on and off and havent found a cleaner solution to what is right now (the animation is new and broke lots of things)
!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.
What did i do?
RectTransform itemSlotRectTransform = Instantiate(itemSlotTemplate, itemSlotContainer).GetComponent<RectTransform>();``` gives the error that the object i want to instantiate is null but they both have recttransforms??
the specific block this is happening in is as follows:
void RefreshInventoryItems() {
int x = 0; int y = 0; float itemSlotCellSize = 90f;
foreach (Item item in inventory.GetItemList()) {
RectTransform itemSlotRectTransform = Instantiate(itemSlotTemplate, itemSlotContainer).GetComponent<RectTransform>();
itemSlotRectTransform.gameObject.SetActive(true);
itemSlotRectTransform.anchoredPosition = new Vector2(x * itemSlotCellSize, y * itemSlotCellSize);
Image image = itemSlotRectTransform.Find("image").GetComponent<Image>();
image.sprite = item.GetSprite();
x++;
}
Show where you assign itemSlotTemplate
private void Awake() {
itemSlotContainer = transform.Find("itemSlotContainer");
itemSlotTemplate = itemSlotContainer.Find("itemSlotTemplate");
}
they're both transforms above awake in
Transform itemSlotContainer;
Transform itemSlotTemplate;
Show them in the hierarchy
where is RefreshInventoryItems called from
For some reason it doesn't find the template object, but you shouldn't use Find anyway, just make the fields public and drag the objects in
a setinventory from another script
public void SetInventory(InventoryScript inventory) {
this.inventory = inventory;
RefreshInventoryItems();
}```
and where is that called from
will do that. thanks
if both are in Awake it may simply be initialization order issue
awake in the player script
private void Awake() {
inventory = new InventoryScript();
uiInventory.SetInventory(inventory);
}
do i put one in start then?
move the code that accesses other scripts to start
all of it?
idk what i did but my force field and fireball dont interact no more
its the logic behind the system - Awake phase is for setting up internals, Start is for accessing externals
ahhh thanks
all scripts first go through Awake phase, by Start everything is expected to be setup and ready
do i do the same with the find ones too?
otherwise you have to rely on Script Execution ORder
private void Awake() {
inventory = new InventoryScript();
}
private void Start()
{
uiInventory.SetInventory(inventory);
}
i have provided the collision script + both the fireballs and force fields components i nthe screenshots
so Find fails
see API Docs for Find
if may ignore the object it originated from, or something similar
monovegaviours can only be added using addcomponent()
InventoryScript() ?
If you drag the objects there you have to remove the Find lines
the one thing i forgot to do lol. thanks
any1?
a powerful website for storing and sharing text and code snippets. completely free and open source.
whats wrong with the physics
it should jump over naturatly not just tripping over and flying
I'm creating custom gravity and I want to have a normalized vector3 in the direction of the gravity so I can determine which way it goes for each object that has this custom gravity override the normal gravity.
does anyone have an idea how to do this efficiently?
what do you mean efficiently?
i dont think there is a way to skip squaring on normalization if thats what youre asking
sqrt'ing
well I could create an empty game object and use that to get a direction for gravity but maybe there's a better way of doing it
you mean an object that will represent the attractor?
Do it like how physics do it by default. There's Physics.gravity so make your own static gravity property
why would you need a separate GO? you just assign the gravity to some component that handles it 🤔
any1?
when I see highlight tutorials, they often replace the material from the object, is it possible to add another shader on top instead? like fresnel with transparency so the original shader is kept?
yes
you can use Command Buffers for that in built-in and Render Features in new RP
command buffer is a container for a bunch of instructions, like draw this mesh with this shader after camera is done rendering
is there a tutorial for command buffers with similar scenario? or similar use
I am pretty new, but I want to explore

it can get quite messy tho trying to overlay it on top of existing shader
probably
that shouldnt be an issue
zfight happens when both shaders are in the same sorting group, your overlay shader should already be higher, and as command buffer will not even be rendered in the same queue
Might be because you can't use the equals operator on strings.
I guess the easiest solution is to have the highlight effect on the shader but disabled, and you tweak the intensity from the code by modifying an exposed property.
But that would imply copy-pasting the highlight effect to all shaders that can be highlighted
probably yea
ah, I see, it is like something above the shaders 
this was one of the options, option 1 was make 2 copies of highlighted and non highlighted materials, option 2 is pasting it in every shader, my 3rd option is to make a fresnel on top of every interactable
well uhm, how do i approach this then?
depending on how many attractors/attractees there will be you may have to implement some sort of spatial optimization structure, in any case the query for the closest attractor, or all in range, will take a massive chunk of computations, at which point whether they are game objects or just v3 in an array is insignificant
i thought the first two options were troublesome, or another way to make it do less work
collision.gameObject.name.Equals(Names.shield)
Or 4th option is to have a separate object that you reposition above the currently selected object
equals? really lol
== exists and works fine
appearantly not..
Then I am of no use lol
that’s only a java thing 😅
Well if == returns false, then your strings are different
ah, like instanced ( i do not know the term xD)? but would that be costly, or not much
Nah if you have only one instance of it that you disable/enable and move as needed
i chekced the names, they are correct, and the object do in fact collide, so idk why it would return false then
Can someone please tell me how to position the text just a bit higher and rotated for 180
if it were you, would you choose 4th or 2nd approach? I do not know the cons and pros yet 
The code says otherwise. Maybe one has a space or invisible characters at the end? Have you logged them and their lengths in the console to see if the variables contains really what you think they are?
Best ways to learn coding
if I have 2 attractors I should just be able to normalize the dot product of their attraction right? maybe have the vector decrease in length exponentially over distance
Try also using a debug log outside of the if statement. An easy thing to print would be the name of the colliding game object like what SPR2 mentioned. It would narrow down whether it’s a naming problem or a detection problem.
can you elaborate? im not sure how dot would help here
Doesn't the dot product return a scalar?
I wanna make a VR game but I don't really have any coding experience. Should I learn general coding or lean how to code vr games straight off the bat?
do you actually have a problem with the performance? if not - I'd say implement in the easiest way and improve only if necessary
if I have a source of attraction on the left at distance 3 and a source on the top at distance 2, the object in question should move to the top left but more towards the top because it's closer
There are formulas for gravity attraction calculations, what do you currently have in place?
Usually you compute each attraction vector for each body, then average them
ah ok
They're based on distance, so bodies that are farther away will attract way less than closer or more massive ones (if you want to implement mass, there are also formulas with them)
problem is locating nearest attractors when you have lot of them, because if you dont optimize that part it will lead to combinatorial explosion
maybe I should only check for gravity sources within a certain radius around the object then?
what the hell is going on
forgot -1?
yes and the method of doing so will affect performance the most
the rest, vector computations you can unload onto a Job
again, before trying to optimize, understand what the parameters are - do you actually have hundreds / thousands of objects that affect each other, or < 10?
optimizing stuff is great fun, it just seems like that's a few steps ahead of your current stage
until a certain point, after which custom structures will perform better
I mostly just want to future proof and learn. I never had a lot of vector math in school
relying on physX internal trees for sphere queries is easy, but they come with an overhead because its a structure designed to work with lots of various geometries, plus you will be relying on moving colliders in the scene
okay, so start with making it work in an easy to code way, play with the elements, see at what counts it starts being problematic, profile, try more advanced solutions, profile and measure improvement 🙂
the point of starting with a simple solution is to have something to compare your optimal thing against, and to be able to compare effort vs effect
I'll see what I can do
(otherwise cache's points are all 💯 👍 )
if you want to learn about spatial structures
https://en.wikipedia.org/wiki/Bounding_volume_hierarchy
https://en.wikipedia.org/wiki/Quadtree
https://en.wikipedia.org/wiki/Octree
and spatial hashing
last question, should I check for custom physics objects from the source of attraction or the other way around?
Inspect each line of the error. If none of them point to your own code, then you can ignore it.
You know when it points to your code when the line has a link to one of your files, with a line number. Instead of the <hex number>:0 at the end
try AddComponent instead of GetComponent
(oh... pointcache! took me a while to realize you're you 😄 )
i see, yea i just re ran the game and did the same thing but the error didnt show up
Also, the debug shows that it is ion fact colliding with the shield, so yea the problem is somewhere with in the if statement, tho even after copying the name fro mthe heirchy its still not running the if statement
Apply the debugging instructions provided earlier on. Log both strings and their lengths to the console.
i think its best to iterate over each object, computing the vector for each individually, if you are using custom tree, and from source if its physx query, it seems to be a complex topic with nuances
there is actually another way completely which may be most performant
there is a thing called flowfield, where space is a grid with each cell being assigned a vector value
there is a possibility that instead of assigning a static vector for a cell you can assign which attractors are affecting it
then each object will know which are in range just by accessing the cell it is in, and compute the final value
the only heavy computation will be updating the grid when attractors move
which is basically just a spatial hash

flow field will not work here because it will lack the resolution and the physics would be wonky
I will pretend to know what this means until I take the time to read up on it xD
those are all just ways to look up things in space with minimal iterations
I've seen flow fields in videos a handful of times
what the hell, how is it even possible if i literally copied the name exactly
You aren't colliding with what you expected
That's the lengths right? Also log the strings themselves
error solved, thanks
<@&502884371011731486> suspicious link
You're trying to destroy a prefab, which is not really possible at runtime and probably not what you want.
what should i do then
Well, what do you want to do?
This a prefab, an asset. Do you want to destroy/delete the asset from the project?
A prefab is an asset.
So you want it deleted from your project?
i want the current prefab that tuched the barrier to be sestroyed
public static class SaveLoadManager
{
public static SaveData saveData = new SaveData();
}
[System.Serializable]
public class SaveData
{
public ScoreTuple casualTopScore = new("Casual", 0, 0, 0);
public ScoreTuple normalTopScore = new("Normal", 0, 0, 0);
public ScoreTuple advanceTopScore = new("Advance", 0, 0, 0);
public ScoreTuple[] previousScores = new ScoreTuple[6];
}
[System.Serializable]
public class ScoreTuple
{
public string mode;
public int score;
public int words;
public int skips;
public ScoreTuple()
{
mode = "None";
score = 0;
words = 0;
skips = 0;
}
public ScoreTuple(string mode, int score, int words, int skips) { }
}```
Any reason why
```cs
public ScoreTuple[] previousScores = new ScoreTuple[6];
default constructor isn't being called here? This works if I just make it into a singleton, but I'm trying to figure out why doing it static this way just doesn't populate this array with defaults.
A prefab instance maybe? The gameobject in the scene? Because if you destroy a prefab it implies it being deleted from the project.
Do you understand the difference between prefabs and objects in the scene?
no ?
i think not that much
The default value of reference types is null
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerShip : MonoBehaviour
{
public int shipSpeed;
public GameObject enemyShip;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
Quaternion rotation = Quaternion.LookRotation(enemyShip.transform.position + transform.position, transform.TransformDirection(Vector3.up));
transform.rotation = new Quaternion(0, 0, rotation.z, rotation.w);
transform.Translate(transform.up * Time.deltaTime * shipSpeed);
}
}
Yeah, but I have a default constructor here, why wouldn't that be called? no wait uh
i want the white wall to destroy only the ball but its not working
what exactly is telling it to do that
Because a constructor is called when an object is created. You just have an array of nulls, no objects in there from what I can see.
Then I suggest going through the beginner pathways on unity !learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Well, you're not referencing the ball
its even looking away sometimes
im clueless
new ScoreTuple[6];
This should be creating 6 indices and all the data should be populated
no
No. That creates the array.
ScoreTuple is a class, the default value for reference types is null
@teal viper
how i must follow this website
No. That's not the ball that you showed. It's not a scene object.
yes its a prefab
Yes. Follow the courses on the website to learn properly.
Yes. And a prefab is not an object in the scene.
it learns the c# ? for unity
bcuz i don't know much about c#
so ow to delete it?
Yes, they cover some C# as well.
For C# I'd recommend the Microsoft C# manual though
Delete what?
no its bad for unity
it didnt helped me
the ball
Well
public class SaveLoadManager : MonoBehaviour
{
// "Global" instance
public static SaveLoadManager Instance;
public SaveData saveData = new SaveData();
}```
Making save data not static here does populate each array with defaults so if someone can expain what black magic is happening
Unity serialization
It's serialized by Unity
ok, so unity is calling the constructor then
yes
I really don't understand what you're saying, but you should do proper learning.
Reference it instead the prefab
ok right, this what happens when I use this language primarily for unity
hmmm
the ball is a bullet
the player is shooting bullets
i want the white wall to destroy the bullet
the bullet is instantiating when i shoot using left M click
i want to destroy the bullet
Then you need to destroy the instantiated bullets, not the prefab that they're spawned from.
yes
spawned ??
wth is spawn hhh
its a shooter point i mean
instantiated
do u understand ?
No. I don't understand.
Please use google translate or something to convey your thought.
emotional damage
But the solution to your issue is to destroy the instantiated bullets, and not their prefab. Understand?
i dont know to cry or laugh
Maybe do some learning instead. Probably the best course of action.
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
think i am wasting ur time , right
what iz zis
what it learn
whats the deferent beatwen learn and teach
it helps ? more than tuts?
For that you'll need to learn English. Not really a question for this server.
Yes, since it goes over all the stuff that you need to know.
what abou coding
it doesnt
i dont want every thing
Unity learn does cover some coding, but ideally you should go throught the Microsoft C# manual.
You do. You do want everything related to basics of working with unity.
no i mean every thing of c#
You wouldn't learn everything of C# even if you wanted to.
just 1 q
what shoud do here?
@twin ibex Unity learn is fine. Plz do not go through that guide
i mean i want a few of the all
This is good
If you read, it'll tell you what to do
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
donot ?
At the very least go over "Get started" and "Fundamentals" Maybe check the tutorials as well for beginner tutorials.
u r saing its fine ?
@twin ibex I am under the assumption that you have never developed any software under any form, correct?
If so, then reading a cold hard manual is going to affect your motivation. It'll be a while till you see any form of progress.
If you were experienced in a different area, my advice would be different
hey guys, i just learned how to make asset bundles in unity, but i dont know how to instantiate them. i want to instantiate them using asset play delivery if possible.
does anyone know how ?
ok then
I'd still go through some of it. That's what I did when I was starting and it helped a lot.
wtf i must do
go through it or not
Even if you don't understand all of it right away, it would give you some idea on the concepts and how they're related
Yeah definitely do the "Introduction to C#" link on that page
Take our input and think for yourself 🙂
what r u talking about ?
Up to you, but maybe start with unity learn instead.
is putting them here and making the delivery mode install time enough or is there anything else i should do ?
About the C# manual.
do u mean this ?
No, I was pretty clear about what I meant here:
<#💻┃code-beginner message>
But you might as well go through this too.
Here's another pro tip: improve your English. It's very important for software development.
It covers object oriented programming. Very important concept of you want to improve beyond basics, but you don't have to learn it right now.
It is. It's part of C#. And unity uses C#.
As I said, start with unity learn first.
The game engine is built around c#, not the other way around
@twin ibex Dude, I'm sure you can figure that one out
Essentials, then programming. The rest is optional.
qqqqq
how the Essentials
the Essentials is 2 weeks and the junior 12
how?
That’s how long it takes to learn them
Welcome to programming, where practice is required to get good
how can I create a logic where if triggers works > play sound and if trigger doesnt work > play another sound? to play a sound when trigger works is clear but idk how to connect them so i wouldnt play 2 sounds at once or missplay one of them
i will die
bro do u see
It can be faster depending on your experience
the Essentials is every thing but in 2 weeks
how
2 weeks is absolutely nothing if you want to make games
but the juniorr is apart of the Essentials but its 12
i dont mean that
Yeah I realize that just now
It's not a part of it, it's after as the graph shows
I think it's supposed to be a path and not a container
Observation and understanding is one of the key skills to have when starting out with programming, you need to work on that
how to open those skills ?
@twin ibex Practice makes perfect
Practice, like everything
practice what
if i dont know much about c#
That's what the tutorials do, they make you practice
no the tut stocked me in a loop
but i exited it
and now iam trying to practice
Member for 3 years. Maybe troll
If you're stuck on a tutorial it's most of the time because it was too advanced for you
ok
give me a bigginer tutorial that explains the codes
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Unity Essentials linked above.
learn isnt a tutorial
really? 😱
It's a collection of tutorials
that explains the basics
u said it
Holy hell, hadn't explored learn in years. Feels bloated now
the basics
you can't learn complicated stuff in c# if you dont know the basics 💀 😭
after it
thats not my first time
well do it and then you will see like @short hazel said
@twin ibex Okay, well after it, you will be a slightly improved version of the Salata developer, and then you keep going until the version is good enough to create what you want to create
and likely stopping won't even be an option at that point
i willl learn from it ?
i mean learn to do somthing without tuts
You could have began like 20 minutes ago, yet you're still here complaining and thinking about your future. Just go do it now
You'll see what you learn while doing it, along the way
you WILL learn of it it's simple you can try to copy it in a notebook or something
when you code, try to go back and see it many time when you need and you will learn it
i must stop the YT tutorials , right
not exactly
no u can do both
unity learn explain the basics while the yt tut learn how to do stuff
Not exactly, just make sure you’re actually retaining the information from the videos and not just copying the code
ok
im having a slight issue with my sliding and im not sure why. idk why but im floating after sliding from any height , if i jump and slide , i float until the sliding timer runs out same happens with the ramp etc, pls someone help me
https://youtu.be/SsckrYYxcuM?si=6I-npAjAxarKsd-q this is the tutorial i followed for the sliding
ADVANCED SLIDING IN 9 MINUTES - Unity Tutorial
In this video, I'm going to show you how to further improve my previous player movement controller by adding an advanced sliding ability, that supports sliding in all directions, sliding down slopes and building up speed while doing so.
If this tutorial has helped you in any way, I would really ap...
meh i had the same problem too :/
did you fix it?
i tried by going to dave's discord server
in was barely active
yeah trying to find a solution there as well but it was barely active
hopefully someone can find the solution to this problem
Hey, can you post your code on one of these? Thanks! !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! Sorry
You’re fine! That’ll just let me see it on phone.
https://paste.ofcode.org/Gpyu9hF7uqzKX2JUKcvgnz here you go
hi sombody can teach me one script to player movement with animation?
i aready have all animation and i know a little of movement code
Can I see the script that holds SlidingMovement()?
Or actually, it would appear that the entire script didn’t paste into the website
Hey, I have a question, I want to position the white gameobject at the edge of the camera, as it works in the canvas with anchor presets, but I don't know how to do it with gameobjects
its in the sliding script lol
don't know where to ask this so just gonna ask here - trying to implement a simple pick up script for items, however they seem to be rotating weirdly as you can see in the video and Im not exactly sure what is causing this. I just followed and copied code from this tutorial: https://www.patrykgalach.com/2020/03/16/pick-up-items-in-unity/
And then can I see the jump script?
the jumping is in the PlayerMovement script , lemme send it to you rq
Do you not set them to their identity rotation when picked up?
and if you're childing them, and the parent has rotational values then they too will be affected by it
yeah I have a parent with the script and then the model underneath - I have only been applying transformations to the parent. Unfortunately I dont know what you mean by setting identity rotation - I am really bad at programming
Quaternion.Identity
basically the default rotation of the object (or just zero out the rotation ^^)
If I want to do roguelike stuff where like, the player gains fancy things during the run. Like, for example returning damage back when attacked or gaining a temporary speed buff after killing an enemy. Should this kind of stuff be already within the player controller script waiting for a boolean to trigger them? Should they be like separated scripts components that I do attach to the player later? Or is there a way to add or override methods to an existing script during runtime?
Hey, have a little problem, I used to have a spawn prefab responsible for spawning bullets for the ship which was a child of player, but now that I moved it as a reference it doesn't seem to update its position anymore (I can see the bullets spawning in the console, but that's about it). I'm guessing it's a very easy fix, could anyone help out with some suggestions?
This also got me a bit confused as I am not sure how to manually assign the position for the spawner anymore
is there someone who can help me setting up with a ladout choosing screen for an fps , just like a good tutorial or a way how its done best would be a big help already
Your examples don't seem controller specific. This would be more related to a class like PlayerStats, PlayerModifiers, ect
Like... just have a reference to what point you want the proyectile to spawn, like the current ship position + an offset
@thorn holly sorry to tag but here
Yeah, I see that in retrospective; but I added all this into the player controller a while ago, since I was just managing basic movement at the moment
Anyways, the question remains kinda the same
found this code in the script SimpleGrabSystem - is this not doing what you said? (sorry for the silly questions;;;)
So locally the values should be rotated as their defaults, meaning if you were to take out the model and put it in your scene that's how they should be displayed, but this also takes into account of the parent rotation if it is being rotated too
Which makes sense because it does follow your arms, so the question is are these objects orientation the same as the imported rotation
I’m sorry, I have to go, I hope someone else can help you
Sorry
damn , alrighty , its fine dwdw
can someone help me with this?
Drag out a pumpkin into your scene with a 0,0,0 rotation that's not parented and tell me if it's flipped like in your video
if it is -> the forward direction of the object was not exported/imported correctly
it is ;_; Okay, so I imported the models wrong...
z-forward, y up
You can also wrap it into an empty gameobject and use that as the pivot
buttt, if you know how to change orientation through blender, I'd just go ahead and do that
I think doing that + hitting "apply transform" worked! I will test with my other food stuffs
there's one other option that deals with transform units if you're importing by fbx
in case your objects import with terrible scaling
Where should I store data for a game element? In the associated script or in another object? E.g., an object has "health", where do I store the current health value? Since I have many other properties (e.g., weight, height, money), if I store the associated values in each script, I get a hotchpotch of scripts and always have to look for it. If I store it in a central object, then some game elements will not have all properties but their objects have them.
Hey everyone. I am an absolute beginner at game-programming. I watched a tutorial on how to program your first game. When it gets to player-movement I followed the instructions step by step and seemingly have everything right, yet I get an error message CS1503. Could someone help me? I don't really know what I did wrong.
what's the other option?
How do I declare it then? I checked it multiple times but I can't find the difference to the code in the tutorial.
i just told you
show the code in the tutorial
100% it's not 1:1
Ah, maybe it was apply transform like you were saying
ayoooo just a quick question to you , youre name sounds familiar , are u working on diffrent other platforms and are u creating programs ?
wdym different other platforms
If you don't want to do it the "composition" way where you have 1 script per "feature", then you can do it with interfaces. Declare an interface like IHealth which forces the class to implement a Health property.
Then to get the script and modify the health, use your regular GetComponent but pass the interface type: GetComponent<IHealth>(). It will get the first component that implements the interface (your script), and you'll be able to modify it as usual
Some Platforms related to League of Legends , creating tools to boost the playfun and making the game easier 😄
Usually you store information about the gameobject such as stats on a component internally. There is no requirement to do that though, and you can pretty much store data about gameobjects on an external script decoupled from the gameobject. This way would require some additional identification and callbacks though because otherwise that gameobject would be ambiguous as to what it contains.
yea if you call it like that 😄
Does someone know how I can fix this pls
eggplant is behaving weirdly when doing the same thing I did for the pumpkin (export as fbx with apply transform, z forward y up). the mesh collider is rendered above the model itself?
hello, im getting this error can someone help me?
Show line 15
if (other.GetComponent<PlayerVariables>().Player == 1)
{
fpitf.WhichPlayerHasPossesion = 1;
}
btw fpitf is a script
Which of those lines is 15?
the if
Then it didn't find the PlayerVariables script on other
well thats strange
You need to check if the getcomponent returns null before trying to use the component
Or use TryGetComponent
You must check if other is not null and it is the player
Other can't be null, it's the parameter of OnTriggerEnter
Oh, true
If you changed the export settings with already some samples on the scene, it does update the mesh, but not the collider, which is calculated when you assign the collider based on the current mesh, so it keeps the original mesh shape
is this right? btw i just added debug.log so i know if it works
if (other.GetComponent<PlayerVariables>())
{
Debug.Log("Works");
}
I would use TryGetComponent or put == null at the end
and how should i do it with the TryGetComponent?
TryGetComponent gives you the benefit of being able to use the script directly from that one call
TryGetComponent was made for this
i never used it
other.TryGetComponent(out PlayerVariables player)
Always check the docs for examples https://docs.unity3d.com/ScriptReference/Component.TryGetComponent.html
thanks
alright i will
Does no one know how to fix this?
if I create a new parent object, assign eggplant fbx and add mesh collider component, it still happens
you only shared one script and it's most likely the PlayerMovement script that's the issue
Debug what other is, outside any if statement
ok
Are you following the tutorial to the letter?
What? That shouldn't happen. Did you try to just drag the model into scene and add a meshcollider? Does it still get the collider wrong?
is there a way to reset the corresponding metadata? I messed up a little while moving a couple of files
Yuppp
It does only happen with that model?
I could just be being incredibly dumb but im confused why im getting this error when its just not true??
this is my script: https://hastebin.com/share/adoyigoxem.csharp
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
so it debugs ball which im using
There's another script somewhere else in the scene that doesn't have them assigned, and that's the one throwing the exceptions.
Locate it and remove it
it is happening with the pumpkin too - I exported these with fbx apply transform z forward y up. I assume it'll happen to my other foodstuff models if I do it that way, too 😅
thank you so much i was really lost
Very cool shaders!! hamantha
You should be able to do it easily from the Hierarchy's search bar, search for t: EnemySpawn to filter out the list to object having this script attached
so i dont know what im doing wrong
I've got it now it was on one of the enemies, thank you for pointing that out
Does that object have the PlayerVariables script in it?
Not on a child or anything?
it has it in the object
i have a gameobject of 11 gameobjects and all 11 of those have it
That's... weird, those kind of issues happen cause the export is wrong, but seing the imagen just seems that the mesh IS slighty moved for some offset or weird parenting...
Do you have convex enabled
yes
models fall through the terrain if I do not
If you are using blender. I use this and then in Unity, when importing, tick "bake axis conversion"
Try that
Hmm, and it's only one gameobject such that you've not a secondary mesh child with the mesh collider not rendering.
well so in hierarchy view the eggplant for example looks like this, I was putting the mesh collider in the circled part
doing that is slightly different but mesh collider is still off
Wdym?
it just cannot find the PlayerVariables script because everything else is working
Do you really need to have 3 objects there? Why not combine them?
You're following that tutorial, correct?
