u/Its-all-about-MA

Struggling Learning New Input System

I am very new to coding and unity. I am currently trying to rebuild the Google Chrome dinosaur game. I’m trying to get my character to jump. I already set up my own input action maps, and actions where I bound the space bar to the jump action.

Now I am trying to actually get this to work in my script. I have been watching many tutorials and it seems like everyone approaches this differently. Some people use the awake function some people use OnEnable function and OnDisable function, some use the FixedUpdate function, and some use their own custom function (i.e. Jump())).

Some people establish references to the InputActions, or PlayerInput component, or another class. Some people use callback context, etc.

I’ve tried following the code people use in their tutorials for many different tutorials and nothing is getting my sprite to respond to the space bar press.

I know there’s probably not one right way to do this, but for this example, I simply want to know what is the most straightforward way to get my sprite to jump when I click the spacebar using the new input system?

If anyone has advice, or suggestions, please let me know! Thanks in advance :)

reddit.com
u/Its-all-about-MA — 1 day ago

Trying to Store the Positions of Randomly Spawned Obstacles

I am very new to Unity + coding, but I am trying to start by creating a simple game on my own after following a few "build a full game" tutorials.

Currently, I am trying to recreate something along the lines of the Google chrome dinosaur game. I have obstacles spawning at random points within a range of X values, and I have them continuously moving to the left. Issue is that sometimes the obstacles spawn too close together or on top of each other, so I am trying to write code that checks where an obstacle is to avoid spawning on top of it.

Right now I am attempting to create a list and store the obstacle positions in that list in the void Update(); method, but when debugging in the console it just spits out the same Vector2 position each time. I need help with 2 questions here:

  1. What is the best way to stop randomly spawned obstacles from spawning too close to/on top of each other? Is there a better way to do it than how I am going about it?

  2. Why is the position of each new obstacle not being stored, and it's just the same position each time? (FWIW i tried using transform.GetChild but my obstacles are not a child of the ObstacleSpawner Game Object that this script is attached to)

https://preview.redd.it/t64zdmvb570h1.png?width=2012&format=png&auto=webp&s=5e8d69eb0054d2a53b5d95ea73270c7a24eeae13

https://preview.redd.it/52yfglvb570h1.png?width=2874&format=png&auto=webp&s=571d123c7fbd13be651025ceec0b7d5c0b46cb9f

reddit.com
u/Its-all-about-MA — 10 days ago