I’m trying to get values or calculate an equalivalent type value to determine which direction (compass degrees) the user is facing and holding their device towards, so I can orient the game world along their relevant axis.
It seems like this would be fairly simple to do based of the readings from the iphone magenetometer or compass heading, but I can’t seem to find any documentation about accessing or calling those features in UE.
Does anyone have any tips for where to begin approaching this? I figure the answer will stretch beyond blueprints, but I’m curious how involved this could become?
can someone tell me why are there almost no valuable Information about this topic? It seems like nobody can answer this question. I searched for hours and nowhere I can find some answer leading in a possible direction. But I found some links which are interesting, although I´m sure that anybody who wants to know how we can access the Compass will get to this sooner or later. It´s kind of sobering.
I found the solution some time ago by ReImplementing the LocationServices - Plugin written by Epic and extended it with the appropriate Objective-C - Code.
You can take a look at “LocationServicesIOSImpl.cpp” from the Engine-Source for example-code.
I didn´t know how Objective-C works before: here is a good way to start:
-(void)startUpdatingHeading
{
LocManager = [[CLLocationManager alloc] init];
LocManager.delegate = self;
if([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined)
{
//we need to request location services
//[LocManager requestAlwaysAuthorization];
[LocManager requestWhenInUseAuthorization];
}
if([ CLLocationManager headingAvailable])
{
LocManager.headingFilter = 5;
// we also need to deliver LocationUpdates, why? i do not know, but it´s recommended in the apple documentation, maybe it´s a parent service ?
[LocManager startUpdatingLocation];
[LocManager startUpdatingHeading];
}
}
-(void)stopUpdatingHeading
{
if([ CLLocationManager headingAvailable])
{
[LocManager stopUpdatingLocation];
[LocManager stopUpdatingHeading];
[LocManager release];
LocManager = nil;
}
}
/*
* Callback from the LocationManager when there is an update to our Heading
*/
-(void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
if(newHeading.headingAccuracy < 0)
{
return;
}
//use Heading if its valid
CLLocationDirection theHeading = ((newHeading.trueHeading > 0) ?
newHeading.trueHeading : newHeading.magneticHeading);
FHeadingServicesData headingData;
headingData.MagneticHeading = (float)theHeading;
// and broadcast this to Unreal
UHeadingServicesBPLibrary::GetHeadingServicesImpl()->OnHeadingChanged.Broadcast(headingData);
I came back to ask this same question from nearly 3 years later and was so thankful to see your reply. The ue4 community is the best!! this solution works 100%, appreciate it!
I’m clearly doing something wrong. I’m also attempting to do the above, but seem to be stuck.
I’ve included location updates in the plist file , made sure to requestwheninuseauthorization, initialized and startupdatinglocation and startupdatingheading but for no apparent reason, iOS events are simply not getting called.
Neither didchangeauthorizationstatus; didupdateheading; nor didupdatelocations get called ever.
What am I doing wrong?