collision

cocos2d v3 collision detection

橙三吉。 提交于 2019-12-02 07:11:59
I'm trying to inspect collision collision of two bodies, but collision detection callbacks are not being fired. Here is my code: 1) My CCScene implements CCPhysicsCollisionDelegate protocol 2) I set collision delegate for physics _physics = [CCPhysicsNode node]; _physics.gravity = PHYSICS_GRAVITY; _physics.debugDraw = YES; _physics.collisionDelegate = self; [self addChild:_physics]; 3) For each of two body I set a collision type body1.collisionType = @"body1"; body2.collisionType = @"body2"; 4) That's it, when these two bodies collide none of CCPhysicsCollisionDelegate callback methods is

How to detect collision between objects in Pygame?

别说谁变了你拦得住时间么 提交于 2019-12-02 06:40:57
I'm making a sidescrolling game in Pygame, and if the fox sprite collides with the tree, it is supposed to print "COLLIDE". But it doesn't work. How can I fix this to detect collision between the fox and the tree? Here's the code: if foxsprite1 > xtree and foxsprite1 < xtree + treewidth or foxsprite1 + treewidth > xtree and foxsprite1 + treewidth < xtree + treewidth: print ("COLLIDE") xtree is the x coordinate of the tree, treewidth is the width of the tree, and foxsprite1 is the fox. Keep object position and size as pygame.Rect() fox_rect = pygame.Rect(fox_x, fox_y, fox_width, fox_height)

Vanilla JS Div Collision Detection

折月煮酒 提交于 2019-12-02 05:13:52
My implementation of the following can be found on jsfiddle.net I have four divs. My goal is to make them draggable around the page but NOT to allow them to overlap one another. Each can be dragged around the page with a mousemove listener. container.addEventListener('mousemove',mouseMove); function mouseMove(e) { if (!mouseDown) {return;} let coords=e.target.getBoundingClientRect(); let movX=e.movementX; let movY=e.movementY; if (!collision(movX,movY,e.target.classList[1],coords)){ e.target.style.left=`${coords.left+movX}px`; e.target.style.top=`${coords.top+movY}px`; } } My collision

OnTriggerEnter2D is not being called

情到浓时终转凉″ 提交于 2019-12-02 04:56:10
I am trying to make a replica of Asteroids in Unity. The problem is that my bullets are not triggering the OnTriggerEnter2D method on the asteroids. The asteroids have the following script attached: using UnityEngine; using System.Collections; public class Asteroid : MonoBehaviour { void Start () { print ("class initiated"); } void onTriggerEnter2D (Collider2D collider) { Debug.Log (collider); } } The bullet GameObject has Is Kinematic and Is Trigger enabled, and has Rigidbody 2D and Box Collider 2D attached. The asteroid GameObject has Rigidbody 2D and Circle Collider 2D, and Is Kinematic and

Consequences of hashcode overflow on Java String

巧了我就是萌 提交于 2019-12-02 00:14:18
问题 I've been reading a bit about Java String class' hashcode here recently, and I haven't been able to find this information : what happens when string's length is higher than 32 (I know an overflow then happens, but as a hash key, what happens)? For example, I need to hash strings that are between 20 and 120 characters long to use them as hash keys. Do I need to implement my own algorithm using BigInteger? Also, since I might have between 30k and 80k strings, maybe more, is usual String

Unity GUIText on Collision c#

断了今生、忘了曾经 提交于 2019-12-01 23:23:18
I'm writing a 3D maze program in C# and I need to have UI Text display "You Win!" When the player reaches the end of the maze. I have a trigger set up in Unity as a cube, named FinishLine, and I have the UI text named winText I'm getting an error on this line.. GUI.Box(New rect (10,10,100,90), winText); the error is "The best overloaded method matfch for unityengine.gui.box (unityEngine rect, string)' has some invalid arguments I also have no idea what those numbers are (10,10,100,90), so maybe that's messing something up? What are those values indicating...? Here is my code.. public class

Do keys with different hashes also get mapped to the same index in HashMap?

跟風遠走 提交于 2019-12-01 21:26:40
问题 Looking at the code specifically line 393, it looks like different hashes have been mapped to same index. I had an understanding that the hashcode is used to determine what bucket in a HashMap is to be used, and the bucket is made up of a linked list of all the entries with the same hashcode. They why have the e.hash == hash check ? public V put(K key, V value) { if (key == null) return putForNullKey(value); int hash = hash(key.hashCode()); int i = indexFor(hash, table.length); for (Entry e =

Bouncing a ball off a surface

倖福魔咒の 提交于 2019-12-01 20:29:08
问题 I'm currently in the middle of writing a game like Breakout, and I was wondering how I could properly bounce a ball off a surface. I went with the naive way of rotating the velocity by 90 degrees, which was: [vx, vy] -> [-vy, vx] Which (unsurprisingly) didn't work so well. If I know the position and veocity of the ball, as well as the point the ball would hit (but is going to instead bounce off of) how can I bounce it off that point? Constraints: I'm using integer math (No FP anywhere) All my

Bouncing a ball off a surface

帅比萌擦擦* 提交于 2019-12-01 19:46:36
I'm currently in the middle of writing a game like Breakout, and I was wondering how I could properly bounce a ball off a surface. I went with the naive way of rotating the velocity by 90 degrees, which was: [vx, vy] -> [-vy, vx] Which (unsurprisingly) didn't work so well. If I know the position and veocity of the ball, as well as the point the ball would hit (but is going to instead bounce off of) how can I bounce it off that point? Constraints: I'm using integer math (No FP anywhere) All my surfaces are simple flat surfaces (Vertical, horizontal, or a block) I only want to bounce off in a 90

Detecting whether two divs overlap [duplicate]

我的梦境 提交于 2019-12-01 18:08:49
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: How to detect if two divs touch with jquery? I've spent a lot of time trying to figure out how to detect if two divs are overlapping. I tried the gamequery plugin and used it like this: $("#" + checkform).collision("#" + checkform + "w").each(function(){ alert("Collision"); }); Would you use the gamequery plugin and/or how would you do it? 回答1: There is already a query here having an answer : How to detect if