Hauptinhalt

setActorInitialParent

R2026b

Specify parent of child actor

Since R2026b

    Description

    setActorInitialParent(scnro,childActor,parentActor) specifies the parent actor parentActor of the child actor childActor in the RoadRunner scenario scnro. Use this function to attach an actor as a child to another actor, or to detach a child actor from a parent actor.

    example

    Examples

    collapse all

    Use the setActorInitialParent function to attach a child actor to a parent actor, such as a trailer to a truck.

    This example assumes that you have prior knowledge of working with RoadRunner in MATLAB®. Before proceeding, follow the steps outlined in Set Up MATLAB Environment for RoadRunner Authoring Functions to set up your scenario using MATLAB functions for scenario authoring.

    Add Two Actors to Scenario

    Add two actors to your scenario by specifying the assets to use for the actors and the locations in the scenario in which to place them. Use the getAsset function to extract VehicleAsset objects that represent the SemiTruck.fbx_rrx and SemiTruck_Trailer01.fbx_rrx assets from the project prj. Then, use the addActor function to add them to the scenario represented by the Scenario object scnro at the scenario origin.

    semitruckAsset = getAsset(prj,"Vehicles/SemiTruck.fbx_rrx","VehicleAsset");
    trailerAsset = getAsset(prj,"Vehicles/SemiTruck_Trailer01.fbx_rrx","VehicleAsset");
    semiTruck = addActor(scnro,semitruckAsset,[0 0 0]);
    trailer = addActor(scnro,trailerAsset,[0 0 0]);

    Align the semiTruck actor to a road. Use the findSceneAnchor function to reference an existing anchor in the scene, and then use anchorToPoint to relocate the actor from the current location to the location specified by the referenced anchor. For more information, see findSceneAnchor and anchorToPoint.

    anchorPoint = findSceneAnchor(scnro,"ScenarioStart");
    semiPoint = semiTruck.InitialPoint;
    anchorToPoint(semiPoint,anchorPoint,PosePreservation="reset-pose")
    

    Use setActorInitialParent to Attach Two Actors

    To attach the actor trailer as a child to the actor semiTruck, use the setActorInitialParent function. This creates an ActorAttachmentPoint object that represents the connection attributes of the child actor trailer.

    setActorInitialParent(scnro,trailer,semiTruck)

    Run the simulation.

    simulateScenario(rrApp)

    Input Arguments

    collapse all

    Scenario that contains the actors, specified as a Scenario object.

    Child actor, specified as a Vehicle, Character, or MovableObject object. The function sets the InitialPoint property of this object based on the value of parentActor.

    • Vehicle, Character, or MovableObject object — If you specify parentActor as one of these objects, the function populates the InitialPoint property of childActor with an ActorAttachmentPoint object. RoadRunner Scenario relocates childActor to a position relative to the specified parent actor parentActor based on the properties of this ActorAttachmentPoint object.

    • [] — If you specify parentActor as an empty array, the function populates the InitialPoint property of childActor with a Point object, detaching it from any parent actor with which it had been associated.

    Parent actor, specified as Vehicle, Character, or MovableObject object, or as []. The function sets the InitialPoint property of childActor based on the value of this argument.

    • Vehicle, Character, or MovableObject object — If you specify parentActor as one of these objects, the function populates the InitialPoint property of childActor with an ActorAttachmentPoint object. RoadRunner Scenario relocates childActor to a position relative to the specified parent actor parentActor based on the properties of this ActorAttachmentPoint object.

    • [] — If you specify parentActor as an empty array, the function populates the InitialPoint property of childActor with a Point object, detaching it from any parent actor with which it had been associated.

    Version History

    Introduced in R2026b