unity – Why the object is not rotating slowly?

At the top

public float secondsToRotate;
private float secondsSoFar = 0.0f;

Then in the Update

private Update()
  secondsSoFar += Time.deltaTime;
  float t = secondsSoFar / secondsToRotate;
  Vector3 lerpPoint = Vector3.Lerp(transform.position, -transform.position, t);
  transform.rotation = Quaternion.LookRotation(lerpPoint);

but instead of slowly smooth rotating it’s just waiting X seconds then rotate too fast like rotating at once.
I wanted it to rotate slowly smooth. for example, if I set the secondsToRotate to 5 so the rotation will take 5 seconds.

The full script :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerSpaceshipAreaColliding : MonoBehaviour
    public float rotationSpeed;
    public float movingSpeed;
    public float secondsToRotate;

    private float timeElapsed = 0;
    private float lerpDuration = 3;
    private float startValue = 1;
    private float endValue = 0;
    private float valueToLerp = 0;
    private Animator playerAnimator;
    private bool exitSpaceShipSurroundingArea = false;
    private bool slowd = true;
    private float secondsSoFar = 0.0f;

    // Start is called before the first frame update
    void Start()
        playerAnimator = GetComponent<Animator>();

    // Update is called once per frame
    void Update()
        if (exitSpaceShipSurroundingArea)
            if (slowd)

            if (playerAnimator.GetFloat("Forward") == 0)
                slowd = false;

            if (slowd == false)
                secondsSoFar += Time.deltaTime;
                float t = secondsSoFar / secondsToRotate;
                Vector3 lerpPoint = Vector3.Lerp(transform.position, -transform.position, t);
                transform.rotation = Quaternion.LookRotation(lerpPoint);

    private void OnTriggerEnter(Collider other)
        if (other.name == "CrashLandedShipUpDown")
            exitSpaceShipSurroundingArea = false;
            Debug.Log("Entered Spaceship Area !");

    private void OnTriggerExit(Collider other)
        if (other.name == "CrashLandedShipUpDown")
            exitSpaceShipSurroundingArea = true;
            Debug.Log("Exited Spaceship Area !");

    private void SlowDown()
        if (timeElapsed < lerpDuration)
            valueToLerp = Mathf.Lerp(startValue, endValue, timeElapsed / lerpDuration);
            playerAnimator.SetFloat("Forward", valueToLerp);
            timeElapsed += Time.deltaTime;

        playerAnimator.SetFloat("Forward", valueToLerp);
        valueToLerp = 0;

In that place in the script, I’m trying to rotate the player smooth slowly to the opposite direction. I want also to increase the “Forward” speed when it’s rotating while it’s rotating but for now the rotation itself is not working at all the player is not rotating.

if (slowd == false)
                    secondsSoFar += Time.deltaTime;
                    float t = secondsSoFar / secondsToRotate;
                    Vector3 lerpPoint = Vector3.Lerp(transform.position, -transform.position, t);
                    transform.rotation = Quaternion.LookRotation(lerpPoint);

The main goal is to create some realistic effect when the player is leaving the colliding area the player will slow down then when the player has stopped to start rotating slowly to the opposite direction and start moving by increasing the “Forward” value while rotating.

Some realistic preventing from the player to leave the colliding area. when he try to leave the area he should move back in the colliding area.

object oriented – Google FooBar Prepare the Bunnies’ Escape Python

I’m currently working on the Foobar challenge, and I’m having difficulty with this problem.
My solution works with (all the cases that i’ve tested).

Prepare the Bunnies' Escape

You have maps of parts of the space station, each starting at a work area exit and ending at the door to an escape pod. The map is represented as a matrix of 0s and 1s, where 0s are passable space and 1s are impassable walls. The door out of the station is at the top left (0,0) and the door into an escape pod is at the bottom right (w-1,h-1). 

Write a function solution(map) that generates the length of the shortest path from the station door to the escape pod, where you are allowed to remove one wall as part of your remodeling plans. The path length is the total number of nodes you pass through, counting both the entrance and exit nodes. The starting and ending positions are always passable (0). The map will always be solvable, though you may or may not need to remove a wall. The height and width of the map can be from 2 to 20. Moves can only be made in cardinal directions; no diagonal moves are allowed.
class Points:
    def __init__(self, row, column):
        self.h = 0
        self.f = 0
        self.g = 0
        self.row = row
        self.column = column
        self.parent = None

