Jump to content

Object always facing KSPs main camera - HELP regarding script


Recommended Posts

Basically, what I'm trying to do is to get an object (any) to always face the main camera in KSP, respectively *you*.

If any is not clear enough, it really can be anything, a sphere, a cube, whatever. Setting pivots is not a problem by the way.

Is it something simple like this?

var camera : Transform;

function Start() {

camera = GameObject.FindWithTag("FlightCamera").transform;

}

function Update() {

transform.LookAt(camera);

}

Or is find not even required?

What about something along these lines:

var cam : FlightCamera;

function Update() {

transform.LookAt(cam.transform);

}

As far as I'm aware the object has to be placed so that the top points towards Y+, that would be facing up in relativity to the target, and Z+ would define the direction that's facing towards the reference object.

Questions:

  • Under what reference is KSPs camera tagged anyway? Is it "FlightCamera"?
  • Can I even refer to it and how?
  • And how am I going to set up target in Unity then?

MOST IMPORTANTLY:

  • How do I get this to work? :confused:

Thanks in advance for any help, if any. ;)

EDIT: Script language isn't that important, although I guess Javascript is to be favoured.

Edited by slumpie
Link to comment
Share on other sites

No, it's about adding a new behaviour script to a gameobject, which defines how its rotation relativ to another gameobject has to be.

I can target another gameobject in the same scene in a relatively simple manner, but I don't know how it's done if the ressources are external, respectively internal in KSP. The actual question is how I can target the main camera without having it in the loaded Unity Scene (which I can't, can I? Possibly an empty gameobject that's linked to it and acts as a placeholder? I don't know how it's handled in Unity).

Behaviour scripts are added as components to gameobjects, that's why this thread is in the Modelling and Texturing Discussion Forum.

On the dynamics of modelling and texturing rocket parts and other related things.

Or am I wrong?

Edited by slumpie
Link to comment
Share on other sites

The main camera in the flight scene can be accesses via

FlightCamera.fetch.mainCamera

I suspect that

yourObject.transform.LookAt(FlightCamera.fetch.mainCamera.transform.position)

will work (with appropriate syntax checking).

D.

Link to comment
Share on other sites

The main camera in the flight scene can be accesses via
FlightCamera.fetch.mainCamera

I suspect that

yourObject.transform.LookAt(FlightCamera.fetch.mainCamera.transform.position)

will work (with appropriate syntax checking).

D.

No that just doesn't work. If I do it that way then the part doesn't even show up.

I can't even tell how many variations I tried...

Most of the time the part loaded just fine (different code but with FlightCamera.fetch.mainCamera), but never rotated.

By the way the game crashed two times because of "mono.dll caused an Access Violation"

Edited by slumpie
Link to comment
Share on other sites

:0.0:

Sooo KSP basically just says f that Unity function and doesn't want any srcripts bound to gameobjects?

Quite shocking I must say... and embarassing on my end. I bet I should've noticed that.

Even as a bloody newbie

:blush:

I'll try that and let you know if it works as a plugin, thanks.

EDIT: Although that doesn't really explain why it caused the part not to show up or even crash the game...

Edited by slumpie
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...