Forums

OverviewV-Play 1 SupportRotation of Image, which is moved by Path Movement › Reply To: Rotation of Image, which is moved by Path Movement

OverviewV-Play 1 SupportRotation of Image, which is moved by Path Movement › Reply To: Rotation of Image, which is moved by Path Movement
#6584

PanflamCutie

Hi Alex,

I have an question concerning the movement of the entity (dog). I want to restrict it, so that it can’t take the direction where another entity (tree) is positioned so I made the following checks (in method choose direction):

// checking for tree (wall)
        var selectedBody
        var entity

        selectedBody = physicsWorld.bodyAt(Qt.point((xPoint-1)*gridSize, yPoint*gridSize));
        if (selectedBody) { // found something
            entity = selectedBody.parent.parent;
            if(entity.entityType === "tree") {
                leftWay = false
                console.debug("Entity " + entity.entityType + " is left (position: x: " +(xPoint-1)+ " y: "+yPoint + ")")
            }
            //console.debug("------------------Entity is left " + entity.entityType + "----------------------------------");
        }

        selectedBody = physicsWorld.bodyAt(Qt.point((xPoint+1)*gridSize, yPoint*gridSize));
        if (selectedBody) { // found something
            entity = selectedBody.parent.parent;
            if(entity.entityType === "tree") {
                rightWay = false
                console.debug("Entity " + entity.entityType + " is right (position: x: " +(xPoint+1)+ " y: "+yPoint + ")")
            }
            //console.debug("------------------Entity is right " + entity.entityType + "----------------------------------");
        }
        selectedBody = physicsWorld.bodyAt(Qt.point(xPoint*gridSize, (yPoint-1)*gridSize));
        if (selectedBody) { // found something
            entity = selectedBody.parent.parent;
            if(entity.entityType === "tree") {
                upWay = false
                console.debug("Entity " + entity.entityType + " is up (position: x: " +xPoint+ " y: "+(yPoint-1) + ")")
            }
            //console.debug("------------------Entity is up " + entity.entityType + "----------------------------------");
        }
        selectedBody = physicsWorld.bodyAt(Qt.point(xPoint, (yPoint+1)*gridSize));
        if (selectedBody) { // found something
            entity = selectedBody.parent.parent;
            if(entity.entityType === "tree") {
                downWay = false
                console.debug("Entity " + entity.entityType + " is down (position: x: " +xPoint+ " y: "+(yPoint+1) + ")")
            }
            //console.debug("------------------Entity is down " + entity.entityType + "----------------------------------");
        }

xPoint is the actual column and yPoint is the actual row of the postitioning of the entity (dog). So I thought that this code would check if there is each a entity (tree) above/left/right/under the entity (dog), but it sometimes even marks a gridcell (states that it contains a tree), even though there isn’t and just a moment before it ran over the spot…

 

Is there something wrong with my check for the tree-entities?

Thanks in advance for (quick) help.

Best regards,
PanflamCutie

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support