collision

Properly attach to a GameObject after collision?

ε祈祈猫儿з 提交于 2019-12-08 19:18:58
问题 How can I properly make a GameObject attach (or "stick") to another GameObject after collision? The problem: I want the GameObject to attach after collision even if it is changing scale. "Attach on collision" code: protected Transform stuckTo = null; protected Vector3 offset = Vector3.zero; public void LateUpdate() { if (stuckTo != null) transform.position = stuckTo.position - offset; } void OnCollisionEnter(Collision col) { rb = GetComponent<Rigidbody>(); rb.isKinematic = true; if(stuckTo ==

Collisions aren't registering with Python Turtles

China☆狼群 提交于 2019-12-08 14:20:24
问题 I'm creating a simple 2D shooter following an online tutorial, and the enemy sprites (except 1, there are 5 total) are not abiding by my collision code. Everything works except the bullet object that the player controls simply passes right through the enemy sprites. Error messages I received: Traceback (most recent call last): File "C:\Python\Python36\pygame projects\space invaders.py", line 163, in <module> bullet.hideturtle() File "C:\Python\Python36\lib\turtle.py", line 2322, in hideturtle

How to make a random position whenever I start running the program?

廉价感情. 提交于 2019-12-08 13:43:14
问题 I have an image which moves in a random direction. My problem is everytime I start running the program, the image always appear at the upper-left corner and moves a diagonal direction and after hitting the wall, it starts to move random direction. How can I make the image appear in a random position everytime I execute or run the program? Any help would be much appreciated... Here's the code: public class Ball extends JPanel implements Runnable { private Image ball; private Thread animator;

converting an image to a rect

旧时模样 提交于 2019-12-08 12:52:28
问题 this script spawns a alien that follows the player, i just want to know how to make the alien (nPc) and the player (mouse_c) a rect so i make the alien kill the player when the imagers overlap. any help would really help thanks import pygame, sys, random, time, math from pygame.locals import * pygame.init() bifl = 'screeing.jpg' milf = 'character.png' alien = 'alien_1.png' screen = pygame.display.set_mode((640, 480)) background = pygame.image.load(bifl).convert() mouse_c = pygame.image.load

HTML Canvas and JavaScript rotating objects with collision detection

▼魔方 西西 提交于 2019-12-08 11:50:13
问题 I'm creating a game with JavaScript and HTML Canvas. It's a multiplayer 2D game with tanks that try to hit each other. The tanks can move as well as rotate. How can you figure out collision detection with rotating rectangular objects? I know, I could make them square and use circular detection, but it looks very messy when a tank runs into a wall. Thanks for all who try to help :) 回答1: Move hit point to local space First an alternative There are many ways you can do it. The simplest way. When

Collision detection leading to color detection? [duplicate]

和自甴很熟 提交于 2019-12-08 09:34:32
问题 This question already exists : Do an SKAction if the colors of two sprites aren't the same? [duplicate] Closed 3 years ago . How can I check if, when I collide with an SKSpriteNode in the middle of two rectangles with a ball, the ball and the two rectangles are the same color? For example, if my two rectangles are red, and my ball is blue, I want it to detect that the colors of my rectangle and the ball are different. If they are the same color, then I don't want anything to happen. If they

Why does collision work properly for convex polygon based physicsBody but touchesMoved doesn't

青春壹個敷衍的年華 提交于 2019-12-08 09:33:21
问题 I setup an SKSprite (s1) to have physicsBody with polygon from path: s1.physicsBody = [SKPhysicsBody bodyWithPolygonFromPath:path]; and the other one (s2) has physicsBody generated from its surrounding rectangle: s2.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:e.size]; and the collisions of the two sprites are fine, they only happen when the actual pixels from the s1's polygon path and surrounding rectangle from the s2 collide (and not the surrounding rectangles from each of the

hash collision and appending data

梦想与她 提交于 2019-12-08 09:11:27
Assume I have two strings (or byte arrays) A and B which both have the same hash (with hash I mean things like MD5 or SHA1). If I concatenate another string behind it, will A+C and B+C have the same hash H' as well? What happens to C+A and C+B? I tested it with MD5 and in all my tests, appending something to the end made the hash the same, but appending at the beginning did not. Is this always true (for all inputs)? Is this true for all (well-known) hash functions? If no, is there a (well-known) hash function, where A+C and B+C will not collide (and C+A and C+B do not either)? (besides from

find a way of fixing wrong collision normals in edge collisions

早过忘川 提交于 2019-12-08 05:57:37
问题 The main problem is that Bullet 2 (2.82, to be specific - and perhaps Bullet 3 too, haven't checked it yet) processes edge collisions lousily, generating skewed reaction normals. Test case 1: a small btBoxShape , positioned (0,9,0), aligned vertically, falls onto another box's (made from btBoxShape also) face, coaligned. The normal is computed properly, the collision happens only in Y (vertical) axis. The box slightly bounces on OY axis and stays centered around it. Test case 2: a small box,

How to fix circles overlap in collision response?

南笙酒味 提交于 2019-12-08 05:48:31
问题 Since in the digital world a real collision almost never happens, we will always have a situation where the "colliding" balls overlap. How to put back balls in situation where they collide perfectly without overlap? I would solve this problem with a posteriori approach (in two dimensions). In short I have to solve this equation for t: Where: is a number that answers to the question: how many frames ago did the collision happen perfectly? is the center of the first ball is the center of the