Sign in to follow this  
Spa8nky

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this