Creating and Using Cameras
-
Hello, Does anyone know how to create cameras. Then be able to set that as the camera that you use in the game. I want to put a camera to a prop I've been trying for about an hour now. Any tips or lines of code would be nice.
-
Camera NewCamera = World.CreateCamera(Game.Player.Character.GetOffsetInWorldCoords(new Vector3(0f, 10f, 5f)), new Vector3(0f,0f,0f), 50f);
NewCamera.PointAt(Game.Player.Character);
World.RenderingCamera = NewCamera;
World.CreateCamera requires a Vector3 position, a Vector3 rotation and a float field of view
To revert back to the normal gameplay camera, you can do
World.RenderingCamera = null;
-
@LeeC2202 THANK YOU! I can finally get back to working on that mod
-
@NotCrunchyTaco No problem, I have another tip or two I can share but I didn't want to throw too much at you all at once.
-
@LeeC2202 Can you please share.
-
@NotCrunchyTaco Okay, it's more to do with if you have a camera that is following the player.
You can end up with situations where the screen jumps about when you get into vehicles or onto something that is moving, like a train for instance. So what you have to do, is position your camera in the world, then get the offset to that camera using:
Vector3 _offset = Game.Player.Character.GetOffsetFromWorldCoords(CameraPosition);
then you attach the camera to the player using that offset, like this:
NewCamera.AttachTo(Game.Player.Character, _offset);
That will stop the screen from jumping about. I had a major problem with that in my camera mod and stillhere had one in his driving modes mod, that code solved it in both cases.
You might not need it for the mod you're doing but it's worth keeping that in a reference file or something, just in case.
-
@LeeC2202 Yes. I don't think I will need it. I am working on a drone mod. I know there is already a drone mod but it is very broken.
-
@LeeC2202 Also another question do you know how to keep call variables in another class?
-
@NotCrunchyTaco How do you mean?
-
@LeeC2202 I made the prop for the drone a variable now I made a new class. Because I want to use another keydown statement and in the second class I cannot access the variable in the first class
-
@NotCrunchyTaco If you want to access a variable in the parent class, you can declare them as
public static
, then access them with ParentClassName.VariableName from the child class.So for example, say you have your main mod class called
MyMod
. In that you could dopublic static int MyVariable;
If you then create a new class called
MyThing
, you can accessMyVariable
in that by doing:int ChildValue = MyMod.MyVariable;
-
Is that what you mean?
-
@LeeC2202 Not quite
-
@NotCrunchyTaco Are you trying to get access to the value that is caught in the onKeyDown event in your other class?
-
@LeeC2202 Yes
-
@NotCrunchyTaco There is a way I could suggest but I wouldn't advise it... well, there are three ways.
-
Create a function on your second class that accepts a Keys parameter as an input, say
public void GetKey(Keys _key)
and pass it that way during an onTick update or similar. -
Store the Keys value into a
public static Keys
property in your main class and access it like I mentioned earlier. -
Make your second class inherit Script and add an onKeyDown event to that.
But my choice would be to do none of them and simply have the main class process the key event and then call/set the required function/variable in the second class.
Multiple keypress events is one I definitely wouldn't recommend, I think that could cause problems. If you want to choose any option, passing it directly would probably be the best bet.
-
-
@LeeC2202 Thanks I will try that