• Content Count

  • Joined

  • Last visited

About splash27

  • Rank
    Advanced Member
  • Birthday 10/20/1990

Profile Information

  • Gender

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. My solution: https://www.babylonjs-playground.com/#RAYW6X#3 It's a little bit similar with solution by @Raggar, however less expensive and more universal (I think). Yeah, the main disadvantage is simplifying physics till bounding box, but it can be accepted in my case. Anyway, it still looks like a hack. I wonder if merging algorithm can be fixed inside Babylon's core.
  2. In a shooter game I can calculate the vector with direction that player look at. This vector can be used to guide the bullet. But in this case the weapon will have 100% accuracy. I want to add a random angle (within limited range) to this vector to simulate accuracy less than 100%. So, the question is how to get rotated vector in 3D space?
  3. Hi, Wingnut. I don't know why you always have troubles with pounterLock. This part of code allows me to use free mouse look. Now what about Long Range Weapons (LRW). I can mark 3 following approaches (or even archetypes). 1. Laser. Instant damage at the point of intersection, or projectile teleportation. It's pretty good for laser cannons or probably sniper rifles. But it's not suitable for rockets, fireballs and other slow projectiles. Also I don't want to use it for regular firearms. Because even in real life you're still have a low chance to evade from pistol bullet. So, I didn't try this approach. 2. Rocket. Moving projectile along straight line. Very common approach. Suitable almost for every LRW. Except grenades, maybe. In this case projectiles just fly straight and ignore any forces. This approach especially good for rockets, since rockets have engine to compensate any force. For regular firearms this approach might be odd, however it's still ok for arcade shooters. I tried to implement it using physics engine and setLinearVelocity but failed with gravity compensation. That's why I tried to use Animation. I faced problems with collisions detection but solved it in my last playground. 3. Grenade. Projectile loses altitude because of gravity. Closer to reality approach. It works pretty fine with CannonJS. Despite the strange collision detection handler attachment (bullet.physicsImpostor.physicsBody.addEventListener('collide', function(){console.log("collide");})). The only problem here is bullet-thru-wall issue. Because bullets should fly pretty fast. It can be solved by using CCD-active CannonJS. So, it's a little bit hard for me at this moment, because I should use native CannonJS interfaces instead of Impostor system. I should learn a lot about it. Also I don't know where to get this modified version of CannonJS, except extracting from Raggar's PG example. So, this is the last obstacle on my way to success. Of course all archetypes could be modified and extended. For example, one can use delayed damage in Laser approach or collision loop reduction in Rocket approach.
  4. What about collision detection in animatable object, I made the following solution: http://www.babylonjs-playground.com/#RS8SCE#3 It works and it's pretty stable. It should has a less amount of bullet-thru-wall issues, because animation and collision checking occurs in the same rendering loop. However it may cause performance issues in case of big amount of meshes in the scene. We could try to reduce intersection loop. For example, we can exclude walls, floors and ceils from the loop and check intersections with them by checking current coordinates of the rocket. Its possible, because walls stay still. If, for example, rocket flew below y-coordinate of the floor, obviously the floor was intersected. Yeah, the situation might be much harder with mutli floor and multi room scenes. Maybe there is no universal solution. Each scene should be optimized individually.
  5. If dropped pistol will act like a box in Physics world this is not a big problem in my simulation. It should looks like compound shape however the box-like colliding is a compromise that I can accept. How to do this?
  6. Ok! Thank you again! Seems like I have to learn this field more carefully before proceed. Is CCD-active CannonJS some kind of fork of official CannonJS? Where can I get the last version of it? Also are there some tutorials how to use BabylonJS with native CannonJS? Since the Impostor system doesn't work here.
  7. @WIngnut, @Raggar, thank you, guys! I'll try to adopt your investigations to my case. I also faced the problem with bullet-thru-target issue on high velocities. I even thought about openning new topic for this :) Increasing physical timestep might help a little bit. However if I increase the power of the ball from 70 to 100 in Wingnut's last example, no further increasing of timestep helps. This is not a problem if I will destroy the projectile right after colliding, however for some other simulations this might be a problem. Also, the issue with handling 'collide' event in animatable mesh (with no impostors) still remains. I posted PG with animatable rocket before: http://www.babylonjs-playground.com/#RS8SCE#1 Btw, what is CCD?
  8. @Raggar, great! However parenting system is not comfortable in cases of spawning instances. You'll have to create instance for every child and attach impostor for every child. Can I fix halfExtents manually after merging meshes? If yes, how I can do this? I can't find such property in Impostor's properties.
  9. The problem is here: https://www.babylonjs-playground.com/#RAYW6X My mesh partially goes through the floor while the physicsImpostor is applied. Can I correct it's behavior on my mesh?
  10. Any ideas how to catch collide event? I tried to do this without animation also. But even when I use physical engine the onCollide handler didn't fire.
  11. I did it! Almost at least. My solution is here: http://www.babylonjs-playground.com/#RS8SCE#1 I just calculate the final destination of the projectile and use Animation to make it move from spawn point till the end point. I also destroy projectile after maximum distance travelled (mind the memory, huh). However, there is still a problem. I can't detect the collision between projectile and any other mesh during the flight. This doesn't work for some reason: instance.onCollideObservable.add(function (mesh) { console.log("collided"); });
  12. What about gravity force compensation? Will it works? I want to applyForce to every projectile instance. The force will be equal to gravity however it will be directed to opposite direction. I try to add this after setting linear velocity: instance.physicsImpostor.applyForce(new BABYLON.Vector3(0, 10, 0), instane.getAbsolutePosition()); However I can't see any changes. How applyForce() works? Will the force be applied forever (like gravity) or it will be applied only during first physical step(s)? Is it possible at all to compensate gravity during all lifetime of the mesh (impostor)? PS: How to change the title of this topic? I want to make it more related to projectile ballistics.
  13. I implemented it as it implemented now in my app. Here is playground: http://www.babylonjs-playground.com/#RS8SCE The trick with instance.setParent(null); works. However, there is another problem. The projectile with zero mass will not fly. I want to make a rocket that will ignore gravity, however I want to keep gravity working for another physical objects that may be placed into the scene. Is there a way to exclude gravity affection for particular physical object? As I mentioned before, setting mass to 0 doesn't work.
  14. Faced new problem. Here is a function that spawns a projectile near player's camera, calculate a vector between point of view and placed projectile and launch the projectile to the flight. launchProjectileInstance(actor) { let instance = this.projectile.createInstance(); instance.parent = actor.playerCamera; instance.position = new BABYLON.Vector3(0, 0, 1.5); instance.rotation = new BABYLON.Vector3(Math.PI/2, 0, 0); instance.isVisible = true; instance.physicsImpostor = new BABYLON.PhysicsImpostor(instance, BABYLON.PhysicsImpostor.CylinderImpostor, { mass: this.projectileMass, restitution: 0 }, this.scene); let movementDirectionVector = instance.getAbsolutePosition().subtract(actor.playerCamera.position.clone()); instance.physicsImpostor.setLinearVelocity(movementDirectionVector.scale(this.projectileVelocity)); } The main problem here is instance.parent = actor.playerCamera; This string destroys physicsBody of instance and the app crashes at setLinearVelocity with error: "Cannot read property 'velocity' of undefined". How can I place a projectile relatively to player's camera? I tried something like this, but this worked incorrectly: instance.rotation = actor.playerCamera.rotation.add(new BABYLON.Vector3(Math.PI/2, 0, 0)); instance.position = actor.playerCamera.position.add(new BABYLON.Vector3(0, 0, 1.5));
  15. Ok, seems like I understood the basics. However, there is still one question. How I can determine the direction of vector that I need to pass to setLinearVelocity()? Initially, the bullet should fly towards the point that I am looking at.