Quantcast

Jump to content

» «
Photo

[C#] Changing spawn rotation of a object.

1 reply to this topic
Kalewero
  • Kalewero

    Best in team

  • Members
  • Joined: 23 Jan 2018
  • Sweden

#1

Posted 23 January 2018 - 05:02 PM

Hello, i've run into a little problem, i am trying to spawn an object where i'm aiming facing with the front towards me. The problem is basiclly that every object i have faces the same way as shown in the clip. I am using raycasting to determent the coords for the object. 

 

https://www.youtube....h?v=chj0TXKD7yM

 

Thanks in advance!

 

-Kalewero


Ezio Baggins
  • Ezio Baggins

    Player Hater

  • Members
  • Joined: 07 Jun 2017
  • India

#2

Posted A week ago

//GTA.Math.Vector3 spawnLoc3 = Game.Player.Character.GetOffsetPosition(new Vector3(0, 5, 0));
RaycastResult rayresult = World.GetCrosshairCoordinates();
Vector3 SpawnLoc = rayresult.HitPosition;

//UI.Notification.Show(rayresult.HitPosition.ToString());
//World.DrawMarker(MarkerType.DebugSphere, rayresult.HitPosition, new Vector3(0, 0, 0), new Vector3(0, 0, 0), new Vector3(.3f, .3f, .3f), System.Drawing.Color.Red);

OutputArgument outPosArg = new OutputArgument();
OutputArgument heading = new OutputArgument();
OutputArgument unkn = new OutputArgument();

Function.Call(Hash.GET_NTH_CLOSEST_VEHICLE_NODE_WITH_HEADING, SpawnLoc.X, SpawnLoc.Y, SpawnLoc.Z, 0, outPosArg, heading, unkn, 1, 0x40400000, 0);
float dir = heading.GetResult<float>();
Vector3 midNode = outPosArg.GetResult<Vector3>();
//World.DrawMarker(MarkerType.DebugSphere, midNode, new Vector3(0, 0, 0), new Vector3(0, 0, 0), new Vector3(.3f, .3f, .3f), System.Drawing.Color.Blue);

Model ObjModel = new Model("object_name");  //speed_bump_lane    //prop_beach_fire
ObjModel.Request(250);

if (ObjModel.IsInCdImage && ObjModel.IsValid)
{
    while (!ObjModel.IsLoaded) Script.Wait(50);
    Prop prop = GTA.World.CreateProp(ObjModel, SpawnLoc, falsetrue);
    prop.Heading = dir;
    prop.IsRecordingCollisions = true;
    GTA.UI.Notification.Show("Prop Created");
}
else
    GTA.UI.Notification.Show("Unable to load the model");

ObjModel.MarkAsNoLongerNeeded();
return;


Main part : use heading/ rotation for changing direction : 

Prop prop = GTA.World.CreateProp(ObjModel, SpawnLoc, falsetrue);
prop.Heading = dir;

or

prop.Rotation = (-1)GTA.Game.Player.Character.Rotation;

-1 : for the object to face u 





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users