I'm trying to implement a simple gravity gun which can suck and hold the object at a certain distance away from the camera. When mouse is released, it can launch the object.
My idea is :
1.use a ray to detect which entity is hited
2.set the gravity of this entity toward to the camera if possible. But I didn't find any method to set it so I tried to apply an impulse on the entity toward to the camera the lock it's position when it is close enough. But the entity will keep it's motion state(keep rotating or something). I want it's world matrix to be the same direction as the camera
3.apply an impulse when the mouse is released
I think the second step is not good enough. Any one have a better idea?
Any good ideas for implement a gravity gun?
Re: Any good ideas for implement a gravity gun?
Take a look at the demos grabber. It's composed of two constraints. One controls linear motion, the other controls angular motion.
In the grabber, the linear motor just tries to keep the object at the same point relative to the camera. However, you could make the goal point closer to you so it gets pulled in. Tuning the stiffness/damping/max force settings on the motor to make this feel good will most likely be necessary.
Similarly, the angular motor can have a goal orientation set so that the object does not change orientation relative to the holder after being picked up.
Note that a grabber-style gravity gun will suffer the same issues as the original Half Life 2's gravity gun. You may recall speedruns of people jumping on pieces of wood they were carrying in their hands, allowing them to fly all over the place. That was because the held object wasn't pushing back on the player, creating a nonphysical configuration. If this becomes a problem for you, you could use two-entity constraints between the character and the held object. The BallSocketJoint and AngularMotor would do the two-entity job of SingleEntityLinearMotor and SingleEntityAngularMotor.
Some more recent implementations of gravity guns do things a bit differently, too. Instead of holding the object with physical forces, picking up an object actually puts it into a special held state where it behaves more like a convex cast. This gets rid of issues where the player is smashing the object into a wall and it's behaving weirdly; instead, the convex cast will see that the object can't be held in that configuration and it gets dropped.
In the grabber, the linear motor just tries to keep the object at the same point relative to the camera. However, you could make the goal point closer to you so it gets pulled in. Tuning the stiffness/damping/max force settings on the motor to make this feel good will most likely be necessary.
Similarly, the angular motor can have a goal orientation set so that the object does not change orientation relative to the holder after being picked up.
Note that a grabber-style gravity gun will suffer the same issues as the original Half Life 2's gravity gun. You may recall speedruns of people jumping on pieces of wood they were carrying in their hands, allowing them to fly all over the place. That was because the held object wasn't pushing back on the player, creating a nonphysical configuration. If this becomes a problem for you, you could use two-entity constraints between the character and the held object. The BallSocketJoint and AngularMotor would do the two-entity job of SingleEntityLinearMotor and SingleEntityAngularMotor.
Some more recent implementations of gravity guns do things a bit differently, too. Instead of holding the object with physical forces, picking up an object actually puts it into a special held state where it behaves more like a convex cast. This gets rid of issues where the player is smashing the object into a wall and it's behaving weirdly; instead, the convex cast will see that the object can't be held in that configuration and it gets dropped.
- richielawrence
- Posts: 1
- Joined: Mon Jun 25, 2012 9:16 am
Re: Any good ideas for implement a gravity gun?
using ray to detec is a perfect idea