# find the neighbours of each node in the matrix
def neighboursGet(map, row, column):
    neigh = ()
    colLength = len(map(0))
    rowLength = len(map)
    # loop to find the adjacent neighbours for each node not allowing diagonals
    for x in range(-1, 2, 2):
        if(0 <= row + x < rowLength):
            if(map(row + x)(column) != 1):
                neigh.append((row + x, column))
        if(0 <= column + x < colLength):
            if(map(row)(column + x) != 1):
                neigh.append((row, column + x))
    return neigh

# find manhattan distance from node to end point
def distance(map, row, column):
    # find the position of the final node
    rowFinal = len(map) - 1
    columnFinal = len(map(rowFinal)) - 1
    # find the absolute value of the manhattan distance
    manY = row - rowFinal
    if(manY < 0):
        manY *= -1
    manX = column - columnFinal
    if(manX < 0):
        manX *= -1
    return manX + manY

# implement A* algorithm
def AStar(map):
    colLength = len(map(0))
    rowLength = len(map)
    points = ((Points(j, i) for i in range(rowLength)) for j in range(colLength))
    openList = ()
    # calculate the distance from the end for each node
    for i in range(rowLength):
        for j in range(colLength):
            if(map(i)(j) != 1):
                points(i)(j).h = distance(map, i, j)
                points(i)(j).f = points(i)(j).h

    closedList = ()
    while len(openList) > 0:
        # find the node with the lowest f value
        lowPos = 0
        for i in range(len(openList)):
            if(openList(i).f < openList(lowPos).f):
                lowPos = i
        currentPosition = openList(lowPos)
        # find the position of the final node
        rowFinal = len(map) - 1
        columnFinal = len(map(rowFinal)) - 1
        endPosition = points(rowFinal)(columnFinal)
        # print(currentPosition.column, currentPosition.row, endPosition.row, endPosition.column)
        # backtrack to the beginning and return the length of this
        if currentPosition == endPosition:
            curr = currentPosition
            ret = ()
            while(curr.parent != None):
                curr = curr.parent
            return len(ret)

        neighbours = neighboursGet(map, currentPosition.row, currentPosition.column)
        # print(neighbours)
        # check all the neighbours
        for i in range(len(neighbours)):
            neighbour = points(neighbours(i)(0))(neighbours(i)(1))

            # already checked
            if neighbour in closedList:

            gScore = currentPosition.g + 1
            gScoreBest = False
            if(neighbour not in openList):
                gScoreBest = True
            elif(gScore < neighbour.g):
                gScoreBest = True
            # if the neighbour is better than current position than make it
            # the currentPosition
            if(gScoreBest == True):
                neighbour.parent = currentPosition
                neighbour.g = gScore
                neighbour.f = neighbour.g + neighbour.h
def solution(map):
    # Your code here
    # count the number of ones in the matrix
    # and put there positions in a list
    # has initial position as a "One position" to make the position into a 0
    # which it already is
    countOnes = 0
    onePositions = ((0, 0))
    for x in range (len(map)):
        for y in range (len(map(x))):
            if(map(x)(y) == 1):
                countOnes += 1
                onePositions.append((x, y))
    # check every single solution by removing a one each time, 
    # and not removing one therefore countOnes + 1
    lowestValue = 10000
    for i in range(len(onePositions)):
        mapCopy = map
        onePosition = onePositions(i)
        mapCopy(onePosition(0))(onePosition(1)) = 0
        newValue = AStar(mapCopy)
        if(newValue == None):
        if(newValue < lowestValue):
            lowestValue = newValue
    # return value + 1 since the initial point counts as one as well
    return str(lowestValue + 1)

my solution uses the A* algorithm and it works pretty quick when I give it some cases but for some reason two of my cases fail. I think i’m missing a special case or something, can someone help?

javascript – How to get an index of an element inside an object?

I am trying to get the index of an element inside an object like below:

