Jump to content

How to add ocillation to a physics object with an impulse already applied?


dbawel
 Share

Recommended Posts

Hello,

How might I add ocillation to a physics object with an impulse vector already applied? I thought it would be simple, but cannot get the function correct. The following playground scene oscillates scaling, but I need to apply this to the meshes position while they are already moving on an applyImpuse vector3 so that they oscillate while on the impuse vector - but I cannot seem to add the oscillation to the object's absolute potosition (abs). I won't even both with my attemps, as they are more problematic than helpful. But below is the last playground I was sent on a former post scling the ojects using math sin function as you can see. I thought this might be a starting point to get abs position and add the sin oscillation.

 http://www.babylonjs-playground.com/#1MJ09V#27

Thanks,

DB

Link to comment
Share on other sites

You're a madman, DB!  hehe.  What an idea.  Could I get you the moon and the stars, too? 

Oh gosh.  Ok, um... I think you need the physics impostor to oscillate its position... and not just the mesh that is directed by it.

And I think there is only one way to do that.  Oscillate the impostor's linearVelocity (periodically adding your zig-zagging to the current linearVelocity).

But guess what.  Your zig-zagging can cause a sideways collision with another mesh, which will completely change the general direction velocity that you were zig-zagging along-upon.

But think about this.  You set an airplane in motion along its fuselage axis... and then you blow it from side to side (oscillating cross-winds) with applyImpulses or summing your zig-zags with the current LV.  Ya gotta do it with impulses/LV.  Back in the old days, we had .updatePhysicsBody()... which seemed like a way to "force-around" the impostor... via repositioning the mesh it applied-to.  But that... is evil.  :) 

The impostor makes the call... on positioning physics active mesh.  Anything less... is unnatural.  :D

Soooo... I think... you HAVE TO zig-zag the impostor, and the mesh will come along for the ride.  The zig-zag has to be"summed" with the current physicsBody LV, I think.  In effect, each periodic impulse will be pushing the impostor sideways AND forward at the same time.  45 degrees left, then 45 degrees right, back and forth.... up and down.  Sure to make my dog vomit.  :)

But like I know anything.  :)  I'm just here for the free beer.

Link to comment
Share on other sites

Hey @adam -

Once again you come through. Although I just spent the day schooling myself in Math.sin() as it's allot of math to get the oscillations just right - especially since I'm also using your speed limit function for the collision imposters - which completely contradict each other.:blink:

Even though it took me all day to get the oscillation correct, I couldn't have done it without your help. Thanks much.;)

Cheers,

DB

Link to comment
Share on other sites

Hey @Wingnut -

If you want to see, here's a link - but the code is more messy than ever. I cleaned it up today, but was asked to remove the oscillation - after several days work and loads of help from @adam.

http://qedsoft.com/DEMOS2014/PE_KYP/index22.html

Again PLEASE ignore the sloppy code. Below is the nice clean code - same scene, but no oscillation:

http://qedsoft.com/DEMOS2014/PE_KYP/index23.html

Cheers,

DB

Link to comment
Share on other sites

@Pryme8 -

The project required random oscillation, but now that I spent a day building it, they decided they wanted it removed.:( So it was a waste of time in building, but I learned so much in building it and getting it to work. Hopefully, I can help others in new ways now that I went through all the pain - not in understanding any new math, but in incorporating this into a physics engine with spped limits on mesh movement. My primary need right now is two things: 

1. build a shader or effect that replicates draging your finger through still water - I'm considering adapting the Fire Material in BJS for this.

2. I must be able to support two users in the same touch application for pointerdown, pointerup, and pointermove events simultaniously.

Cheers,

DB

Link to comment
Share on other sites

for number 1, I think shader toy might have on like that, and for number 2 web workers and separate ports will handle that.

for the oscillation you need to track a few things

Accel => {x,y,z}
CurrentWiggle => {x,y,z}
Max/Min Wiggle => {x,y,z}
wiggleBaseValue => low number like 0.0001;

then set a before render function that takes the base wiggleValue, and calculates a random accel for all three directions being negative or positive does not matter, take the now accell and add that to the currentWiggle values, check that they are in range and push back into min max if not, and then apply this directly to the mesh.body.velocity.(direction) respectively

This will make it like a wobble of the camera or object, and can be tailored to simulate walking effects, stairs ect if you apply it to the cameras rotation instead of the object in a first person setting (just a side note)



All velocities and torques can be edited directly if you go right for the single value.  so velocity.x velocity.y velocity.z... but if you want to pass a vector to jsut velocity then you need to convert the vector object to what ever that physics engine expects so if your using cannon you need to make a cannon vec3 to pass to the body to have it set correctly... or just go for it directly.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...