## game maker – How to make a path without collisions regardless of the size of the enemy / grid?

I am making a game where I have a player and enemies who, depending on the distance, follow the player.

In order for enemies to follow the player, the map was marked with a grid. When the player approaches the enemy, the enemy creates a path to the player, ignoring the walls (obj_Block).

``````global.grid=mp_grid_create(0,0,celHor,celVer,celLar,celAlt);

``````

Code – Creation path (obj_Enemy):

``````xPlayer=(obj_Player.x div obj_ADM.celLar)*obj_ADM.celLar+obj_ADM.celLar/2;

if(mp_grid_path(global.grid,caminho,x,y,xPlayer,yPlayer,1)){
}
``````

So something similar to the image below occurs:

• Purple Square => enemy
• Black squares => wall

The enemy ends up crossing part of the wall while chasing the player.

This is obviously due to the different size of the grid and the enemy. Because I did a test with the enemy with the size of 20×20 and it worked perfectly.

I changed the size of the grid (which creates the path) to 32×32, and it turned out that instead of crossing the wall, the enemy ends up being far from walls (in some places on the map):

I would like to know how to do so that none of these situations occur. Whatever the size of the enemy.

Video that I used to make the code:

## Raycast checks for collisions between XZ coords without Y / Unity C # rotation

I'm really new to Unity / C # (I have a bit of GML experience but far from being professional) and I'm building my first prototype.

Originally, I copied THIS script to get a cube that turns face to face along one of its bottom edges.

Currently, the state of play is the "rolling" cube on a 10×10 grid. The grid currently has a border of walls. I want the cube to fire a rayCast in the direction the cube is moving, check if there is a wall and decide if the cube can move in that direction.

Here's how I set it up previously:

``````Vector3 up = new Vector3(0, 0, 0.5f);
Vector3 right = new Vector3(.5f, 0, 0);
Vector3 down = new Vector3(0, 0, -0.5f);
Vector3 left = new Vector3(-.5f, 0, 0);
Vector3 currentDirection = Vector3.zero;

bool Valid()
{
Ray myRay = new Ray(transform.position + currentDirection, transform.forward);
RaycastHit hit;

Debug.DrawRay(myRay.origin, myRay.direction, Color.red);
if (Physics.Raycast(myRay, out hit, rayLength))
{
if (hit.collider.tag == "Wall")
{
return false;
}
}
return true;
}
``````

currentDirection is set to when the "WASD" motion keys are pressed. I know that one problem I run into is that transform.forward doesn't work because the Y rotation of my cube never changes.

GIF format is not supported, so here is a link presenting the problem:
Movement and clipping: https://i.imgur.com/XxlEx1G.gifv

Overall, I was wondering how to get the raycast to shoot in the proper direction based on the movement.

Sorry if the answer is incredibly easy and I just miss it.
Thanks for the help,
Kalfin

## geometry – Generation of Tilemap collisions – Tracing of polygons with slopes

I use Godot for my game, but it has an unfortunate quirk with a tilemap collision where physical objects can bounce strangely near tile joints and kinematic bodies can often get stuck in seams as well. For the first alpha work, I was able to work around this by not using the tilemap collision and then drawing the contours by hand … could easily lead to incompatible collision data, I ; therefore decided that this process should be automated.

Tilemaps have different types of tiles – fully solid, diagonal slopes and 2: 1 slopes.

My first attempt was to match each of these types to a half-tile size, marking each vertex as solid or non-solid, then combining all the vertices (with their overlap) into a single grid of vertices. I could then use all of these together by walking along the perimeter and probing forward to detect the corners. It turns out that it works well for convex turns but presents serious problems in concave turns, moreover there is not enough data to correctly detect the slopes, it often results in pieces in additional slope or slightly sloping cuts.

From there, I decided to add additional information to the vertex grid, for example if a vertex is a slope edge and to do some smart things surrounding the properties of its overlap, but that explodes quickly in many specific cases.

I spent much of the day thinking about adding vertex normals to each tile definition, but I realized that this was not going to work without adding a bunch of different types of solidity of tile.

Are there better approaches than I think that don't involve fragile / lossy intermediate representations or ridiculous amounts of special cases?

## unit – How to avoid collisions between instantiated prefabs

I am creating a virtual creature evolution system like here.
I want the crash checks performed at the unit to be as efficient as possible. I want to simulate a large amount of creatures at once (50-200).
I have a prefab of a creature. Each creature is made up of several nodes. The nodes of the same creature must collide with themselves but must not collide with nodes which are in other creatures. What is the most effective way to do it?

I thought about checking the root of the collision object, but it just prevents the collision and does not eliminate the unnecessary checks that are done. I have also looked at solutions involving the "layer collision matrix", but still haven't figured out a way to make it work.

