• Advertisement
Sign in to follow this  

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

This topic is 2639 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