swift usesPreciseCollisionDetection does not work? - swift

i have made an app where you need to shoot on an enemy but sometimes the bullet goes through the enemy. swift sprite kit game when I shoot on a enemy sometimes the bullet goes trough the enemy, how can I fix this?
so i added usesPreciseCollisionDetection = true.
but the bullet sometimes still goes trough the enemy. so my question was did i do something wrong or is usesPreciseCollisionDetection not working?
thank you for reading my question I hope someone can help me.

You are using moveTo to move your bullets, Physics Engine does not work with moveTo the way you want it to, usesPreciseCollisionDetection will not do anything
As far as your Physics World is concerned, your bullet is stationary. You are just playing God and performing some kind of molecular transportation to move items.
You need to use functions like applyImpulse or even just give the physicsBody a velocity if you want this to work correctly

I had similar problem that is collision was sometimes not detected even when usesPreciseCollisionDetection was set to true and both SKPhysicsBody were rectangles. In my case usesPreciseCollisionDetection for some reason started working much better when I changed one of the SKPhysicsBody to circle instead of rectangle. Try changing your bullet physics body to circle, it seems that collision detection algorithm with circles is more precise so that might help you.

Related

Setting up a sliding character in the right way

I would like to try and make a game similar to Altos Adventure. I am having trouble starting.
How to set up the terrain so that my character doesnt get stuck?
I simply drew a test sprite for the ground in photoshop. What collider2d should I use?
I use polygon collider and reduce friction in the material. But the character gets stuck, hits small invisible bumbs and it feels awful. The worst part is connecting 2 ground sprites together! The point where they connect is always messy.
I have a question for the future as well. How would I add the endless part of the game?
Would having many "pieces" set up and just spawning them as the player rides down work?
I havent written any code yet as the problem is simply in the physics in my opinion.
Thanks to anyone who takes the time and tries to help!
To move your player use rigid body.AddForce(Vector3 direction, ForceMode forceMode); then create a Physics Material with friction = 0 and put it in your player's collider.

Spritekit physics failing to detect second adjacent item

Kinda what the title says, I have a "wall" made out of multiple segments specifically for modular purposes. I have a contactTestBitmask that forces the player to stop moving in the direction of the wall once collided, but, if you slide along the wall to another segment, the player just rolls straight through it. I cannot do a collisionBitmask as the player runs fast enough to "phase" through the walls. I also cannot do collision as my camera and lighting are also dependent on the player's movement and position, and will not interfere with the walls (I think). If anyone could help point me in the right direction to allow me to make solid modular walls, I'd greatly appreciate it.
Figured out the source of my problem, contact IS happening, I just have wonky flags and the system doesn't like that. I need a contact currently happening method, I guess

Unity3D Ball physics bug in BlockBreaker game 2D

I am trying to create a block breaker game in Unity 3D but I am having problems (this is my first time creating a game). When I throw the ball it ends like this https://gfycat.com/LimitedVagueAnkole. The physics between the ball and the bricks should be problematic i think but I don't know why. My ball's material is frictionless and its bounciness is 1. My bricks materials are None (physics material).
I can send more info if it helps but I don't really know what else to send.
PS: I didn't code the breaking of the bricks yet. I just don't understand why the ball isn't acting the way it should.
The same thing is happening to me, I think I have a solution for this problem. I think the reason why the ball keeps bouncing at one place is because the ball didn't have much speed to escape from the loop. Try increasing the speed of the ball a bit and you could see the ball indeed escape bouncing at one particular angle.

How to change the shooting accuracy?

I am making an FPS game using unity 3d, I've a problem in the shooting accuracy script. Can you tell me how I can change it with a single script that shoot the bullet and include the shooting accuracy and equipped to the gun, please?
If you are currently using a raycast, you should have no problem.
If you are spawning a sphere and thrusting it forwards, I suggest you use a raycast.
Raycasts go in a completely straight line. Bullets follow gravity, and quickly fall to the ground.
You don't see bullets, they move too fast. Raycasts are invisible.
When it hits something, it sends you back the information you need. If you make the sphere go too fast, it might glitch through objects.
You can learn about raycasts here.

Boolean question in Cocos2d

I am making a game in Cocos2d. I have enemies in the game. I want them to shoot at the character. Currently, I have a boolean that says
buffDude.shoot = YES
when it is done moving. And in the Enemy class, I want it to detect if the boolean is YES or NO, and shoot if it is YES. And, while we're on that note, if I declare
buffDude.shoot = YES
in the
+(id)enemy
method, it will create a bullet at the bottom of the enemy sprite, but the bullet will not move. I know that it is because it didn't add the bullet to the Layer, it added it to the Enemy, but I don't know how to add it to the layer. Please Help! This is really driving me crazy, and help would be appreciated.
EDIT:
Okay, to get it to work, I just created a different layer and added the enemies and their bullets to that. Thanks for the help!
I am not really sure what you are trying to do. But I can only assume that you are adding a bullet sprite. And if you are adding a bullet sprite in you Enemy Class like: [self addChild:bulletSprite];, the Enemy class will own that bullet. Instead, if you would like the bullet to be visible in your game scene, you can add the same code in HelloWorldLayer.m instead.
But as I said, I'm not really sure what your problem is.