## unreal 4 – Unreal4 – Clothing and physical asset, collisions do not work

I make a character in a blender where there is a character mesh and a simple skirt.

The skirt has a slit of different material, which allows me to use the Unreal Clothing tool. I created the clothing data, applied it, painted it so that the upper part does not move at all and the bottom has 100 "dynamics".

I also created a physical asset, but no matter what parameters I try – the skirt will always go through the thighs as if it did not exist. All colliders are capsules. I also feel like the hip collider actually works. But only this one!

The skirt works perfectly with the wind, which makes it even more bizarre.

Anyone know what can cause this?

## blender – New in 3D at Godot, need help for collisions on slightly complex primitives

I've been using Godot for about 6 months now, I'm working on a different project which is basically a 2D text adventure, so I'm pretty familiar with everything you would expect from someone who knows it, but I am fairly new to 3D. I know how to model primitives in Blender so that they have physics, animate a scene, etc., and I did some basic armature animations.

I'm having a hard time making collisions work on something more complicated than a can. In this POC example, I am trying to make a basic crane controlled by the left stick. I have a long arm working for the front / back after a lot of pain and suffering. I have seen a few articles saying that the best thing to do now with Blender 2.8 and Godot 3.1.2 is to simply export a .glb from Blender and it should just work, but after more than one tutorial, I can't get a collision mesh on any of my imported shapes. Am I doing something wrong there? (None of the tutorials do exactly what I'm trying to do here, but here is an example of the one I watched: https://www.youtube.com/watch?v=CSAl3vgxu4M&t=359s)

Other than that, I will take advice or instructions on how to do what I am looking for. In the image below, I will call the outer frame "Frame", the long red arm "Arm" and the hollowed-out square on the arm "Slider". I had previously tried to create Frame in Blender and import the GLB; I created an animation with a rolling cylinder inside to be sure it had a collision mesh. But when I imported it, I got nothing. So in my POC here, I just built it with primitive StaticBody cubes. As you can see in the picture, Arm and Frame work well together, but Slider doesn't work. (It must do what is shown by the designer in the image.) The cursor must live on the arm and slide left and right along it. In this image, when I launch the game, it is obviously static but I tried other attempts for example RigidBody but the collision mesh is never correct.

I tried to use CSCombiner, a scene with a collection of RigidBodies under a Spatial, and a few other things I could think of, to no avail.

TL; DR: I don't know how to create an appropriate collision mesh on the cursor shape shown. Halp plz? (… and thank you.)

## collision detection – Collisions with rock and player (spaceship)

I'm trying to do when the rock hits the spaceship or the player, it should decrease the health of the health bar but when I run it, it doesn't work. rock randomly decreases health. how can i fix this?

``````# 1 - Import library
``````

import pygame
from pygame.locals import *
import math
randomly import

pygame.init ()
pygame.display.set_caption (& # 39; Rescue mission! & # 39;)
clock = pygame.time.Clock ()
width, height = 840, 680
screen = pygame.display.set_mode ((width, height))
keys = (False, False, False, False)
playerpos = (380,620)
acc = (0,0)
laser beams = ()
objecttimer = 100
objecttimer1 = 0
rocks = ((640,100))
health value = 194
lifeboostertimer = 200
lifeboostertimer1 = 0
lifebooster = ((640,100))

player = pygame.image.load (& # 39; spacecraft.png & # 39;)
background = pygame.transform.scale (background, (840, 680))
rockpic = rockpic1
lifeboost1 = lifeboost

while 1:
objecttimer- = 1
lifeboostertimer- = 1
# 5 – Clear the screen before drawing it again
screen.fill (0)

``````# 6 - putting the images of the game on screen

screen.blit(background,(0,0))
#screen.blit(lifeboost, (100,100))

position = pygame.mouse.get_pos()
angle = math.atan2(position(1)-(playerpos(1)+32),position(0)-(playerpos(0)+26))
playerrot = pygame.transform.rotate(player, 360-angle*57.29)
playerpos1 = (playerpos(0)-playerrot.get_rect().width/2, playerpos(1)-playerrot.get_rect().height/2)
screen.blit(playerrot, playerpos1)

for bullet in laserbeams:
index=0
velx=math.cos(bullet(0))*10
vely=math.sin(bullet(0))*10
bullet(1)+=velx
bullet(2)+=vely
if bullet(1)<-64 or bullet(1)>840 or bullet(2)<-64 or bullet(2)>680:
laserbeams.pop(index)
index+=1
for projectile in laserbeams:
laserbeam1 = pygame.transform.rotate(laserbeam, 360-projectile(0)*57.29)
screen.blit(laserbeam1, (projectile(1), projectile(2)))
# Draw Rocks
if objecttimer==0:
rocks.append((840, random.randint(50,430)))
objecttimer=90-(objecttimer1*2)
if objecttimer1>=35:
objecttimer1=35
else:
objecttimer1+=6
index=0
for rock in rocks:
if rock(0)<-1:
rocks.pop(index)
rock(0)-=7
# - Attack castle(change to Attack spaceship later on)
rockrect=pygame.Rect(rockpic.get_rect)
playerrect = pygame.Rect(player.get_rect)
rockrect.top=rock(1)
rockrect.left=rock(0)

if rockrect.colliderect(playerrect):
healthvalue -= random.randint(5,20)

rocks.pop(index)
# Check for collisions
index1=0
#index3=0
for bullet in laserbeams:
bullrect=pygame.Rect(laserbeam.get_rect())
bullrect.left=bullet(1)
bullrect.top=bullet(2)

if rockrect.colliderect(bullrect):
acc(0)+=1
rocks.pop(index)

laserbeams.pop(index1)

index1+=1
index += 1

# Next Rock

#index+=1
#for rock in rocks:
#screen.blit(rockpic,rock)

# Draw 1-UP image
if lifeboostertimer==0:
lifebooster.append((840, random.randint(50,430)))

lifeboostertimer=1000-(lifeboostertimer1*1)
if lifeboostertimer1>=15:
lifeboostertimer1=15

else:
lifeboostertimer1+=3
index2=0

# Makes object move
for lifeboost in lifebooster:
if lifeboost(0)<-1:
lifebooster.pop(index2)
#speed of 1-UP
lifeboost(0)-=7

screen.blit(lifeboost1,lifeboost)

lifeboosterrect=pygame.Rect(lifeboost1.get_rect())
lifeboosterrect.top=lifeboost(1)
lifeboosterrect.left=lifeboost(0)
#if lifeboosterrect.left<1:
#healthvalue += random.randint(5,20)

# Check for collisions (if hit for lifebooster give more health)
#index=0

#index2=0
index3=0

for bullet in laserbeams:
bullrect=pygame.Rect(laserbeam.get_rect())
bullrect.left=bullet(1)
bullrect.top=bullet(2)

if lifeboosterrect.colliderect(bullrect):
acc(0)+=1
lifebooster.pop(index2)
laserbeams.pop(index3)
print ("rock poped")
healthvalue += random.randint(5,20)
index3+=1
``````

# - Next 1-UP image
# index2 + = 1 # can probably take this line and the next line
#for lifeboost in lifebooster:
screen.blit (lifeboost1, lifeboost)
index + = 1
for rock in rocks:
screen.blit (rockpic, rock)

``````# 6.4 - Draw clock
font = pygame.font.Font(None, 24)
survivedtext = font.render(str((90000-pygame.time.get_ticks())/60000)+":"+str((90000-pygame.time.get_ticks())/1000%60).zfill(2), True, (0,0,0))
textRect = survivedtext.get_rect()
textRect.topright=(635,5)
screen.blit(survivedtext, textRect)

# 6.5 - Draw health bar
screen.blit(healthbar, (5,5))
for health1 in range(healthvalue):
screen.blit(health, (health1+8,8))

# 7 - update the screen
pygame.display.flip()
clock.tick(60)
# 8 - loop through the events
for event in pygame.event.get():
#print (event)
# check if the event is the X button
if event.type==pygame.QUIT:
pygame.quit()
exit(0)

# if it is quit the game
if event.type == pygame.KEYDOWN:
if event.key==K_UP:
keys(0)=True

elif event.key==K_LEFT:
keys(1)=True

elif event.key==K_DOWN:
keys(2)=True

elif event.key==K_RIGHT:
keys(3)=True
if event.type == pygame.KEYUP:
if event.key==pygame.K_UP:
keys(0)=False
elif event.key==pygame.K_LEFT:
keys(1)=False
elif event.key==pygame.K_DOWN:
keys(2)=False
elif event.key==pygame.K_RIGHT:
keys(3)=False
if event.type==pygame.MOUSEBUTTONDOWN:
position=pygame.mouse.get_pos()
acc(1)+=1
laserbeams.append((math.atan2(position(1)-(playerpos1(1)+32),position(0)-(playerpos1(0)+26)),playerpos1(0)+32,playerpos1(1)+32))

# 9 - Move player
if keys(0):
playerpos(1)-=5
elif keys(2):
playerpos(1)+=5
if keys(1):
playerpos(0)-=5
elif keys(3):
playerpos(0)+=5
``````

## ab testing – How important is it to avoid A / B test collisions?

Let's say you have 3 A / B tests as such

1. Control vs A
2. Control vs B
3. Control vs C

Unless you are specifically working to ensure that the tests do not collide (run on top of each other), you will end up with populations of users who will see both A + B, B + C, A + B + C.

Technically, because if you look at the results of experiment 1, Control and A will see an equal number of pollution of 2 and 3, so the only difference in performance between 1. Control and A should only be the impacts of AT.

Thoughts? Is it always better to avoid collisions or can we just assume, as long as the pollution is evenly distributed, that we are good?

## Filtering collisions with the help of Python and Box2D

I'm trying to filter the collisions occurring in my Box2D world by replicating this example: https://github.com/pybox2d/pybox2d/blob/master/examples/collision_filtering.py

I have four classes in my world, Car, Wheel, Building and Pedestrian, I want to filter which instance has collided with which and one of the possible outputs is (pseudo-code)

``````if contact.FixtureA.isinstance(Pedestrian) and contact.FixtureB.isinstance(Car):
print("You have caused a traffic accident")
``````

I have this CollisionFiltering class:

``````class CollisionFiltering():
SMALL_GROUP = 1
LARGE_GROUP = -1

CAR_CATEGORY = 0X0002
WHEEL_CATEGORY = 0X0004
PEDESTRIAN_CATEGORY = 0X0008
BUILDINGS_CATEGORY = 0X009

def __init__(self):
super(CollisionFiltering, self).__init__()
world = box2world

box2world = world(gravity =(0.0, 0.0), doSleep =True)
``````

and I apply this in given classes (only the class wheel is shown as an example):

``````class Wheel():
def __init__(self, box2world, phi, max_lateral_impulse =1, shape =(0.25,0.75), turn_torque =15000, position =None):

if position == None:
position = (POS_X, POS_Y)

self.position = position
self.shape = shape
self.box2world = box2world
self.phi = phi
self.max_lateral_impulse = max_lateral_impulse
self.turn_torque = turn_torque
self.wheel = self.box2world.CreateDynamicBody(position =(self.position(0), self.position(1)),
angle =self.phi,
fixtures =b2FixtureDef(
shape=b2PolygonShape(box = shape),
density=650.0,
friction =10000,
filter = b2Filter(
groupIndex=CollisionFiltering.SMALL_GROUP,
categoryBits=CollisionFiltering.WHEEL_CATEGORY,
)))
``````

I then connect four wheels to the bodywork of a car, then draw the bodies and run the world using pygame

But I do not know how to continue, how could I use the CollisionFilterring class to be able for example to print the phrase on the accident from above?

thank you so much

Edit: I've tried this too: but it does not work (it does not matter)

``````class myContactListener(b2ContactListener):
def __init__(self):
b2ContactListener.__init__(self)
def BeginContact(self, contact):
fixture_a = contact.fixtureA
fixture_b = contact.fixtureB

body_a, body_b = fixture_a.body, fixture_b.body
ud_a, ud_b = body_a.userData, body_b.userData
pedestrian = None
car = None
for ud in (body_a, body_b):
if isinstance(ud, Pedestrian):
pedestrian = ud
elif isinstance(ud, Car):
car = ud

if car is not None and pedestrian is not None:
if began:
print("It does stuff")
else:
print("It does something")
def EndContact(self, contact):
pass
def PreSolve(self, contact, oldManifold):
pass
def PostSolve(self, contact, impulse):
pass

box2world = world(contactListener=myContactListener(),gravity =(0.0, 0.0), doSleep =True)

I also edited my StackOverflow question hoping to solve my problem faster
$$```$$
``````

## Elastic collisions in 2D Unity

I'm trying to create elastic collisions in the game 2d in unity. I have a ball surrounded by a polygon collider and I calculate the reflected vector using the velocity of the ball and the normal at the point of contact. Everything works, but I have a small problem where the ball gets stuck sometimes.As you can see below, the ball bounces but later it stops

Here are some details about the implementation.

The ball is a circle collider and I drew the object with the help of a line rendering and I added a polygon collider using the width of the line. The Polygon Collider consists of about 130 points.

The bullet has its collision detection mode set to continuous, but the use of the discreet mode does not work either.

The speed of the ball is not the problem because I face the same problem even if I move the ball at lower speeds. I use Vector3.AddForce to move the ball. The force mode is ForceMode.Impulse.

Any help will be greatly appreciated. Thank you for your time.

Below you can find the code.

``````    void Start()
{
rb = Transfrom.GetComponent();
velocity = rb.velocity;
}

private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Wall")
{

float speed = velocity.magnitude;
Vector3 direction = Vector3.Reflect(velocity.normalized, collision.contacts(0).normal);
rb.velocity = direction * speed;
}
}
``````