Change font size
It is currently Sat Feb 24, 2018 10:56 am

Forum rules


{L_IMAGE}



Post a new topicPost a reply Page 1 of 1   [ 3 posts ]
Author Message
 Post subject: "crash simulation"
PostPosted: Mon Feb 05, 2018 8:42 am 

Joined: Mon Feb 13, 2017 1:53 pm
Posts: 13
Hi!
I'm trying to make a simple car crash simulation (very simple one).

The car is not supposed to be controllable by an avatar.
It simply moves in a predefined way.
The car is supposed to drive in the following way:

1. The car goes straight on for 5 meters
2. It drives against the left side of a standing object (driver's perspective).
3. Due to the impact, it gets a 45° rotation to the left.
4. Then it drifts off, in a 45° degree angle, to the left, for 3 more meters, losing speed.
5. It then grinds to a halt.

Here is my question:

How can I make the car rotate in step 3
(and not from the beginning)?

Without the rotation, the car simply moves crabwise,
which does not look realistic.

- I tried llSetKeyframedMotion.
But, the rotation I built in made the car rotate from the beginning.
(However, the rotation is only supposed to start in step 3, not earlier.)

- I also tried to divide the script into two parts using a timer event,
but it did not work at all.

- I also tried llSleep in order to divide the script but that did not work, either.
(llSleep is not advisable anyway, is it?)

Here is the script I used without the rotation or timer:


default
{
touch_start(integer num_detected)
{
llSetKeyframedMotion(
[<5.0, 0.0, 0.0>, 0.1, //(step 1 and 2)
<1.0, 4.0, 0.0>, 0.2],//(step4 and 5; step 3 is missing)
[KFM_DATA, KFM_TRANSLATION, KFM_MODE]);

}
}


Does anyone have some ideas?
Thank you!


Top
 Profile  
 
 Post subject: Re: "crash simulation"
PostPosted: Mon Feb 05, 2018 8:53 pm 
Furious Typer
User avatar

Joined: Fri Mar 26, 2010 12:11 pm
Posts: 113
Location: Belgium / Brussels
You can do with keyframe motion or with pathfinding.
Unfortunately pathfinding is still not implemented in OpenSim.

Here is a exemple:
{L_CODE}:
// Multi Keyframe Motion v0.1 by djphil (CC-BY-NC-SA 4.0)

rotation NormRot(rotation Q)
{
    float MagQ = llSqrt(Q.x*Q.x + Q.y*Q.y +Q.z*Q.z + Q.s*Q.s);
    return <Q.x/MagQ, Q.y/MagQ, Q.z/MagQ, Q.s/MagQ>;
}

default
{
    state_entry()
    {
        llSetLinkPrimitiveParamsFast(LINK_THIS, [
            PRIM_PHYSICS_SHAPE_TYPE,
            PRIM_PHYSICS_SHAPE_CONVEX
        ]);
    }
   
    touch_start(integer number)
    {
        float    dist = 5.0;
        rotation rot1 = NormRot(llEuler2Rot(<0.0, 0.0, 45.0> * DEG_TO_RAD));
        rotation rot2 = NormRot(llEuler2Rot(<0.0, 0.0, -45.0> * DEG_TO_RAD));
        rotation rot3 = NormRot(llEuler2Rot(<0.0, 0.0, 180.0> * DEG_TO_RAD));

        llSetKeyframedMotion([
            <dist, 0.0, 0.0>, ZERO_ROTATION, dist * 0.5,
            <0.0, 0.0, 0.0>, rot1, 1.0,
            <dist, dist, 0.0>, ZERO_ROTATION, dist * 0.5,
            <0.0, 0.0, 0.0>, rot3, 2.0,
            <-dist, -dist, 0.0>, ZERO_ROTATION, dist * 0.25,
            <0.0, 0.0, 0.0>, rot2, 0.5,
            <-dist, 0.0, 0.0>, ZERO_ROTATION, dist * 0.25,
            <0.0, 0.0, 0.0>, rot3, 1.0
        ], [KFM_MODE, KFM_FORWARD]);
    }
}

Enjoy! :P

_________________
Webmaster @ digitalconcepts.free.fr & digigrids.free.fr


Top
 Profile  
 
 Post subject: Re: "crash simulation"
PostPosted: Tue Feb 06, 2018 5:39 am 

Joined: Mon Feb 13, 2017 1:53 pm
Posts: 13
Nice, mate,
thank you so much!

It is actually beautiful to watch. 8-)

I have no idea how you did this, but it works amazingly.

I might use this with my students.

Thanks again! :-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 3 posts ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
610nm Style by Daniel St. Jules of Gamexe.net