Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

How do you get the GPS position of your character?

Discussion in 'Programming (In-game)' started by pcsagan, Mar 14, 2019.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. pcsagan Trainee Engineer

    Messages:
    3
    I've looked at the source code and tried to find working examples, but I just can't seem to get the position of my character. How do you make this code work?

    public override void UpdateAfterSimulation()
    {
    if (!MyAPIGateway.Input.IsNewKeyReleased(MyKeys.F8))
    return;

    MyAPIGateway.Utilities.ShowNotification(..., 10000, MyFontEnum.White);
    // I've tried 40 different things here like Sandbox.ModAPI.IMyEntity.GetPosition().ToString()
    }

    Thanks.
     
  2. Digi Senior Engineer

    Messages:
    2,372
    This sounds like it's for modding, wrong subforum then :p

    MyAPIGateway.Session.Player.Character gets the local player's character.
    On DS side that will throw an error because Player is null.

    Or MyAPIGateway.Session.ControlledObject to get character/seat/cryo/cockpit/RC/turret/etc they're *controlling* (not necessarily *in*, because you can be in a cockpit and control an RC, in that case this property will return the RC).
     
  3. Mollymawk Trainee Engineer

    Messages:
    91
    It does look like a mod question. But just in case you are talking in game scripts (and don't get cross if this is zero help):

    In the past, I have used several sensors to detect my location and use that location to point a spot light on two rotors, the light following me around the base.
    very useful for a base in an asteroid cavity.
    I've also tried this using a small chain of hinges with a spotlight on the end. adds a very war of the worlds look to your lighting. I tried this with a gattling gun too but Klang was very unhappy and it would explode for no reason.
    also it would get stuck shooting the same dead spider.
     
  4. Ronin1973 Master Engineer

    Messages:
    4,682
    For in-game scripts within the programmable block, there's no way to detect the players location without some help. Space Pirates and NPCs can located the nearest player without any help: GetNearestPlayer or something like that.

    You can detect the location of a player using a sensor block. But that's only if the player is within 50 meters of the sensor. You can also detect if a cockpit or flight seat is occupied then get the location of that block. The only other way I think that's possible is raycasting. But players are really small and the camera raycast would have a difficult time detecting the location of a player at-large. If you can confine the player to a hallway or confined space, maybe it'll work.
     
  5. Wicorel Senior Engineer

    Messages:
    1,241
    Another way to detect an enemy player is with a turret.
     
Thread Status:
This last post in this thread was made more than 31 days old.