in my archery game, the arrow has a cone collider at the tip of the mesh. The arrow also has rigidbody that is changed throughout the game lifecycle.
the target has cylinder collider and the ground has box collider.
when the arrow is shot the target is not detected, but the ground is detected.
my testing:
- swapped arrow tip collider type from cone to both capsule and sphere. Not resolved.
- increased the target cylinder collider’s height. Not resolved.
- multiplied the target cylinder collider’s radius by 10. Works. But does not scale with my model
- added complete new object with box collider. Does not recognize this as well.
- added rigidbody of type static to the target. Not resolved.
I will be attaching the arrow script for reference as well.
var ArrowScript = pc.createScript('arrowScript');
ArrowScript.attributes.add("drawDist", { type: 'number', title: 'draw distance' });
ArrowScript.attributes.add("drawTime", { type: 'number', title: 'draw time' });
ArrowScript.attributes.add("arrowSpeed", { type: 'number', title: 'arrow speed' });
// START
ArrowScript.prototype.initialize = function () {
this.entity.collision.on("collisionstart", this.OnColiisionStart, this);
this.app.on('aim:start', this.OnAimStart, this);
this.app.on('aim:release', this.OnAimRelease, this);
this.cam = this.app.root.findByName('Bow').script.bowControllerNEW.cam;
this.isDrawing = false;
this.drawTimer = 0;
this.entity.rigidbody.type = pc.BODYTYPE_KINEMATIC;
this.spawnPos = this.entity.getLocalPosition().clone();
this.spawnRot = this.entity.getLocalEulerAngles().clone();
this.arrowHolder = this.entity.parent;
};
// UPDATE
ArrowScript.prototype.update = function (dt) {
if (this.isDrawing) {
this.DrawArrow(dt);
}
};
// DRAW ARROW
ArrowScript.prototype.DrawArrow = function (dt) {
this.drawTimer = Math.min(this.drawTimer + dt / this.drawTime, 1);
const z = this.spawnPos.z - this.drawDist * this.drawTimer;
this.entity.setLocalPosition(this.spawnPos.x, this.spawnPos.y, z);
};
// onAim START
ArrowScript.prototype.OnAimStart = function () {
this.entity.rigidbody.type = pc.BODYTYPE_KINEMATIC;
this.isDrawing = true;
this.drawTimer = 0;
this.entity.reparent(this.arrowHolder);
this.entity.setLocalPosition(pc.Vec3.ZERO);
this.entity.setLocalEulerAngles(new pc.Vec3(-90, 0, 0));
};
// onAim RELEASE
ArrowScript.prototype.OnAimRelease = function () {
this.entity.rigidbody.type = pc.BODYTYPE_DYNAMIC;
this.isDrawing = false;
this.drawTimer = 0;
this.ShootArrow();
};
// SHOOT ARROW
ArrowScript.prototype.ShootArrow = function () {
console.log("shoot arrow");
var worldPos = this.entity.getPosition().clone();
var worldRot = this.entity.getRotation().clone();
this.entity.reparent(this.app.root);
this.entity.setPosition(worldPos);
this.entity.setRotation(worldRot);
var camFwd = this.cam.forward;
this.entity.rigidbody.applyImpulse(camFwd.clone().scale(Math.abs(this.arrowSpeed)));
};
// onCollision ENTER
ArrowScript.prototype.OnColiisionStart = function (obj) {
console.log(obj.other.name);
this.entity.rigidbody.type = pc.BODYTYPE_STATIC;
this.entity.rigidbody.linearVelocity = pc.Vec3.ZERO;
this.entity.rigidbody.angularVelocity = pc.Vec3.ZERO;
}
