Monday, November 19, 2018

How do I use the auxiliary "do" in questions?


Consider these two sentences:



Who left the door open?




and



Who do you want to speak to?



In the first question auxiliary do cannot normally be used, but in the latter question it can. Why is that so? What is it about the second sentence that requires auxiliary do that the first sentence doesn't have? Please include a few more examples of this pattern if possible.



Answer



These are called subject questions (as your first example) and object questions (as your second). Here we are talking about "do", so this is present simple and past simple tense. Let us take one example:


Paul wants to speak to him.

1) If we want to know who "him" is, "him" is the object and the question we will ask is an object question. There will be an auxiliary verb, which will come between the question word and the subject:



Who does Paul want to speak to?

2) If we ask a question about "Paul" (the subject), however, it will be a subject question, and then all we need to do is substitute the subject with a question word:


Who wants to speak to him?

Further reading with examples: in this grammar book


3) It is possible to add an auxiliary verb in subject questions, that has already been discussed here. To sum it up, it adds emphasis, as in:


A: Who wants to speak to him? Jack?
B: No.
A: Jim?

B: No.
A: Well, then who **does** want to speak to him?

More examples of that can be found in the link.


javascript - determine collision angle on a rotating body


update: new diagram and updated description


collision angle and body angle


I have a contact listener set up to try and determine the side that a collision happened at relative to the a bodies rotation. One way to solve this is to find the value of the yellow angle between the red and blue vectors drawn above. The angle can be found by taking the arc cosine of the dot product of the two vectors (Evan pointed this out). One of my points of confusion is the difference in domain of the atan2 function html canvas coordinates and the Box2d rotation information. I know I have to account for this somehow... SS below


questions:




  • Does Box2D provide these angles more directly in the collision information?

  • Am I even on the right track? If so, any hints?


I have the following javascript so far:


Ship.prototype.onCollide = function (other_ent,cx,cy) {

var pos = this.body.GetPosition();

//collision position relative to body

var d_cx = pos.x - cx;
var d_cy = pos.y - cy;

//length of initial vector
var len = Math.sqrt(Math.pow(pos.x -cx,2) + Math.pow(pos.y-cy,2));

//body angle - can over rotate hence mod 2*Pi
var ang = this.body.GetAngle() % (Math.PI * 2);

//vector representing body's angle - same magnitude as the first

var b_vx = len * Math.cos(ang);
var b_vy = len * Math.sin(ang);

//dot product of the two vectors
var dot_prod = d_cx * b_vx + d_cy * b_vy;

//new calculation of difference in angle - NOT WORKING!
var d_ang = Math.acos(dot_prod);

var side;

if (Math.abs(d_ang) < Math.PI/2 )
side = "front";
else
side = "back";

console.log("length",len);
console.log("pos:",pos.x,pos.y);
console.log("offs:",d_cx,d_cy);
console.log("body vec",b_vx,b_vy);
console.log("body angle:",ang);

console.log("dot product",dot_prod);
console.log("result:",d_ang);
console.log("side",side);
console.log("------------------------");

}


meaning in context - Right or left? When the teacher says: "If you look at the diagram on the left hand side, you will solve this question!"(In a position like this?)


● Right or left? When the teacher says:



"If you look at the diagram on the left hand side, you will solve this question!"




Is it the teacher's left hand side or students' left hand side?


Imagine, you are in a position like this:



Where is right? Where is left? (You can use the colours).




The example I have in mind is this Cardiac Muscle: Function & Main Parts – Histology | Lecturio. There is a speaker off-screen. Referring to this image, he says



enter image description here
And cardiac muscle has structures called intercalated disks, which if you look at the diagram on the left-hand side, it explains what these intercalacted disks actually are and what their functional role is.





Answer



When somebody is standing in front of a crowd and they say left or right, it's almost always in reference to the perspective of the crowd that is being addressed.


A teacher may turn and point to the blackboard, indicated something to the left or right as they are now facing.


In theatre, if an actor or director wants to talk about things from the perspective of people on the stage facing the audience, they use the phrases stage left and stage right (from Merriam-Webster). Note that that is not spoken to the audience; it's for stage direction behind the scenes and during rehearsals. The audience uses the normal words.


So, the assumption is normally the perspective of the audience.


But if it's unclear, clarifying language can be used.


unity - Mip Maps on 2D Sprite causing black line above. Why is this?


I am new to Unity. I'm trying it out and using Futile for a code-first approach, but still importing textures using the Unity system.


The problem I'm having is that when I use mip maps to scale large sprites down to smaller sizes without jagged edges, I'm getting a black line artefact above said sprites.


Hard to see


A little hard to see, but they're there. If I turn down the resolution, you can clearly see them:


Easier to see


These are my texture settings:



Settings


My question is, why are these black lines here? Is it a mistake I've made? Is it just a common side effect? How can I reduce these? Also, if this is the wrong approach, how can I use smooth sprites in a game with the ability for them to scale up smoothly?


Thanks!



Answer



There are many reasons why you may be getting those lines. I wrote a more detailed answer in here, but the bottom line is:



Do not do atlasing and mipmapping at the same time.



For 2D, in general, you don't want/need to do mipmapping. That's useful mostly in 3D where you don't know the size at which your textures will be rendered, but that's usually uncommon in 2D.


If you definitely have a texture that you will aggressively downscale, then don't include it in an atlas.



And I'd also recommend you turn anisotropy off. That's meant to give you better results when you're looking at big textures from extremely sharp angles, which simply doesn't happen if your game is 2D.


Sunday, November 18, 2018

tense - Is there a simple and clear way to explain the difference between past simple and present perfect?


I read (or do I say "have read"?) many rules for when to use the present perfect. I found them complex and hard to understand (or do I say "have found"?). I am finding it hard to apply these rules in real sentences.


