I know this is not the first time this question has been asked of a physics engine, but I have been unable to make this work in Cocos 3.1 (iphone / swift)
I am making a physics based driving game, and when my vehicle is in the air I want the gas and brake to add a little rotation to the vehicle so you can control its angle. I have the collisionType for the wheels set to "wheel" and I have a CCNode based class acting as a delegate listening for:
-(void)ccPhysicsCollisionPostSolve:(CCPhysicsCollisionPair )pair wheel:(CCNode )nodeA wildcard:(CCNode *)nodeB {
this gets called fine, and my plan was to set a variable to true in this method, but can not figure out where to reset the property for each cycle.
I tried adding an -(void)update:(CCTime)delta method, but it does not get called (which i find odd, I assumed this was all I would need to do in V3.1
Thanks in advance.
Cocos2d V3.1 Vehicle touching ground?
-
- Posts: 4
- Joined: Tue Jul 22, 2014 4:17 pm
- Contact:
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Cocos2d V3.1 Vehicle touching ground?
I came across your question on Stack Overflow first:
http://stackoverflow.com/questions/2527 ... 3#25287563
It is a bit weird that your -update method does not get called. That's best asked on the Cocos forums though.
http://stackoverflow.com/questions/2527 ... 3#25287563
It is a bit weird that your -update method does not get called. That's best asked on the Cocos forums though.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 4
- Joined: Tue Jul 22, 2014 4:17 pm
- Contact:
Re: Cocos2d V3.1 Vehicle touching ground?
Thanks, you are very quick.
I resolved the update issue (I had not added the node to the parent, so update was not being called), but I am still having issues with the class. ccPhysicsCollisionSeparate is never called, so as a result if I leave out the update _wheelContacts just climbs by two at a time forever. When I add a reset into the update (_wheelContacts = 0) whenever I check for _wheelContacts I get a 0.
#import "PKTruckCollisionDelegate.h"
@implementation PKTruckCollisionDelegate {
int _wheelContacts;
}
@synthesize wheelContacts;
-(id)init {
if(self = [super init]) {
_wheelContacts = 0;
}
return self;
}
-(void)ccPhysicsCollisionPostSolve:(CCPhysicsCollisionPair *)pair truckWheel:(CCNode *)nodeA wildcard:(CCNode *)nodeB {
_wheelContacts ++;
}
-(void)ccPhysicsCollisionSeparate:(CCPhysicsCollisionPair *)pair truckWheel:(CCNode *)nodeA typeB:(CCNode *)nodeB {
CCLOG(@"seperate");
_wheelContacts --;
}
-(void)update:(CCTime)delta {
_wheelContacts = 0;
}
@end
I resolved the update issue (I had not added the node to the parent, so update was not being called), but I am still having issues with the class. ccPhysicsCollisionSeparate is never called, so as a result if I leave out the update _wheelContacts just climbs by two at a time forever. When I add a reset into the update (_wheelContacts = 0) whenever I check for _wheelContacts I get a 0.
#import "PKTruckCollisionDelegate.h"
@implementation PKTruckCollisionDelegate {
int _wheelContacts;
}
@synthesize wheelContacts;
-(id)init {
if(self = [super init]) {
_wheelContacts = 0;
}
return self;
}
-(void)ccPhysicsCollisionPostSolve:(CCPhysicsCollisionPair *)pair truckWheel:(CCNode *)nodeA wildcard:(CCNode *)nodeB {
_wheelContacts ++;
}
-(void)ccPhysicsCollisionSeparate:(CCPhysicsCollisionPair *)pair truckWheel:(CCNode *)nodeA typeB:(CCNode *)nodeB {
CCLOG(@"seperate");
_wheelContacts --;
}
-(void)update:(CCTime)delta {
_wheelContacts = 0;
}
@end
-
- Posts: 4
- Joined: Tue Jul 22, 2014 4:17 pm
- Contact:
Re: Cocos2d V3.1 Vehicle touching ground?
I just updated the separate method to use wildcard and now it is being called. The problem is separate is being called at the correct time (when the wheels leave the ground) but the collisionPostSolve method is being called what looks like every frame (maybe because the wheels are rolling?)
here is the updated, and working, ccPhysicsCollisionSeparate method:
-(void)ccPhysicsCollisionSeparate:(CCPhysicsCollisionPair *)pair truckWheel:(CCNode *)nodeA wildCard:(CCNode *)nodeB {
CCLOG(@"seperate");
_wheelContacts --;
}
here is the updated, and working, ccPhysicsCollisionSeparate method:
-(void)ccPhysicsCollisionSeparate:(CCPhysicsCollisionPair *)pair truckWheel:(CCNode *)nodeA wildCard:(CCNode *)nodeB {
CCLOG(@"seperate");
_wheelContacts --;
}
-
- Posts: 4
- Joined: Tue Jul 22, 2014 4:17 pm
- Contact:
Re: Cocos2d V3.1 Vehicle touching ground?
I just realized this post is totally in the wrong forum. Should I create a new version in the other forum?
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Cocos2d V3.1 Vehicle touching ground?
Hey sorry. Have been busy with work and haven't been checking the forums. (again...)
There are 4 collision events begin, pre-solve, post-solve and separate. You want to be using begin and separate. Post-solve is called every frame after running the solver so you can find out how much force was applied between two objects.
There are 4 collision events begin, pre-solve, post-solve and separate. You want to be using begin and separate. Post-solve is called every frame after running the solver so you can find out how much force was applied between two objects.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Who is online
Users browsing this forum: No registered users and 1 guest