var array = ({spot_id: 6, spot_no: 6, gate_id: 6}, {spot_id: 16, spot_no: 17, gate_id: 5}, {spot_id: 5, spot_no: 5, gate_id: 5}, {spot_id: 11, spot_no: 11, gate_id: 5}, {spot_id: 15, spot_no: 16, gate_id: 4}, {spot_id: 4, spot_no: 4, gate_id: 4}, {spot_id: 10, spot_no: 10, gate_id: 4}, {spot_id: 14, spot_no: 15, gate_id: 3}, {spot_id: 9, spot_no: 9, gate_id: 3}, {spot_id: 3, spot_no: 3, gate_id: 3}, {spot_id: 8, spot_no: 8, gate_id: 2}, {spot_id: 13, spot_no: 14, gate_id: 2}, {spot_id: 2, spot_no: 2, gate_id: 2}, {spot_id: 7, spot_no: 7, gate_id: 1}, {spot_id: 12, spot_no: 13, gate_id: 22});

var result = array.reduce( (acc, o) => (acc(o.gate_id) = (acc(o.gate_id) || 0)+1, acc), {} );
let index = result.findIndex(rank => rank === 4);

but it fails. I think findIndex is only for arrays and not objects.

Here is this example in Fiddle:

unity – How can I draw a circle around a specific object, not necessarily the object the script is attached to?

I have this script that draws a circle around the object the script is attached to.

I would like also to use the centerObject variable as an option to draw another circle around the centerObject, or just only around the centerObject and not the transform the script is attached to. I’m not sure how to do it.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class DrawCircle : MonoBehaviour
    public GameObject centerObject;
    (Range(1, 50)) public int segments = 50;
    (Range(1, 500)) public float xRadius = 5;
    (Range(1, 500)) public float yRadius = 5;
    (Range(0.1f, 5)) public float width = 0.1f;
    (Range(0, 100)) public float height = 0;
    public bool controlBothXradiusYradius = false;
    public bool draw = true;

    (SerializeField) private LayerMask targetLayers;
    (SerializeField) private LineRenderer line;

    private void Start()
        if (!line) line = GetComponent<LineRenderer>();

        if (draw)

    private void Update()
        if (Physics.CheckSphere(transform.position, xRadius, targetLayers))
            Debug.Log("player detected");
            Debug.Log("player NOT detected");

    public void CreatePoints()
        line.enabled = true;
        line.widthMultiplier = width;
        line.useWorldSpace = false;
        line.widthMultiplier = width;
        line.positionCount = segments + 1;

        float x;
        float y;

        var angle = 20f;
        var points = new Vector3(segments + 1);
        for (int i = 0; i < segments + 1; i++)
            x = Mathf.Sin(Mathf.Deg2Rad * angle) * xRadius;
            y = Mathf.Cos(Mathf.Deg2Rad * angle) * yRadius;

            points(i) = new Vector3(x, height, y);

            angle += (380f / segments);

        // it's way more efficient to do this in one go!

    private float prevXRadius, prevYRadius;
    private int prevSegments;
    private float prevWidth;
    private float prevHeight;

    private void OnValidate()
        // Can't set up our line if the user hasn't connected it yet.
        if (!line) line = GetComponent<LineRenderer>();
        if (!line) return;

        if (!draw)
            // instead simply disable the component
            line.enabled = false;
            // Otherwise re-enable the component
            // This will simply re-use the previously created points
            line.enabled = true;

            if (xRadius != prevXRadius || yRadius != prevYRadius || segments != prevSegments || width != prevWidth || height != prevHeight)

                // Cache our most recently used values.
                prevXRadius = xRadius;
                prevYRadius = yRadius;
                prevSegments = segments;
                prevWidth = width;
                prevHeight = height;

            if (controlBothXradiusYradius)
                yRadius = xRadius;

Screenshot of script in action

Find the file size when uploading the document in sharepoint library using Javascript object Model

I am uploading the Document to SharePoint library while uploading I need to find the file size , if file size More than 100 Mb I need to skip one functionality. This need to wrote in Js file and add the Js File to the Master Page.

Need help.


java – How to stop a decelarating object?

I am programming a 2D game. When a ball is launched it should decelerate and eventually come to a stop. I have implemented the deceleration part but when the ball nearly stops it starts accelerating. I understand that I should implement some kind of condition for when it should stop (when velocity is 0), however all of my attempts have failed.

These are my variables:
v, v0 – velocity
acc – acceleration
dt – delta time

Here is a code sample of how the velocity gets updated on every game tick:

v.setX(v0.getX() + acc.getX()*dt);
v.setY(v0.getY() + acc.getY()*dt);

