Hello again,
today I’m trying to setup a little scene with an actor, an obstacle and a simple floor. all of them are visually and physically represented by rectangles/box colliders. The floor and the obstacle are static bodies. There are two things i want to happen:
1) Everytime, the dynamic actor hits the floor rectangle, the actor should jump (negative y force impulse). This works so far.
2) Everytime, the screen is touched/clicked somewhere, the force of the actor body should be adjusted the reach this point on the X axis only (the Y force should keep untouched as far as possible). This does not work at all, and a tried alot of configurations to achieve this effect. Here is the code i gave up for now, it includes everything what for the behavior is needed.
import VPlay 1.0
import QtQuick 1.1
EntityBase {
id: actor
entityType: "actor"
width: 50
height: 80
transformOrigin: Item.TopLeft
MoveToPointHelper {
id: moveToPointHelper
}
Rectangle {
id: rectangle
anchors.fill: parent
color: "red"
}
BoxCollider {
id: boxCollider
anchors.fill: parent
force: Qt.point(moveToPointHelper.outputXAxis * 1, force.y)
fixture.onBeginContact: {
actor.jump();
}
}
function jump(){
boxCollider.body.applyLinearImpulse(
boxCollider.body.getWorldVector(Qt.point(0,-300)),
boxCollider.body.getWorldCenter()
);
}
function moveTo(mouseX, mouseY){
moveToPointHelper.targetPoint = Qt.point(mouseX, actor.y);
}
}