Hot answers tagged

4

Don't trigger based on the camera's position. Trigger based on the player's. Once the player enters the trigger you spawn the enemies just outside the edges of the camera's view. Since the camera should be following the player anyway, you can derive the edges of the screen from its position and the screen dimensions. Then it's a simple matter of adding/...


3

Invoke is useful if you want to do something one time only. A coroutine is able to pause, let the game continue running, and then do something else later. This makes them useful for processes which run over time. Also, you can pass arguments to a coroutine. The Invoke method does not allow that. Example of a coroutine which implements a countdown: ...


3

There is a lot you can do with a mathematical approach to game design, but in the end you won't get around systematic playtesting. A good way to identify places in your game which are too hard are automatically collected metrics. Whenever the player dies, log when, where and exactly how they died. Put those events into a database, so you can analyze and ...


2

The problem is that you first move every link closer to one of its neighbors, then closer to the other, without saving the original position. These two should happen at the same time, so that the position of the current links stays fixed throughout. # get vector to previous link and adjust position var vec_to_prev_link = prev_link_position - link....


2

The first and best optimization you can make is to cut down on the number of times you need to do this calculation at all. You may already be doing this, but since we can't tell from your question, here's a quick intro to the idea: If every moving object needs to compute steering angles vs every obstacle object, then your total cost is: [# moving objects] *...


2

New Answer Frame challenge: If we are checking if the sphere will collide with another, ee do not need angles. We need to know if the velocity vector we use for reference will lead to a collision of the spheres. That is, we need to know if the distance from the second sphere to the line defined by the position of the first sphere and the velocity vector ...


2

After calculating the rope, save the points it bends at relative to the objects, that cause that bend and the rotational direction (whether the rope bent in the right or the left direction). You can use these relative positions to reposition the rope during gameplay, but there will be 3 different interactions you need to pay attention to: 1.) An object hit ...


2

Try creating a 3-4 frame animation of a semi-transparent blue-white dot that moves downward a few pixels before expanding out to a 1-2 pixel radius circle. Then just create random instances of this animation all over the map. Should give the appearance of rain droplets. From there you can adjust it by maybe adding more frames or adjusting the shape when it ...


1

Your condition, Input.GetMouseButton(0), will be true for as long as that button is held down. Your code therefore updates the velocity of your Rigidbody2D to move it towards the target (tap position) while the button is held down / a tap on the screen is held, which is what produces your 'pinned to the cursor' behaviour. Depending which phase (input ...


1

The two options are: 1.) NPCs run away from the player. With this one you just need to take the vector going from the player to the NPC, normalize it and set the NPCs velocity to this vector 2.) NPCs run perpendicular to the player's direction. To achieve this, you need to take the direction of the player and rotate it 90 degrees. Since there are two ...


1

It looks like you want this: private IEnumerator BezierShooting() { var shotInstance = Instantiate(shotPrefab, transform.position, Quaternion.identity); while (t < 1 && shotInstance != null) { float invT = 1f - t; var currentPosition = invT * invT * invT * controlPoint0.position + 3 * invT*...


1

I think the OP is not looking for a solution to a kinematic problem, but rather he is looking for methods to properly balance the game. I don't think there is any method in particular, but once you decide the parameters of the jumps or speed, it's a matter of doing a lot testing. If you want to make it more "scientific", you could involve a sample of people ...


1

Jump height The approach is: when Mario just has jumped, his kinetic energy is \$ mv^2 \over 2 \$ and potential energy is zero due to zero height, and in highest point of jump trajectory his potential energy is \$ mgh \$ and kinetic is zero due to zero speed. They are equal because of the law of energy conservation: \$ v^2 = 2gh \$ (I've already simplified ...


1

To add on to the discussion I think Bezier curves are good approach, and in terms of recalculating them you can pre-bake some curves and modify their points based on requirements, so the impact should not be heavy (less so in 2D) Since you are working in 2D getting started is a bit easier, and ignore the z-axis (or y in unity, depending on your dominant ...


1

Not a complete answer, but this might help. The slowest parts of your code are the Mathf.Sin, Mathf.Cos and Mathf.Acos commands.They are usually evaluated by libraries at runtime using mathematical series and are accurate to last bit of float. (up to 1.5 * 10^(-45)) That is way to much precision required just for a game. I suggest substituting them with a ...


1

As you've found, clamping an angle can be surprisingly tricky. To illustrate your particular problem, here's a couple of crappy diagrams: This is the output from atan2 for some various vectors. Note that it wraps at 180/-180. (The Unity docs do not specify this, but it's how the function normally operates regardless of the framework.) Then, here is the ...


1

If the floor is smooth i.e. there is no drag from the surface, just use AddForce setting the ForceMode to Impulse, something like this: void FixedUpdate() { rb.AddForce(dirX, dirY, dirZ, ForceMode.Impulse); } It is important that you use Impulse as force mode, since otherwise the force is continuously applied on your rigidbody, therefore constantly ...


1

In physics engines, "kinematic" means "I'll handle steering this object around collisions myself — so engine, don't do any collision resolution on my behalf" It's often useful for things like moving platforms, which should absolutely never stray from their assigned path — even if it goes through a solid floor — or get jostled when something lands on them. ...


1

A simple linear interpolation should be enough here, since the sides are straight. For just one side, the equation is $$p(t) = \vec a + (\vec b - \vec a)\cdot t$$ Where \$t\$ is a value between 0 and 1, \$\vec a \$ is one of the vertices of the side and \$\vec b\$ is the other. For \$t = 0\$ the returned position is \$\vec a\$, for \$t = 1\$ it's \$\vec b\$...


Only top voted, non community-wiki answers of a minimum length are eligible