sql server – Troubleshooting error message Invalid Object Name accessing MS SQL with python

Using python, I can connect to a MS SQL database, but cannot run any queries at all. I always get the error – invalid object name.

I understand from other stack exchanges that I may be accessing the wrong database (although that is specified in my connection); there may be something wrong in my schema (whatever that is); or I simply don’t have permission to run a query (I should have been given read only permissions).

My connection looks like:

import pyodbc

connSurvNet = pyodbc.connect(r'DRIVER={ODBC Driver 17 for SQL Server};' +
   ('SERVER={server},{port};' +
   # 'DATABASE={database};' +
   'UID={username};' +
   server= 'xxx',
   port= 1433,
   database= 'db',
   username= 'xxxx',
   password= 'xxxx')

In another database, I can download a table into a pandas dataframe with the following code:

df = pd.read_sql_query('''SELECT * FROM MyTable''', conn)

But from the database in question, MyTable is never a valid object name.

We have a gui interface for querying the data, which allows me to see the SQL-code used for the queries. It includes code like:

FROM (Data).(Version)

I’ve a pdf of the tables, with all the table names and columns, but nothing I enter as MyTable is ever valid.

I’ve run a few ideas from Stack Exchanges, like DB_SELECT(), which shows I’m connected to a database ‘master’, but I do not know of other things I can do to isolate my issue. Any further steps to understand my issue would be appreciated.

c++ – How am I “supposed” to hold a pointer to an object I don’t own?

For instance, let’s do this in the context of a dynamic programming solver where each partial solution has a link back to the problem it solves. I might do that like so:

class Problem { /* ... */ };

class PartialSolution
  Problem * problem;

  // ...

This is fine and produces working code — including a default copy constructor and copy-assignment operator that work correctly — but then when I turn on various kinds of warnings things get upset that I’m holding a raw pointer — they assume that I must own the thing I’m pointing at and that I’m not cleaning it up.

So I take it I’m supposed to use some kind of smart pointer? But what are my options here? std::unique_pointer is definitely incorrect, since I don’t own the object. std::shared_pointer would at least work correctly, but it causes me to do unnecessary reference tracking. There’s also std::weak_ptr, but that’s even worse in terms of unnecessary cost because I have to convert it to a temporary std::shared_ptr each time I want to use it.

There’s also std::reference_wrapper in <functional>. This seems like it may actually do to right thing here, although I don’t enough about it to be confident about this and given that it’s in <functional> and not <memory> I feel like this may not be the intent.

Or should I just hold a raw pointer and do something to disable the warnings? (And, if so, what?)

game maker – How to round/smooth the path of an object/sprite that orbits around another object?

Below is a code that defines the values ​​that cause the sprite to start at the top of the object being orbited:

Create Event:



Below is a code that modifies the values ​​started in the previous code so that the sprite starts to rotate / orbit the object in a counterclockwise direction:

Step Event:



Draw Event:


The object/sprite moves correctly, but the movement occurs as follows:

enter image description here

The movement I would like the object/sprite to perform:

enter image description here

I don’t know why the object makes a straight movement. For me it would tend to always keep the same distance from the reference point (position of the object in the center). Since the movement is not circular, it does not. I would like to know why and how to make him move in the desired way.

OBS – Using the program’s “path” feature is out of the question.

django exception Object of type ‘User’ is not JSON serializable?

I’m getting the error mentioned in the title of this question. Here i’m wokring with django only. Not using django restframework. The point is i want to query user with a json response from the user model. How can i do that ?

class ProfileManager(models.Manager):
    def toggle_follow(self, request_user,user_id, username_to_toggle,json_follower):
        profile_ = UserProfile.objects.get(user__username__iexact=request_user.username)
        is_following = False
        follower = profile_.follower.filter(username__iexact=username_to_toggle).first()
        if follower:
            actor = User.objects.get(pk=user_id)
            user = User.objects.get(username=username_to_toggle)
            json_follower = user
            new_follower = User.objects.get(username__iexact=username_to_toggle)
            actor = User.objects.get(pk=user_id)
            user = User.objects.get(username=username_to_toggle)
            notify.send(actor, recipient=user, verb='follow you')
            json_follower = new_follower
            is_following = True
        return profile_, is_following,json_follower