#💻┃code-beginner
1 messages · Page 390 of 1
So again, 
Optionally take the boolean result from Remove and see if it return true. If it's false there was no instance found
I'm not sure why it would not remove it, though? What do you think might happen?
havenbt worked with refrances before
i just kinda slapped a ref prefix in my class constructor
oh pointers!
why not?
sounds like the way to go now that you mentioned it
Because C# is a managed language and most things are reference types
Pointers are mostly only used when you communicate with a language that exposes these
the only place that i am using pointers in the code i sent are required by the fmod plug in im using
So in the case of EventInstances you have a Dictionary with a string key and object value. The value is a reference type.
If you have this exact reference type then you can do comparisons by reference, which is the defualt in C#. If you remove items from a Dictionary you can specify the unique string key otherwise
It's hard to determine where callBackData comes from here since you used a pointer but considering you don't seem to instantiate another reference this should remain the same reference
Only with value types this is different, as a copy is returned instead. This is usually what C and C++ does with everything unless you start using pointers
seems like it worked!
no crashes!
the reason i got crashes was that the plugin required me to have DialogEventCallback be a static method, and i didnt know how to pass my data to it when it was static
since i couldnt add any new params to the method
so i had it be private and it crashed the editor
I don't get why that would crash, weird
yooi
Would it make sense to use an event instead so you don't have to specify a callback?
i dont either. havent got a respond to my post on the forums of the package im using
i thought that too but ya know... its not my package
its a package that integrates the fmod audio engine into unity
and thats how fmod, which is a seperate program interacts with unity
Hello, I am really stucked now 😄
I have two scenes. Where one is showing the loading progress bar, that shows % and loading text. The second scene is the main game scene.
I was thinking that I can load the game scene asynchrounously and set operation scene activation to false and receive the information from game scene in loading screen (Like the game scene will be reporting the state of loading...).
(Context info - I don't want to simulate it - as I am generating the map procedurally so I want to report real status of the loading).
But I cannot do that with this approach, as Awake / Start methods are not launched until the scene is activated.....
Can I somehow have two scenes that will be communicating while loading ? Or this is completely wrong approach?
(My next idea is to merge these two scenes and just create loading handler.... but I don't like this idea - I will do it nly when I must to 😄 )
Ok Nevermind!!!
I found out I can load it with Additive flag:
↓
SceneManager.LoadSceneAsync("Game", LoadSceneMode.Additive);
So I can still have my loading scene active... and the Game scene too 🙂 Than handle manually switching the scenes!
Please, don't cross-post.
Also I have never seen someone sending an image of their question
How can i do this so it works on an prefab. I dont know how to get the gameobject of an canvas text.
i know i have to get component but i can seem to find out how
first, you should probably finish everything before you call for something’s own destroy
if you need to work on a prefab, you need a reference to its gameobject instance
i assume you want to work on the instance, and not the prefab file itself
when you instance a prefab, Instantiate returns a reference to the thing you just instantiated, which you can use
Destroy happens at the end of the frame, not instantly
but doesn’t it call OnDisable instantly?
i forget about that part, because OnEnable is definitely called from one line to the next
the canvas is a component, which is on a gameobject
oh
Does it? Idk, the docs say this:
When destroying MonoBehaviour scripts, Unity calls OnDisable and OnDestroy before the script is removed
ambiguous wording as always
it sucks to have the documentation, and still need to test to find out the details
it took me the longest time to figure out that Awake gets called, then OnEnable gets called, all one line to the next, but Start might get called next frame
Yeah I think that depends on which stage of the playerloop you instantiate an object
It's consistent with when instantiation and destruction actually happen
Instantiation happens immediately (otherwise it would not be very useful)
Is there an diffrent approach that works?
read the error
you're trying to assign a Text into a GameObject variable
don't do that; make a Text variable if you want to store a Text
https://hatebin.com/lgsrbwyytb
Movement works fine, but the rotation applied in the LateUpdate is extremely tiny, like 0 to 1 instead of 0 to 360 tiny. What could be causing this?
I see the error. but im trying to change the text using an prefab so i couldnt do i the "Easy way"
that doesn't make any sense
wdym
oh, you mean you can't just serialize a reference
bceause you're instantiating a prefab with this component on it
Hello! I have 2 scripts where I set camera rotation. First is FPS Mouse Look and second is camera shaker. How can I combine them to work togather. Now CameraShaker dosen't work at all, because MouseLook every frame sets rotation
https://gdl.space/olihadubac.cs
!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.
please share large amounts of code via a paste site
I would store the camera shake separately from the actual camera rotation
Alternatively, apply it after the camera gets rotated, and have it just adjust the current rotation
You could use an event for this
Why cant i add the Text Component into ScoreText?
public event System.Action<Transform> OnCameraRotated;
public void RotatePlayer(Vector2 delta) {
// ...
OnCameraRotated?.Invoke();
}
didn't you just say that you're using a prefab here?
or is this now in the scene?
Then, in the camera shaker:
I swiched because the player isnt an prefab so its easier..
void OnEnable() {
mouseLook.OnCameraRotated += DoRotation;
}
void OnDisable() {
mouseLook.OnCameraRotated -= DoRotation;
}
void DoRotation(Transform cam) {
// mess with the camera here
}
You would calculate the shaking as usual, but not actually do anything until DoRotation gets invoked by the event
Does ScoreText actually have a Text component on it?
Show its inspector.
if you are using TMP you need to put using TMPro and make it a TMP_Text type not Text
so, yes, do this
https://pastebin.com/fX4tpGmP
my character keeps spamming left and right when i stand to the left of it. The console is only printing "TURN LEFT" yet the scale is being spammed between -1 and 1.
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.
okay well first of all, i would suggest against using smoothdamp to move the camera
if its a first person game
instead you can use the mouse delta and just += the local rotation, then you wont be setting it just adding to it
here is my view calculation:
Vector2 cameraAngles
private void CalculateView()
{
inputView *= sensitivity / 10;
cameraAngles += inputView;
cameraAngles.y = Mathf.Clamp(cameraAngles.y, -90, 90);
Quaternion camRot = Quaternion.AngleAxis(-cameraAngles.y, Vector3.right);
Quaternion playerRot = Quaternion.AngleAxis(cameraAngles.x, Vector3.up);
camHolder.localRotation = camRot * Quaternion.Euler(camRecoil);
transform.localRotation = playerRot;
}```
and then in the shake, you can just camRecoil += shakeRotation (or maybe you want to change the name to camShake
hey guys, so im trying to make the paddle stop the moment that it's on the same y axis as the ball, but for some reason, it still passes by the ball no matter what. Why is this the case?
never test floats for equality, I'm sure you've been told this before
ohhhhhh
thank you
can someone help me understand this? im new to namespaces and unity in general. LevelData is part of the same namespace.
you are missing a class declaration
what does that mean? I declare level data in a different file
that merely means that LevelData exists
the problem is that SaveMap isn't being declared inside of a class
thus the error
spot the difference. This has a class declaration, the previous shot does not
Should I put it inside of the LevelData class? it is for taking a Tilemap and outputs a LevelData
It could be a static method of LevelData, or it could be a static method in another separate class.
put it where you want, just follow the syntax of c# when doing so
yeah i was gonna say you might want to make that static, so you dont need a specific instance to call it
otherwise, you'd need to do something very silly like new LevelData().SaveMap(...)
if (PlayerPositionX < gameObject.transform.position.x) {
transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
Debug.Log("TURN LEFT");
}
else if (PlayerPositionX > gameObject.transform.position.x)
{
transform.localScale = new Vector3(transform.localScale.x, transform.localScale.y, transform.localScale.z);
Debug.Log("TURN RIGHT");
}```
Nothing else changes the local scale... but the gameobject keeps switching between -1 and 1 when standing to the left of him
Hi I have a quick question. Im using visual studio as my ide and for some reason syntax highlighting and tool tips just turned off for one of the files im using? It still compiles fine. I don’t know if this is the right place to ask this but any help would be greatly appreciated
which would then return a second, unrelated LevelData
do you see "Miscellaneous Files" in the top left corner?
or do you see "Assembly-CSharp"?
I have miscellaneous files
can i make it so you can do Tilemap.SaveMap()? or would i have to edit the tilemap code
Actually, yes, this is possible.
im pretty sure you can extend unity classes, yeah
It'd be an extension method
Close VS, regenerate project files (preferences -> external tools), and then reopen VS
public static class TilemapExtensionMethods {
public static LevelData SaveMap(this Tilemap tilemap, int id, LevelData levelData) {
// ...
}
}
I wouldn't make this return LevelData, since it's just modifying the LevelData you pass to it
either way, you'll use it like this:
tilemap.SaveMap(123, someLevelData);
Note that the name of the class doesn't matter
the magic is in the this keyword
Hmm clicking that button doesn’t seem to start any file regeneration as far as I can tell when I press it. After reopening the issue still remains
Is there anything unusual about where this file is located?
what's the path to it?
Currently it’s just sitting at the top of my assets folder
go into your project folder with file explorer and delete all .sln and .csproj files
yep, that's the next move
I had an issue once where Unity somehow wrote duplicate entries into the .csproj files
and I had to completely delete them to fix the problem
That’s so weird, I imagine y’all are right because moving it to a sub folder fixed the issue.
If it comes up again I’ll try what y’all said, thanks a bunch!
Hey quick question, ive recently finished a tutorial for unity so right now i can move my character left and right
id like to make my character run if i tap left or right twice
im thinking in order to do that I'd need to make a seperate movement script and somehow find a way to where if i tap left twice or right twice my character moves faster
Id like to test myself so pls dont give me the answers but nudge me in the right direction y'know?
might want to take a look at the new input system 👀
I would not make a separate movement component, but I would add some extra logic to the existing one
State machines
oooohhh
theres a hwat!you're talking about the input manager?
It's a new (not really, it's current now) way to handle input using events. It's not beginner friendly, and if your'e just learning, doing it the way you're handling it now is probably a better learning opporunity; modifying existing logic etc.
But you wouldn't separate it no, as above, you'd modify the existing movement logic that tracks if you've pressed the direction twice.
it has a way to set up double-press events very easily
otherwise i’m sure you could figure something out with a timer that checks for a second input within the time
A coroutine and waitUntil works well for that
or timer -= time.deltatime every frame 
Hey, can anyone tell me what I'm doing wrong?
I am trying to make the jumps increase every 2 seconds but not surpass 2.
i would use InvokeRepeating for this, its super useful and you can just give it the name of a method and how often you want it to be called
i used that for a regenerating health system
Alright, thanks.
how can I have this code calculate the playercolliders bottom & center of the collider (Physics.Raycast(playerCollider.transform.position, Vector3.down, out RaycastHit hit, 0.2f))
I know I use bounds.min I think but not sure where to fill it in exactly
You want to freeze the game for 2 seconds every time this runs?
Well yes, I was suggesting a better method that that
I tried googling stuff and that's what it gave me.
My brain is melting from listening to brainrot in VC.
why is a coroutine better
Waituntil second input is very readble and clean
Better may not be the right word, just cleaner
You mentioned one and made it seem negative
fairs, i just dont like making a whole seperate method like that if i dont need to
So I suggested a nice alternative
I prefer to break down code as much as possible
dumb question, any reason why theres two horizontal and vertical options?
As in multiple bindings for the same input? Expand it and you should see places to add more bindings
The more the better.
RaycastHit hit;
if (Physics.Raycast(playerCollider.bounds.min, Vector3.down, out hit, 3))
Not to sure why this is not working I'm trying to use it as a ground check
3 is the raycast max btw
Try using Debug.DrawRay with the same start and direction to see where your ray actually is visibly and see if it's where you expect it to be
Okay I'll check
I can just shove it under the physics.raycast line right?
I'd put it above the raycast line
So it isn't conditional based on the raycast hitting anything
why is it asking me for two colors?
Just wants me to say Color.Red?
nvm
oopsi
Should I say bounds.center maybe instead
you should be able to use the player transform position, but i guess bounds.center works as well
I'm trying to have the origin be the collider not the empty game object player though
do you mean playerCollider.transform.position?
why?
That would probably work, unless your collider's center is offset
to detect for ground
You could also just create an empty child object whose sole purpose is to let you position the raycast origin in the inspector, and use the position of that
if (Physics.Raycast(playerCollider.bounds.min.y, Vector3.down, out hit, 3)) getting an error argument cant convert from float
are you using rigidbody or character controller for movement?
Yes, because playerCollider.bounds.min.y is a float, not a Vector3
the y is a float?
which one
Rigidbody
kk
All the components (x, y, and z) are floats
Yeah
Except in Vector2Int or something, where they are int
i would have the player origin point to be at their feet if it isnt already
Is there no way to do it from the collider and using bounds.min?
i mean there is
Yes, there is
which object is your script on?
the player
its an empty object whihc I called the playerCollider and dragged and dropped it so I have reference to it
if you got the center of the collider and the player position, they should be the same no?
I guess so yeah
im confused now, can you send a sc of the hierarchy?
Yeah I will
i dont know if the script is on the parent object or a child
on the parent
right ok
looks okay, what is the problem currently?
Error message
looks good, yeah you might need to extend it 0.1 or so
I adjusted it and it didn't change it at all
Hello
did you change the debug ray as well?
As-salamu alaykum everyone 🥰❤️🫂
yeah
oh no
i didnt
yep now I did same thing still
though this works, if you are on a steep slope with a capsule collider the center of your collider will be a bit off the ground meaning the raycast wont hit the ground. i dont know how to fix this issue and it led to me using CharacterController instead
still broken?
I don't think it works my character is now flying upwards slowly
When I hit space at least
does the ground check work before you press space?
might wanna take another look at the gravity/jumping code
so when you start flying upwards it still says grounded?
its in update() right?
should be alright
seems like rb doesnt have gravity on
and it could be that you arent jumping high enough to get 5 units of clearance for the raycast
check in scene view with the debug line
I can jump now fine but I'm able to double jump
the debugline no matter the raydistance I set is the same
oh, yeah that method is different. instead of putting 5 at the end of the parameters, just multiply Vector3.down *5
ill try it
DrawRay takes a position and a displacement
Both Physics.Raycast and Debug.DrawRay take float distance as their parameter
Not sure what's not working
maybe debug drawline(collider.center, collider.center + (vector3.down*5))
with 2 points
I can jump infinite now
Why? It's the same as their DrawRay method
public static void DrawRay(Vector3 start, Vector3 dir, Color color = Color.white, float duration = 0.0f, bool depthTest = true);
What's your objective?
yeah but apparently drawray isnt working
DrawRay does not take a distance.
groundcheck
the fourth parameter is the duration of the ray
Oh, you're right
can someone explain to me what the lamda here is for ?
public void MoveTo(int targetScene, int targetSpawn)
{
Pause();
SaveSystem.SaveSceneData();
UIHandler.FadeToBlack(() =>
{
var asyncop = SceneManager.LoadSceneAsync(targetScene, LoadSceneMode.Single);
asyncop.completed += operation =>
{
m_IsTicking = true;
foreach (var active in m_ActiveTransitions)
{
if (active.SpawnIndex == targetSpawn)
{
active.SpawnHere();
SaveSystem.LoadSceneData();
}
}
UIHandler.SceneLoaded();
UIHandler.FadeFromBlack(() =>
{
Player.ToggleControl(true);
});
};
});
}
not on both, only on debug
the mulitply?
Is there any reason for not using OnCollisionEnter & Exit?
Hey guys, im new to unity here and Got my first game yesterday. So far chatgpt wrote all my code, but i want to learn more. How can i start?
it works thank you!
!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.
I heard its much worse
less reliable
Sorry, wrong one. !learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Oh this looks good
It's much better and more reliable
just use CharacterController 
Idk
I don't like character controller very much because my character can't use physics
like If I want to throw an item based off my current velocity I don't think u can do that
The reason why it might not work is you not even using a LayerMask. If your player has a Collider, this is what the Raycast is going to detect and set the boolean to false.
yeah, depends on the game you want obviously
This much should be enough to fix it, but I would rather you used the methods I've previously mentioned.
i wonder if its possible to still do collision checks with having a rigidbody and a charactercontroler
alright chat im stumped, how would I make it to where if i double tap left or right mmy character would run? here's my code if you need it
It is, but it doesn't make sense
how would i make myself able to push boxes with a cc do you know?
you want me to paste my code and send it back or smthn?
Don't think you can because Cc doesn't have physics built in no? you are simply just moving the object
yeah, but there might be a way
I SHOULD JUST READ
I think they both are just going to detect the collisions at the same time
Question and might be silly
Can two objects if only one has a rigidbody collide?
assuming they both have colliders
Surely
Collision requires a rigidbody on at least one of them yes
only convex
OnControllerColliderHit{
if (hit.getcomponent<rigidbody>{
whoops
but you can do it apparently
by just getting the direction you hit it in and doing AddForce()
holy moly one sec
so you wouldnt be losing anythign with cc, and it has a super robust ground check
I have this but doesn't work still
Oh interesting
v simple
what doesn't work ?
damn, you can even make it go flying by increasing the magnitude and stuff lol
covex it still clips through the map
which one has convex the rigidbody ?
ok, and they have colliders ?
yesh mesh colliders + covex however the ground is a mesh collider without a covex
thats fine
is any of them marked "isTrigger"
na, do you have scripts moving it
no scripts moving it just instantiating
can u show whats happening
yeah ill record
thank you
No problem, since Unity has a big community is very easy to find common functionality and mechanics on Internet
how do I record haha
I'm trying to use the amd thing but It's not working
something like OBS or the built in recorder with Windows key + G
hey guys! i was working on a pacman game but my pathfinder kinda seems off. can someone take a look at it?
lol what is happening here ? its hard to tell
try and see?
so the player stays on the ground? is just the items ?
Generally best to just provide the information instead of asking if anyone can help
try turning out their collision detection to Continuous
thanks
np!
no
This script is on a ui toolkit document, and I make it deactivate out of the way at the start
Then when I need it, it gets activated and I can interact with the UI element and its buttons
However the buttons dont work after reactivation
When I just leave it activated from the start the buttons work
But not after having being deactivated and then reactivated
show the full !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.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
public class ui_tileSelect : MonoBehaviour
{
public static ui_tileSelect instance;
private HexTile tile;
private void Start()
{
instance = this;
VisualElement root1 = GetComponent<UIDocument>().rootVisualElement;
Button buildButton = root1.Q<Button>("BuildButton");
Button quitButton = root1.Q<Button>("QuitButton");
buildButton.clicked += () => ClickedBuild(tile);
quitButton.clicked += () => DeSelect();
gameObject.SetActive(false);
}
public void SelectTileUI(HexTile hexTile)
{
tile = hexTile;
Debug.Log("SelectMenuUp");
}
private void DeSelect()
{
gameObject.SetActive(false);
}
private void ClickedBuild(HexTile hexTile)
{
Debug.Log("building...");
}
}
Where do you activate it?
from another script
Well yes
void Update()
{
RaycastHit hit;
ray = cam.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
Transform objectHit = hit.transform;
//If the object has a selectable component on it, call it.
//Debug.Log(target);
//Debug.Log(objectHit);
if (objectHit.tag != "TileTemp")
{
//Debug.Log(objectHit.parent);
if (objectHit.parent.TryGetComponent<HexTile>(out target)) //hmm
{
target.OnHighlightTile();
//Debug.Log("Hit");
if (Input.GetKeyDown(KeyCode.Mouse0) && !ui_tileSelect.instance.gameObject.activeSelf)
{
//Debug.Log(target.GetType());
target.OnSelectTile();
}
if (Input.GetKeyDown(KeyCode.Mouse1))
{
if (!ui_tileSelect.instance.gameObject.activeSelf) {
ui_tileSelect.instance.gameObject.SetActive(true);
ui_tileSelect.instance.SelectTileUI(target);
}
}
}
}
}
}
in the last if block
and this
Debug.Log("SelectMenuUp");
is in the console?
hey uhhhh. im tryna copy some of the things I saw on the forum @storm pine sent, do I have to define this first? the "inputanykey"
Is that in a function
might want to go through some c# crashcourse
no I dont believe so
Why not
why did you put it there
might need to, I went through one tutorial and i realized how little it actually taught me
i was copying off a forum 
yeah maybe its time because this is pretty basic stuff
Pretty sure the forum didn't put it just floating in a class
e...y'know what ill just find a c# tutorial. thanks guys!
guys what can be possible reasons for such ghost behaviour
found a fix
public void SelectTileUI(HexTile hexTile)
{
tile = hexTile;
Debug.Log("SelectMenuUp");
VisualElement root1 = GetComponent<UIDocument>().rootVisualElement;
Button buildButton = root1.Q<Button>("BuildButton");
Button quitButton = root1.Q<Button>("QuitButton");
buildButton.clicked += () => ClickedBuild(tile);
quitButton.clicked += () => DeSelect();
}
The buttons needed to be reconfigured after each deactivation
I suck, please help.
I need it to give jump 1 number if it's below 2.
literally anything. Nobody can say without knowing how your game and your code works.
I need it to give jump 1 number if it's below 2.
What does this sentence mean?
ooooo clutch thanks!
what piece of my code should i show?
Jump has a value, I need it to go up by 1 if it's below 2.
if (jump < 2) {
jump = jump + 1;
}```
That's it
nothing else
https://learn.unity.com/project/unit-1-driving-simulation I had followed this one btw lol, good tutorial
In this Unit, you will program a car moving side-to-side on a floating road, trying to avoid (or hit) obstacles in the way. In addition to becoming familiar with the Unity editor and workflow, you will learn how to create new C# scripts and do some simple programming. By the end of the Unit, you will be able to call basic functions, then declare...
any of it?
All of it?
The part you suspect to be the problem?
We know nothing right now.
any of the unity Learn paths will do yes
gotcha, imma try yours tho it seems more indef
thank you so much
yeah they're all good as long as its the Unity ones!
my problem is most likely w how im processing the board
That should not be the case. If it is it is a Unity bug
no one knows for sure unless you share the code / setup
i stored the board like this
bc unity tilemapping was giving me unexpected results
in what way? its literally a grid.. this looks like a nightmare
Why not... show the code?
how do i show code
!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.
!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.
double kill!
DOUBLE KILL
the 1's means walkable tiles
i get it
what about script that moves the enemy
that'll be the pathfinder logic!
the positioning of my grid is also kinda wacky
like the centre is (0, 0)
so i hv to add offsetting to make top left (0, 0)
i feel like the path finder logic is mainly correct, and moreso a problem w my grid
and how i process it in code
Is there an equivalent to public Rigidbody2D myRigidbody; but for circle colliders? I don't see any other way to make a script reference a circle collider.
Does anyone know how to make a code for moving our characters up, down and left to right, but using Android buttons specifically for mobile games, I've followed chatgpt but there are still errors like the character doesn't move or the code is an error, but it's the same as what is displayed on chatgpt.
Honestly, it is very difficult to find sources of inspiration, especially on YouTube, and in my area there are very limited people who understand game making, especially for mobile games
I'm trying to detect a click on a sprite and I've only found half finished explanations. I'm assuming I need to use a circle collider but I can't find a way to reference it to be able to detect the click with a script.
When you say "on a sprite" can you be more specific?
Sprites are assets, they don't exist in the game.
You'll have either a:
SpriteRenderer
or
UI Image
Hi guys, I have this line of code ,and several others that are like it, that applies a velocity on the player using the rigidbody2d (for example, the walking code is rb.velocityX = 4 * MovementDirection; ). My issue is that I have this line of code in the FixedUpdate() function, and when I run the game and I walk, the speed that I am going is 3.74... This doesn't happen in the update function, so what could be the problem?
friction probably.
It's a sprite render. I just need to detect a click on that sprite render. Idk how though
So yeah you can't detect a click on a Renderer. What you need is to attach a Collider2D to it.
Then you can either use OnMouseDown or IPointerDownHandler (which needs some extra setup too if you go this route)
is there a way I can turn that off? I already have a function that will make the player slowly stop when not moving.
yes you can use a custom physics material with no friction
Also double check if you have drag/linear damping on the Rigidbody
The exact same thing but you get a CricleCollider instead of a Rigidbody2D
It doesn't work. I've tried it
@rich adder were u able to see smth?
ah yes you were right. I changed the values and I got the expected value. Thanks!
Weird. I must have done something wrong. Thanks!
It works now
Maybe a typo
definitely.
Note there's nothing special about Collider2D or Rigidbody2D. This is the same process you use to reference ANY component or asset in Unity
i hv the positioning for all of these nodes. is there a way to place a one by one square to check if it's being mapped to the right positioning through code?
write a for loop and instantiate objects in a grid?
objects?
yes objects
for example a prefab of a "square"
whatever that means to you
perhaps a cube MeshRenderer or a SpriteRenderer
yes I was recommending a way for you to debug it
Am I going to learn anything by yoinking other peoples code and mashing into what I need to make? I know it's an ongoing joke that that's what programmer do but I'm concerned that I'm not learning a whole lot.
No, you will not. Not really
You may see patterns, but underatanding takes more
Im trying to code a simple orbit simulation but im not sure how to actually apply the force to the external planet
i saw something about some addforce methods or sm but idk
this is my current code
I recommend watching this https://www.youtube.com/watch?v=7axImc1sxa0
you definitely don't want to use Update.
what part are you confused by
how to actually apply the force i have calculated using code
i saw online about a rigidbody.addforce
That's covered in the video, though he doesn't use Rigidbodies
but yes for a Rigidbody, you use AddForce to add forces, naturally.
it just doesnt show up when i try to add it to a rigidbody
wdym by "it doesn't show up"
that sounds like a problem with your intellisense
is your IDE configured properly?
i just followed a tutorial on how to set up vscode for unity
if you don't see this in the bottom left corner, it's not working properly
(well, not that exact project count, but you need to see "Projects: ")
my pathfinder seems to be working fine when i turn off my walls tilemap. but when i turn it on, it seems to get "stuck" in the walls. why can that be?
perhaps the wall tilemap has a collider
well if the "walls" has its own collider... they'll collide with it
it has a tilemap collider
what allows me to see projects in the bottom left
but i gave it a no friction material
Doesn't seem too mysterious then
cause i had it before with this but it wasnt working
Why should the ghosts be interacting with that collider at all
just use layer based collisions and disable the interaction entirely
ayoo
that fixed it
tysmm
Depends, there are multiple overloads (version of the method) available. Check the documentation to see what's available.
i read that it takes the x and y value of the force then adds that to the rigidbody
but doing that gives me an error
2D or 3D rigidbody?
and what is the error..?
Yeah so this one only has one overload available. It takes a Vector2, and optionally a force mode
Two arguments maximum
ah, it doesn't have a separate overload for separate x and y forces
ok i had also a vector 2 with both combined forces
ive got the force working and its moving
but my forces are staying constant even though the distance from the planet is changing
```
i just started programming with unity and watched some tutorials, and they all did these 2 lines of code for movement. I dont understand what this exactly does, can someone explain it to me please?
GravitationalConstant * (rb1.mass * rb2.mass) / (distance * distance);
OH MY GOD
pretty sure u need to square the distance (seperately)
YEA I DID I FORGOT THE BRACKETs
It reads input for the horizontal and vertical input axes and just stores the input data into variables.
It doesn't do anything else.
no need to shout
so if i add a rigidbody force to the left by an if statement which detects if i press a, does it just read the input for that and store it or are these two not associated?
the code you showed has nothing to do with Rigidbodies or forces
it's literally just reading the input data
and putting it in a variable
what inputs though?
The axis named "Horizontal" is going into a variable named horizontalInput
For example W = 1 S = -1
that makes sense
so its just the location of the object that is put into the variable?
By default this, but you can change it
there is no object
right
it's just detecting input from input devices
i.e. keyboard/gamepad
nothing to do with object locations or anything like that
Whatever you define it as
ok
by default "Horizontal" is the D and A keys on the keyboard
and left and right on a joystick
oh ok thats what i didnt know thanks
You can look it up and change it here
but you can change it to whatever you want
i just started programming with unity so thanks for helping me
Oh also the arrow left/right keys on keyboard
ok thanks
and joystick
It may help to read this https://docs.unity3d.com/Manual/class-InputManager.html
so vertical is just a and s?
ok
yeah
W and S
ok thanks
thats what i meant i just wrote the wrong letter
check out this screen @errant niche
if i edit the name to something else, will i also need to do
Input.GetAxis("newName")?
yes
ok
ok thanks now i understand
if i press w or upArrow, what exactly gets saved in the variable ?
one... [1]
and if i press s?
and if u press down its -
Why ask us
You can cehck for yourself
ok
1 and -1 but u can debug these values ^
thanks
same with A - D left is -1 and right is +1
is it a good idea to use these values to make movement?
var test = Input.GetAxis("Horizontal");
Debug.Log("Horizontal is: " + test);```
Get used to using Debug.Log to test things
of course
ok
thats how ive always done it
ok thanks so much for the help
now it makes so much more sense to me why everyone uses it
fast and easy
yeah
// Check for W key input (move forward)
if (Input.GetKey(KeyCode.W))
moveDirection += Vector3.forward;
// Check for S key input (move backward)
if (Input.GetKey(KeyCode.S))
moveDirection += Vector3.back;
// Check for A key input (move left)
if (Input.GetKey(KeyCode.A))
moveDirection += Vector3.left;
// Check for D key input (move right)
if (Input.GetKey(KeyCode.D))
moveDirection += Vector3.right;```
way better than garbage like this ^
thats what i did in the beginning
lol me too
but u learn quickly why its bad
when u can use 2 input axis's for 4 degree's of movement
w/o needing 4 if statements
yeah much better
with my orbital simulation
the orbiting particle just flies away and leaves and im not sure why
{
// Start is called before the first frame update
public GameObject Planet1;
public GameObject Planet2;
public float GravitationalConstant;
public float distanceX;
public float distanceY;
public Rigidbody2D rb1;
public Rigidbody2D rb2;
public float forceX;
public float forceY;
public Vector2 totalForce = new Vector2(0, 0);
void Start()
{
}
// Update is called once per frame
void Update()
{
rb1 = Planet1.GetComponent<Rigidbody2D>();
rb2 = Planet2.GetComponent<Rigidbody2D>();
distanceX = (Planet1.transform.position.x - Planet2.transform.position.x);
distanceY = (Planet1.transform.position.y - Planet2.transform.position.y);
if (distanceX < 0){
distanceX = -distanceX;
}
if (distanceY < 0){
distanceY = -distanceY;
}
if (distanceY == 0){
forceY = 0;
} else {
forceY = GravitationalConstant * ((rb1.mass * rb2.mass)/(distanceY*distanceY));
}
if (distanceX == 0){
forceX = 0;
} else {
forceX = GravitationalConstant * ((rb1.mass * rb2.mass)/(distanceX*distanceX));
}
totalForce = new Vector2(forceX, forceY);
rb1.AddForce(totalForce, ForceMode2D.Force);
}
}```
this is the code
for one you should not be adding force in Update
only FixedUpdate
for two - why have two separate references?
public GameObject Planet1;
public GameObject Planet2;
public Rigidbody2D rb1;
public Rigidbody2D rb2;
Why not just delete the GameObject one and use rb1 and rb2 exclusively?
You can assign them in the inspector
for 3 - Add some Debug.Logs to see how much force you're actually ending up adding
im not sure how to access the position for the other planet
i can see the force cause it changes in the inspector
never test floats for equality
what does that mean
rb1.position rb2.position
if(float == float) is a bad idea
floats are approximate numbers they are not precise.
If you would either use < or >
Equality check can be used withhttps://docs.unity3d.com/ScriptReference/Mathf.Approximately.html
force does not ever show in the inspector
don't confuse force and velocity
that means don't do this
if (distanceY == 0){
thats just doing it so when the distance = 0 the force doesnt go undefined
but 0.0000001 != 0
thats the point tho.. its an inaccurate comparison
odds are it'll evaluate false when it should be true
no i mean if y = 0, then i cant run the program cause unity gives me an error
and it may just do weird stuff
i dont wanna risk it
what
are you just making stuff up?
distance can never be negative
it genuinely wasnt working
idk what was going on then
but it was giving me an error saying the force vector was (0.000008, infinity)
why not just:
distanceX = Vector2.Distance(rb1.position, rb2.position);```
okay well we're just giving you a heads up on how floats work. and you should never == floats
probably because you did:
forceX = GravitationalConstant * ((rb1.mass * rb2.mass)/(distanceX*distanceX))```
And dividing by zero is bad and gives you nonsense answers
i like Mathf.Approximately
why does this say this when the horizontal axis input is set up?
also a good option, i linked it above
because you spelled it wrong
read it closely
Horziontal
well yea thats the formula but what else can i do when they are inline in a plane
Horziontal
oops
Hzntalia
thanks
Well you're discovering why micro black holes are a thing
lol
they shouldn't ever be able to get that close - they should have collided before that
i made a 2D black hole once..
i would destroy the outer one if it ever got close enuff to cause problems
Guys for having a lot of grass would I do that through coding or something else
shaders
maybe then increase the original force b/c you know now its 2 blackholes
I'm getting really mixed answers online of how to go about grass
but i doubt tahts how pyhsics works
Is there a proper channel to ask these questions
#💻┃unity-talk myb
zammm tass lookin lush
is it a grass mesh with the shaders on it
im sorta confused why its doing this
is the attractive force just not strong enough
Grass is a suprisingly complex subject with many solutions, so it makes sense there are mixed answers
Acerola has a series on it
Yeah it's crazy some people use pngs others meshes others have shaders
each has their own pros and cons
are ur objects oriented correctly? @hollow forum
how can i catch errors coming from any source get its message and stack trace?
w/ the X facing right.. and the Y facing upwards?
oh I think @rocky canyon does this stuff @stuck palm
imo I really love valheims grass
but that's all the positive I have to say about that game lol
when building an interaction system is it better to use raycast or the onmousehover function?
i mean i tried to rotate them around and it keeps going the same way
Raycast
can u elaborate a bit?
Thanks
OnMouseOver is very sus and unreliable also you dont have layers
it took me ages of debugging and trial and error to get my stuff working as flawless as it does..
i know the debug build has this, but I've made this notification system and i want to basically get the console into this notification system thing
not sure i'm able to help but i can try
so like if an error shows up the notification system will find it and display to the player
u want ur debug messages to appear on ur notification system?
yeah
my favorite is how hunt showdown does
the tall grasses can also bend and you can easily hide behind
apparently Application.logMessageReceived can do something like this
Looks like you probably still have the default gravity enabled
The force you are calculating is the magnitude
yes i know in each axis
then im putting that in a vector2
how do i disable it
on the rigidbody
i have disabled that
i'll have to dig thru my source and see how its printing the debugs in my console
oh that looks good, what asset is that
1 secnod and ill find it
its free
https://assetstore.unity.com/packages/tools/gui/command-terminal-123344 @stuck palm here ya go try this out
it automatically set up for Debugs to appear in the console.. im pretty sure u can reverse engineer it
awesome, much appreciated 😄
might just use tthis tbh
yea its pretty easy to use..
for debugging at least, will probably remove in real builds
The magnitude will always remain positive though, it’ll always move either up or to the right
ok i made them both negative
now it just goes around a little bit
and it gets fired across the screen like a particle accelerator
im using it for the opposite.. when i build my test builds i want a cheat type console for my testers to be able to teleport different places.. add to their inventory and whatnot..
once my testing is over then i'll remove it
(or make it a cheat thing w/o giving out the password/way to access it)
Hi, i was trying to compile a build of my game and it's giving me errors that I've never encounter before while building, i don't have any idea what to do, can someone help me? it's an android game
fix your gradle errors
gradle gradle gradle
sorry i didn't see the channel
what is gradle? sorry im very new to this
its part of the Android SDK
it builds your android app
probably just need to chage the API level to 33
yeah for my game it doesnt really make much sense to keep it in, im having my friends connect to my PC via parsec to test it out but my internet can't handle more than 3 people at a time connecting 😭
if you want the objects to orbit from gravity, the gravitational force must always point towards the planet. It would be best to calculate a vector from the satellite to the planet, and multiply the magnitude you calculated.
im hoping to use Gm1m2/r^2
@rocky canyon yeah i was correct
heck ya
i knew it was in there
sorry i made u install it.. lol a bit busy to look for myself
it still just flies away
That works, create a vector from the orbiting object to the planet cs Vector2 dir = planet1.transform.position - planet2.transform.position; dir = dir.normalized * Vector2.distance(forceX, forceY);
and use dir into your addForce
for orbiting objects, the force is always pointed towards the planet
it worked, thanks everyone!
it gives an error of cannot convert float to vector 2
what does? Show your code and the error
distanceX = (Planet1.transform.position.x - Planet2.transform.position.x);
distanceY = (Planet1.transform.position.y - Planet2.transform.position.y);
Vector2 dir = Planet1.transform.position - Planet2.transform.position;
totalForce = new Vector2(forceX, forceY);
Force = dir.normalized * Vector2.Distance(forceX, forceY);
rb1.AddForce(totalForce, ForceMode2D.Force);
Force
And hwat line has the error?
Force = dir.normalized * Vector2.Distance(forceX, forceY); < this line?
yes that line
I don't see how that line could possibly cause that error
show screenshots of your error and your IDE etc
Yeah Vector2.Distance(forceX, forceY); doesn't make any sense
The player's camera can't move up or down on this script and I have no clue why, does anyone know?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraMovement : MonoBehaviour
{
public float sensX;
public float sensY;
public Transform orientation;
public Transform Player;
float xRotation;
float yRotation;
private void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Vector3 currentRotation = transform.rotation.eulerAngles;
xRotation = currentRotation.x;
yRotation = currentRotation.y;
}
private void Update()
float mouseX = Input.GetAxis("Mouse X") * sensX * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * sensY * Time.deltaTime;
yRotation += mouseX;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
orientation.rotation = Quaternion.Euler(0, yRotation, 0);
}
}
that shuld be new Vector2(forceX, forceY)
btw sorry for block of code between yalls convo
it’s to get a normalized vector towards the planet and multiply by the magnitude of the gravitational force calculated
- you'd have to show screenshots of which object this script is attached to and what objects are assigned to
orientationandPlayer - You should remove
Time.deltaTimefrom that calculation, it is an error and will cause stuttering
it still starts flying in the opposite direction
Vector2.Distance doesn't work with floats, that doesn't make sense
ok so its working all of the sudden and I don't klnow why again
btw, why should you get rid of Time.deltatime there?
is it just for camera movement stuff you dont do that?
i swear to god if its just because its far away
because it doesn't make any sense. Mouse input is already framerate independent. Adding it here is going to make it stuttery when the framerate isn't constant
camera is irrelevant
mouse input is the reason
im still testing stuff.. not sure this is working the way i want it to or not
oh okay thanks
no but the problem is its flying in the opposite direction to the mother planet
if i dont move the sun it works
Praetor is right, instead of Vector2.Distance, you can use
dir.normalized * Mathf.sqrt(forceX*forceX + forceY*forceY);```
or new Vector2(forceX, forceY).magnitude
still flying opposite direction
it’s not that bad, but both will work :)
can you show your current code?
{
rb1 = Planet1.GetComponent<Rigidbody2D>();
rb2 = Planet2.GetComponent<Rigidbody2D>();
distanceX = (Planet1.transform.position.x - Planet2.transform.position.x);
distanceY = (Planet1.transform.position.y - Planet2.transform.position.y);
if (distanceX < 0){
distanceX = -distanceX;
}
if (distanceY < 0){
distanceY = -distanceY;
}
if (distanceY == 0){
forceY = 0;
} else {
forceY = GravitationalConstant * ((rb1.mass * rb2.mass)/(distanceY*distanceY));
}
if (distanceX == 0){
forceX = 0;
} else {
forceX = GravitationalConstant * ((rb1.mass * rb2.mass)/(distanceX*distanceX));
}
Vector2 dir = Planet1.transform.position - Planet2.transform.position;
totalForce = new Vector2(forceX, forceY);
Force = dir.normalized * Mathf.Sqrt(forceX*forceX + forceY*forceY);
rb1.AddForce(Force, ForceMode2D.Force);
}
}
You are applying the force in the wrong direction
p1 - p2 is the direction FROM p2 TO p1
so that would be the direction of force to apply to P2
you are applying it to P1
aka - backwards
i just want one to orbit the other
huh that's a really intuitive way to think about it
its still flying in the opposite direction wtaf
it now flew in the opposite direction towards the planet but it didnt curl around
probably means the force isnt strong enough
in my version u have to add an initial force to get teh orbit to start
or else the planet just gets sucked into the sun
if it’s flying towards the planet, that means it’s working. You need some initial force
i just did that by putting an add force in the start function
I mean you could massively simplify this code just by doing something like
velocity = (otherPos - myPos) * G * (m1 * m2) / Mathf.Pow(Vector3.Distance(tempPos, otherPos), 2)
public class Orbit : MonoBehaviour
{
public Rigidbody2D sun;
public Rigidbody2D planet;
public float gravitationalConstant = 1f;
void Start()
{
Vector2 distanceVector = planet.position - sun.position;
float distance = distanceVector.magnitude;
float orbitalSpeed = Mathf.Sqrt(gravitationalConstant * sun.mass / distance);
Vector2 tangent = new Vector2(-distanceVector.y, distanceVector.x).normalized;
planet.velocity = tangent * orbitalSpeed;
}
void FixedUpdate()
{
Vector2 distanceVector = sun.position - planet.position;
float distance = distanceVector.magnitude;
if (distance == 0f) return;
float forceMagnitude = gravitationalConstant * (sun.mass * planet.mass) / (distance * distance);
Vector2 force = forceMagnitude * distanceVector.normalized;
planet.AddForce(force);
}
}
``` heres my version if it helps
its really old.. soo not sure its perfect by any means
oh i did the same thing distance == 0f
lmao.. oops
now its just flown off the screen
rb1.AddForce(impulse, ForceMode2D.Impulse);
impulse has a value of 1.0
10,0
and is in the start function
gotta find a value that works for the gravity
it has to be exact
thats y i use math to figure out the needed velocity depending on the gravitationalConstant
if u crank that up.. u also have to crank up the initial vel
why would you apply a constant force?
no
also why impulse mode
this is just an impulse in the start to get it going
ok well you can't just guess at that number

it's going to need to be the exact orbital velocity for that altitude
i mean you could guess it
or the orbit isn't going to be stable at that altitude
but good luck
can you teach me the math
Simulating orbital mechanics requires knowing orbital mechanics
There are lots of sources out there
400 hours of kerbal space program is not helping here
or copying from someone that already knows it
to be honest, it really should lol
that's where I learned almost all my orbital mechanics
yea same
but idk all of the formulas and stuff
like im guessing im tryna find the speed at apoapsis no?
but you should know intuitively that for a given planetary mass and a given altitude, there is exactly one orbital velocity
Do you want a circular orbit
or an elliptical one
technically they're all elliptical
not sure how to make elliptical orbits.. lol i just move the sun a bit after the game starts
and i lost a planet
should camera control go in update or fixed update?
lateupdate
Update
or update. u want smooth camera
isnt LateUpdate better for follow?
that what ive heard
in terms of rotating I usually do update tho, not sure if thats 100%
ofc anything else i use Cinemachine 😄
i use cinemachine even if i have custom camera's
i just put my camera code on an empty.. w/ a vcam tucked inside
oh yeah i def used Cinemachine just as camera with Body set to none
automatic transitions got me hooked
butter smooth
i mean i calculated it to 4.767x10^-5
the only annoyance is controlling them with code 😅
like some cameras you wnt the transition time to be more than 0 and sometimes you want 0
u can jack my code if u want
u can intercept the brain.. and change the transition variables before changing cams
but i assume thats the annoyance ur talkin about
ofc u can set preset stuff too
yeah pretty much
like going from an FPS camera with 70FOV to 40ish FOV just for "zoom in" effect, blending is acceptable.. But If I want my player to look at a CCTV camera, the transition is ridiculously not needed to from from Player to a CCTV cam
oh yea... i need to do that mechanic soon
that shuld be much snappier
u dont need the out of body tansition i agree
i have 93 line script can somebody read and explain my glitch?
!code give it a shot
📃 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.
Start by describing the "glitch"
show the glitch
Not a Number
well what is it then
a pigeon?
burds aren't reall
A value that is not a number
Hallofax
like i making a prototype to like replicate the mechanics of a other game and in that it uses right click to dribblewhich applies less force to the sphere(the ball) and shoot with more force i made it so however long you hold it down it multiplies the force of the shot but whenver i play test it dosent reset the power which it is supposed to do if i click very very fast
Such as x / 0 or ln(-1)
it's what you get when you divide by zero or perform other mathematical sins
lol ^ well explained
well idk how cause im not dividing by zero
when u calculator says ERROR
am i rooting a negative number?
thats NaN
possibly
Debug.Log is your friend
you can find out all these things instantly!
Are you sure
yes
How about logging distanceX right after you get it
first one is blend transition , CCTV is 0s no blend
very nice!
well im not gonna be able to cause the program wont run
i figured it out
Then how'd you get that error?
it was a brain error
on the first one why not just lerp the FOV?
ok so it enters the planet now
Thats true I didn't even think of that lol
lol, i never thought of a transition /cam
Do you have a #1180170818983051344 ?
I keep seeing glimpses and wanna see more
cause it was smooth at the time 😛
he should.. hes got some good stuff
I probably should right 😅
i just have a bunch of stuff collecting digital dust not going anywhere
the planet works like a railgun lmao
the particle gets through and it gets fired into empty space
thanks guys! you inspired me to post some stuff there
less gooo! better post them assets too!
doesn't need to be extravagant.. im just gonna post some clips here and there
😄 i'll try brother
!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.
impulseValue = ((float)(Math.Sqrt((GravitationalConstant * rb1.mass)/distanceX)));
impulse = new Vector2(impulseValue, 0);
rb1.AddForce(impulse, ForceMode2D.Force);
Debug.Log(impulse);```
is my maths in correct for finding the required impulse
cause that finds the speed
where post go
but im not sure where to go from there
hi, enemy is jittering and switching anims quickly, how do I solve this? ty
You didnt have to delete the whole thing discord has edit button lol
its close.. but not quite right
im too impulsive lmao
mb
yeah using magnitutde on navmesh agents for animations is both a curse and blessing
So I'm trying to use a co routine to using waitforchanged result
i was tryna follow a tutorial
and I'm having issues with the parameters inside
how do i fix it
void Start()
{
Vector2 distanceVector = planet.position - sun.position;
float distance = distanceVector.magnitude;
float orbitalSpeed = Mathf.Sqrt(gravitationalConstant * sun.mass / distance);
Vector2 tangent = new Vector2(-distanceVector.y, distanceVector.x).normalized;
planet.velocity = tangent * orbitalSpeed;
}```
reference my code from earlier #💻┃code-beginner message
yeah I know, not saying its wrong just saying because of the values you've chosen and it seems to be ping ponging between two values since the terrain is sloped
can you show which numbers you picked between blends, its cutoff
show code show errors
hellooo
i am trying to make a suika game
how do i make it so that on click at a certain axis a entity is spawned? kinda a dumb question but im kinda new to unity ngl
wdym on a certain axis ?
get the mouse world pos and compare
thats cool
ty lol apple stage manager
you got off the important part again
click blendtree Show me the Clips in the blend tree and which values are picked in inspector
why are you finding a tangent?
In orbital mechanics, finding the tangential velocity (often referred to as initial impulse in your case) is crucial because it determines the initial speed and direction perpendicular to the line connecting the two bodies (e.g., planet and sun). This velocity ensures that the orbiting body (planet) moves in a circular or elliptical path around the central body (sun or another planet).
sooo like
if i press anywhere
it spawns the item on like a line so if i press under that line for example it spawn the fruit on that axis line
