Jump to content
  • Advertisement
Sign in to follow this  
Spa8nky

[C#] Moving an object around based on impulses and mouse movement.

This topic is 2784 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I cast a ray out into 3D space and come back with the earliest hit time, the location of the hit and the first object hit by the ray.

I now create a spring between the entity and the hit location:


public void Setup(Entity e, Vector3 grabLocation)
{
Entity = e;

localOffset = grabLocation - e.InternalCenterOfMass; //Vector3.Zero;
GoalPosition = grabLocation;
}



The corrective impulses are applied to the object each update and it moves towards the GoalPosition end of the spring:


Vector3 grabbedLocation = localOffset + Entity.InternalCenterOfMass;
Vector3 positionError = GoalPosition - grabbedLocation;

// Apply the force
Entity.ApplyImpulse(grabbedLocation, positionError * CorrectionStrength * dt * Entity.Mass);

Entity.ModifyLinearDamping(1.0f);
Entity.ModifyAngularDamping(1.0f);



The problem is that I don't want to move the object towards the goal (current location of the mouse) when selected but only when the mouse moves.

How can I factor in the mouse offset so that the GoalPosition will be based on mouse movement from point of selection?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!