Wrong Second position of LineRenderer

I’m drawing some kind of bullet trace effect with LineRenderer in my 2D Game Project with Unity. At some position, setting position of LineRender result weird:

enter image description here

In the above screenshot, you can see two types of lines are exists. Pure red lines are result of Debug.DrawRay which is only renders in Scene view, not actual game play, and another lines which has yellow to red gradient are actual line renders I want to draw.

I used exactly same code for rendering both two, Debug.DrawRay() and LineRenderer.SetPosition(), but as you can see only DrawRay works as I expected and LineRenderers are cutted and pointing wrong direction.

Here’s the code I’m trying:

void Fire() {     Vector3 shootDirection = m_ShootPoint.right;      RaycastHit2D hit = Physics2D.Raycast(m_ShootPoint.position, shootDirection, m_Range);     Debug.DrawRay(m_ShootPoint.position, shootDirection.normalized * m_Range, Color.red, 20);      // On Hit, set end position where it hits     if (hit) {         CreateBulletTrace(m_ShootPoint.position, hit.point);     }     // Otherwise, render straight until it's range     else {         CreateBulletTrace(m_ShootPoint.position, shootDirection.normalized * m_Range);     } }  void CreateBulletTrace(Vector3 startPos, Vector3 endPos) {     GameObject bulletTraceObj = Instantiate(m_BulletTraceLineRendererPrefab);     LineRenderer bulletTraceLineRenderer = bulletTraceObj.GetComponent<LineRenderer>();     bulletTraceLineRenderer.useWorldSpace = true;      bulletTraceLineRenderer.SetPosition(0, startPos);     bulletTraceLineRenderer.SetPosition(1, endPos);      // Destroy(bulletTraceObj, 0.1f); } 

Note that LineRenderer checked use world space to true. What am I missing?

Using Unity 2019.1.0f2.

2D Isometric map, (0,0) coordinates wrong origin point

I have an isometric diamond-shaped map. Currently my map origin is to the far left, instead of the top. I have attached a picture below. Green circle is where I want the origin point to be, however the red circle is where it currently is now.

Green circle is where I want origin to be, red is where it is now

Basically when I walk up in my game, x coordinates increase, where I would want them to decrease.

So far in my code I load in a text file with the following format

1 5 5 5 2 8 9 9 9 6 8 9 9 9 6 3 7 7 7 4 

It’s loaded with infile into a pointer of ints, from left to right, disregarding columns. The edges and corners of the map above, are sides and corners of tiles – the middle (9) is a grass tile, that is walkable.

Here is how I get map segments of x and y (Terrain codes according to tileset): https://hastebin.com/kehezeyami.cpp

Here is my world_map::render function https://hastebin.com/mezusebodo.cpp x & y parameters in render function are player x & y coordinates

If any more information is needed, please let me know, this has been bugging me for hours 🙁

What’s wrong with my line segment plane intersection code?

I’m following the algorithm on on this website for my line segment intersection test code. But when looking at my line segment and plane intersect it doesn’t produce the correct point of intersection.

Here is an example of what I’m talking about. intersection test failure

Here is my code for the test

public static bool SegmentPlane(Vector3 p1, Vector3 p2, float distance, Vector3 normal, out float time, out Vector3 point) {     time = 1f;     point = Vector3.zero;       time = (Vector3.Dot(normal, normal * distance) - Vector3.Dot(normal, p1)) / Vector3.Dot(normal, (p2 - p1).normalized);     if(time >= 0f && time <= 1f)     {         point = p1 + time * (p2 - p1).normalized;         return true;     }     return false; } 

Display Code

public void OnDrawGizmos() {     plane = new Plane(transform.forward, transform.position);      colliding = CollisionLibrary.SegmentPlane(p1.position,p2.position,Vector3.Distance(Vector3.zero,transform.position),transform.up,out time,out point);      if (!colliding)         Gizmos.color = Color.yellow;     else         Gizmos.color = Color.red;      Gizmos.DrawLine(p1.position, p2.position);     Gizmos.DrawSphere(point, .1f);      Gizmos.color = Color.white;     Gizmos.DrawLine(transform.position, transform.position+transform.up * 100);    } 

What is wrong with the following P problem?

Our teacher gave us the following statement and we were wondering what is wrong with it.

Consider an array A of n distinct numbers. Since there are n! permutations of A, we cannot check for each permutation whether it is sorted, in a total time which is polynomial in n. Therefore, sorting A cannot be in P.

obviously this is wrong. my friend thought it should just be: therefore sorting A cannot be in NP. is this correct or are we thinking about it to easily?

Is our group using the Sleep spell wrong?

I am playing a 3rd-level wizard, and I have to say sleep seems really overpowered as a spell. On numerous occasions now, a combination of sleep followed by the rest of the party slitting throats has seen us clear enemies really quickly.

I even used it on a charging bugbear getting him to pass out just before he reached me, we then managed to take him down to just 4 health in the next round of combat before he woke up. And a wolf who was clamped onto the leg of a PC.

Our GM does have creatures wake up as they take the wounds, but 9 times out of 10 they are already dead, given that they can’t defend themselves from the stabbing. Are we doing something wrong here with this spell? Having spoken to other wizard players, they have told me they find it a pretty useless spell.

What happens if I use wrong kind of spell component in a Conjure Volley?

The spell conjure volley has one piece of ammunition or one thrown weapon as its material component. The spell effect further describe the requirement of the said ammunition or thrown weapon: they must be nonmagical.

You fire a piece of nonmagical ammunition from a ranged weapon or throw a nonmagical weapon into the air and choose a point within range. Hundreds of duplicates of the ammunition or weapon fall in a volley from above and then disappear.

What happens if I use magical ammunition or magical thrown weapon? Do the spell fail and the spell slot consumed? Do the spell just don’t get cast at all and I’m like an idiot throwing a magical axe into the air waiting for something to happen?

Is a counterspell ineffective against the wrong spell?

So I had this idea in my campaign to rob a magic store. Logically, it makes sense that the owner of said store knows counterspell. So what I plan to do is to take out the components of fireball but not cast fireball. Simultaneously, I’ll take out the components for major image, concealing them, and create a “fireball”, then run out with whatever stolen goods I have. Since the spell the shop owner is countering isn’t fireball, would this counterspell be ineffective?