Spawning Props in Relative positions and correct rotations facing you
-
Hello I was wondering if anyone could help me with a small issue I encountered while coding because I am a beginner and I need help so when I spawn a prop it always faces north is there anyway I can get it to face the direction the character is facing if they are facing east or south
-
@NotCrunchyTaco I usually just do
Prop.Rotation.Z = Game.Player.Character.Rotation.Z
There's probably another way using Vector.Forward or something, but they're not my strong point so I take the easy option.
You can probably use
Prop.Heading = Game.Player.Character.Heading
as well.
-
@LeeC2202 Thanks for the input I will try both of those right now and get back to you
-
@LeeC2202 THANK YOU SO MUCH IT WORKED
-
@LeeC2202 One more question this keeps happening
I am doing the very bottom prop placeOnGround true then the 2nd one from the bottom I do upvector * 1 then the very top one I do upvector * 2 I want to get rid of the gap it only happens when I am on unlevel ground and for all I am doing fowardvector * 5
-
@NotCrunchyTaco I honestly struggle with upvectors and forwardvectors, I've read up on them so many times but whatever I read just falls straight out of my head.
I would have to try and use
float _height = propName.Model.GetDimensions().Y
and use that as a Y offset to the next position up.So something like:
float _height = propName1.Model.GetDimensions().Y; propName2.Position = propName1.Position + new Vector3(0,_height,0);
Don't know if that would work but that's the way I would try it first.
-
@LeeC2202 I will try and again I will get back to you and yet again thanks for the input
-
@LeeC2202 So I tried the 0's no luck then I tested a bunch of other numbers and even negative numbers didn't work when my character was on even ground or up hill/down hill
If you have any other methods
-
@NotCrunchyTaco I've just noticed, my post was wrong.
It should be
propName2.Position = propName1.Position + new Vector3(0, 0, _height);
I took the height which is the Y value and added to the Y position value, which is wrong... it gets added to the Z position value... sorry about that.
-
@LeeC2202 It's okay and I will try the new method
-
@LeeC2202 One problem there is no "_height" variable do I take it from the other line of code you just gave me?
-
@NotCrunchyTaco You do understand that where I have written propName1 and propName2, you will need to change that to the names you have called your props?
Sorry if that sounds like a stupid question but I though I had better make sure.
-
@LeeC2202 I changed it to the names of the props I'm not an idiot but I am a newbie to coding but sadly it still didn't work is there a way to stack props on top of each other without any overlapping or gaps?
-
@NotCrunchyTaco See, that's what I was afraid of... I didn't mean it to sound like I was saying something bad.
It's just that I have given code to people like that many times and they simply copy and paste it as it is. So I have to ask and take the risk of it sounding like I am calling someone an idiot.
What's the name of the Prop you are trying to spawn?
-
@LeeC2202 It's okay
the prop I am trying to spawn is prop_ld_fragwall_01b
-
@LeeC2202 I also do not copy and paste code I modify it because I am curious and I know that will not work I know how programming works
-
@NotCrunchyTaco I can't believe I didn't spot my other mistake... these spammers are a real distraction.
This line
float _height = propName1.Model.GetDimensions().Y;
should actually say thisfloat _height = propName1.Model.GetDimensions().Z;
and that positions the second wall almost on top of the first one.However, something is not quite right because there is still a tiny gap between the wall pieces. So that probably means that the model dimensions are slightly bigger than the actual mesh dimensions.
So you will need to work out how big the gap is and subtract that from the _height value. What I would do then, is store that value in the mod class, something like
const Vector3 WallOffset = new Vector3(0,0, [proper offset]);
Then you can do
propName2.Position = propName1.Position + WallOffset;
So to put all that together.
Spawn the first wall.
Get the height withfloat _height = propName1.Model.GetDimensions().Z;
Do this to see the value in _height:UI.Notify(_height)
Spawn the second wall
set the position withpropName2.Position = propName1.Position + new Vector3(0, 0, _height);
But before the UI.Notify, do
_height = _height - .01
and keep making the .01 bigger until they match up, or smaller if that's too much. When you finally get it matched, store the value that is shown in the UI.Notify like I mentioned earlier, in theconst
statement
-
@LeeC2202 I will try that when I get on my PC and I'm giving you credit on the mod!
-
@NotCrunchyTaco No problem... hope it works for you.
Sorry it all got a bit messy last night, I was getting really stressed trying to manage everything, so I was making stupid mistakes.
-
@LeeC2202 I am still playing around with that I will figure it out soon thanks for the help!