Dream Of Sleeping Posted December 6, 2014 Share Posted December 6, 2014 I'm having all sorts of weird issues with collision. Do I set the sprite.x and sprite.y when I need to position it? Because setting the sprite.body.x often doesn't seem to work. If I alter the sprite.x and the move the body.x do I take into consideration the anchor being centered in the sprite? Do I set the body.x - the sprites half width? Link to comment Share on other sites More sharing options...
Dream Of Sleeping Posted December 6, 2014 Author Share Posted December 6, 2014 I'm updating the sprite.x then checking for collisions, but when I check the body.x after altering sprite.x it just says 0. I'm trying to work out a good position for pickups so I place the pickup somewhere then I check for collisions and if it hits something I move it. Link to comment Share on other sites More sharing options...
spencerTL Posted December 6, 2014 Share Posted December 6, 2014 i don't think you should manually be positioning sprite or body when collisions could be taking place. I think you should be using velocity so you are working with the physics system and not against it. Link to comment Share on other sites More sharing options...
Dream Of Sleeping Posted December 6, 2014 Author Share Posted December 6, 2014 But surely there are times when you need to move something. What if a character teleported? What if you needed to make sure he didn't teleport into anything? Link to comment Share on other sites More sharing options...
Dream Of Sleeping Posted December 6, 2014 Author Share Posted December 6, 2014 If I don't figure out how to do this. I don't think I will be able to finish. This will be the first time I've failed at a game jam. Please, can anybody help? Link to comment Share on other sites More sharing options...
Dream Of Sleeping Posted December 6, 2014 Author Share Posted December 6, 2014 Now I'm trying the sprite.intersect method instead. It's always coming back true. I'm even printing out the x and y values right afterwards and they are on opposite ends of the screen, yet it still comes back true. Link to comment Share on other sites More sharing options...
spencerTL Posted December 6, 2014 Share Posted December 6, 2014 There are much better people than me at this sort of thing but as a suggestion if you need to move the sprite outside the physics could you kill it and then revive it in the correct place. This sort of thing happens all the time in sprite pooling so should work. If anything is placed where two bodies interest though they'll whizz off. (They do in P2 anyway). When I had this I always calculated a point a set distance and rotation from one of the sprites so that the two bodies would not intersect when the new one was added.I hope this is some help or that somebody with a better idea contributes.EDIT:This thread incicates that what you are doing will have weird effects:http://www.html5gamedevs.com/topic/3258-cant-set-xy-of-sprites-only-velocity/ Link to comment Share on other sites More sharing options...
Dream Of Sleeping Posted December 6, 2014 Author Share Posted December 6, 2014 Thank you very much for replying. I'm actually starting to really depressed about this, so I might just not finish this time. I wish I'd used create js now. That thread was useful thank you. If I do continue in the morning will just have to write my own functions to test collision. I can't possibly understand why the sprite. intersect method always returns true. Link to comment Share on other sites More sharing options...
spencerTL Posted December 9, 2014 Share Posted December 9, 2014 I know too late but I've just been doing something similar and I've found that body.reset(x,y) moves the sprite and body to a new position without any problems. Graphei 1 Link to comment Share on other sites More sharing options...
Recommended Posts