Is there a simple and clear way to explain the difference between past simple and present perfect? If there is a simple explanation, please tell it! If there is no simple explanation, please tell why it is so complicated. Maybe if I knew why there is no simple explanation, that would help me understand what work I need to do in order to learn the difference.





unity - Enemies are penetrating in each other when following player


enter image description here


As you can see the image my enemy (when following my player), penetrate each other. How can i avoid it? I am using NevMeshagent to follow the player.


void Update () {
currentNavMeshAgent.destination = player.transform.position;
}


I have added a Rigidbody and a Collider to my enemy object but they are still penetrating each other



Answer



To avoid penetration, increase each NavMeshAgent's radius so it's equal to or larger than your agent's collider.


Saturday, November 17, 2018

2d - Restricting Maximum Velocity in Space


I'm making a top-down 2D space ship game in which you rotate and thrust. I'd like to impose a maximum velocity for different engine types, meaning that a certain engine can only get you going up to a certain speed.


But I'd also like the ship to be able to travel faster than that maximum velocity, say if it were sent flying by a collision with a fast-moving asteroid.


I can't naively have the engines only apply impulse if the ship is moving at less than its maximum speed -- otherwise if an asteroid sent you flying to the right, you couldn't deliberately slow down because that would involve applying an impulse to the left.


But I'm not restricted to cardinal directions. If the ship is moving too fast to the right, I don't want it to accelerate to the right, but I would like it to be able to curve upward, which might involve applying some kind of impulse at say a 15 degree angle.


My other thought was to cap the maximum velocity of the ship at the maximum velocity of the engine, but then an asteroid collision could send you flying no faster than you engine's maximum speed, and that's undesirable as well.


How might I go about designing a system that allows one to reach velocities no higher than a set maximum from their own impulse, but still be able to steer their ship at higher velocities and still actually attain those higher velocities from external means?


Edit



Let's say my maximum velocity is 50 m/s. I'm traveling at 50 m/s at a 15 degree angle, which means my x velocity is 48.3 and my y velocity is 12.9. The ship is facing at a 30 degree angle (even though it's traveling along a 15 degree vector).


When I press the thrust button, I want the ship to trend toward that 30 degree angle of travel. Which means that its current angle of travel must be altered in some fashion. Right now I do so by applying impulses. But if I apply an impulse at a 30 degree angle, the ship's velocity will exceed is maximum (a good portion of that impulse is in the same direction as we're already going).


If I don't allow that impulse to be applied, the player can't adjust their course at all while they're moving too fast. And I'm not sure how to determine which components of an impulse would change a ship's velocity's angle without increasing its length.



Answer



This problem is a bit difficult to think about because it's unphysical -- engines have a thrust which equates to acceleration and not top speed. So I think to fully answer this question, you need to remove it from a physical framework and just think of it in terms of vectors.


To be clear, I will use "speed" whenever I am talking about the overall quantity of movement of the ship, and "velocity" when there is some directionality associated with it.


You can use the directionality of velocity to your advantage here. Your engine impulse can only add velocity in the direction of impulse if the velocity in the direction of impulse is below the "engine speed" rating. You need to consider vector addition here for this to work the way you want it to. If the player impulses in a direction that is not orthogonal to direction of motion, then ONLY the amount of impulse applied in the orthogonal direction will actually increase the velocity in that direction, which means that you can change direction. To disallow the player from actually increasing speed in this situation, you need to remove velocity from the previous direction of motion so that the speed stays the same (using that you can calculate speed by adding the orthogonal velocities in quadrature).


This would allow for maneuvers at higher than engine speed given that your original speed is over engine speed due to some external mechanism, but it would not allow for acceleration past engine speed in any given direction.


EDIT


Here's an example of what I mean (using the conditions you included in your edit):



You would presumably have an acceleration value of some sort from your engine specifications. Let's just say it's 1 m/s/s for the sake of argument. Let's say you press the thrust key and hold it down for 1s at 30 degrees while your ship is travelling at 50 m/s at 15 degrees (giving vx = 48.296 m/s and vy = 12.941 m/s). You would then need to apply a 1 m/s change somehow, while still maintaining 50 m/s overall speed. So, first we must figure out what part of that 1m/s is orthogonal to your original direction and then decompose the 1 m/s along that basis.


If you draw it out (I'm not sure how to draw here) you can see that you just need to undergo a 15 degree rotation, so the direction of thrust along your current vector is 1 m/s * cos(15)=0.966 m/s and the direction orthogonal is 1 m/s * sin(15)=0.259 m/s. Here comes the "difficult" part: you now need to calculate the new direction based on these values. We already determined that the thrust along the vector will not affect anything, so we can discard the 0.966 m/s change and just apply a 0.259 m/s change in the orthogonal direction.


Since we have forced acceleration to only be orthogonal, we know that this is a "circular" change in velocity (it only changes direction and NOT speed -- exactly what you want!). In this case, the orthogonal direction is 15 + 90 = 105 degrees, so decompose that into your original x-y basis and you get that dvx = 0.259 m/s * cos(105) = -0.067 m/s and dvy = 0.259 m/s * sin(105) = 0.250 m/s. It's important that you get your angles right, because that negative sign in dvx is how the magnitude stays the same! Put this together and your resulting velocity after 1s of thrust at 1 m/s/s is vx = 48.296 m/s - 0.067 m/s = 48.229 m/s and vy = 12.941 m/s + 0.259 m/s = 13.200 m/s which gives you vt = sqrt(48.229*48.229 + 13.200*13.200) m/s = 50.003 m/s which is 50 up to the precision we calculated (3 decimal places). The computer will maintain float or double precision, but you still might want to cap it at previous speed manually or those rounding errors will accumulate.


Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...