New answers tagged

0

You have to check if the distance travelled is greater than what remains to travel; if it is, you arrive at your destination on that frame, explicitly set the position instead of 'travelling': public void Draw(SpriteBatch batch, int goalX, int goalY){ destX = goalX - posX; destY = goalY - posY; dist = Math.sqrt(destX * destX + destY * destY); ...


0

There are multiple things I can think of that could be causing you problems. Here are some things to look at: If your rigidbody is set kinematic, setting velocity will have no effect. Add debug statements like those in the code below to see what is or isn't working as intended Try removing the boundary checking statement to eliminate that as a potential ...


0

Well, I generally use to ask this questions in interviews :) Although I don't know Swift but I can give you a general idea about to achieve this. You have to play with some trigonometry to get current direction vector according to your current angle. Here is the pseudo code. float speed = 0.01 void GameLoop() { // I don't know that how Vector2 works ...


2

You will need a forward vector which represent the forward direction of your ship, and the velocity of your ship. // Stuff that you need (or already have) vec3 shipForwardVector; // This is according to your game infrastructure // and ship model; make it a unit vector. mat4 worldSpaceRotationMat; // assuming ship!.transform is only ...


0

Similar to RDeving's answer, here's my usual code: var keys = {}; window.onkeydown = function(evt) { keys[evt.keyCode] = true; } window.onkeyup = function(evt) { delete keys[evt.keyCode]; } Then, in your update loop: if (37 in keys) { //keycode 39 is down } if (38 in keys) { //keycode 38 is down } // ... etc


3

You would need to know the angle to the element from the spectator, so, if you have A | | \aº| |bº\ | | \| | B where the lines marked with pipes "|" are the "facing" directions, the diagonal is the "attack line", aº is the angle between B sight and A (-30deg) and bº is the angle between A sight and B (-30deg). You had to add the angles to see the ...


2

To be physical, you need to calculate friction based on the magnitude of your velocity. You can simply remove the if checks when calculating friction and store a "friction constant" instead of a "friction force." You are already essentially doing this because m_fFriction is a double and not a vector, you are just thinking about it wrong. The friction ...


0

It looks like you're using acceleration in a weird way in your engine, so I can't give you a 100% fool-proof answer you can directly implement into your code, but I can take a shot at it. You'd want to apply your friction to your current speed, not your characters acceleration. Try to change your code to this instead: if( curVel.x > 0.0f ) curVel.x ...


1

It sounds like you want to implement your own physics instead of using what's built in. Fortunately, you don't have do any kind of parabolic calculation when jumping (unless you want to project the path of the character or something like that). Instead, you let physics run its course which will naturally create parabolic shapes. Here is some example code for ...


1

One of the two parents is rotated 90 degrees around the Y axis. I can't be sure which way, but you can "fix" this by toggling Global/Local gizmos (its one of the two buttons in the upper-left corner, just above the "scene" tab). That, or un-rotating the parent object.


3

I prefer not to use FSMs for movement, but it can work in certain cases. One of the things FSMs are great for is animations, which is what the linked example would easily tie into. The key thing to notice about the code you are working from is that lateral motion is considered in every one of their states using their function agent:getMovement(). Even in the ...


1

Your ball behaves similar to how a real ball would. You are applying an increasing force (which looks unusual to me) you call "speed". The drag of the Rigidbody dampens the effect of the force in a way that grows with speed, which means that there is a max speed called "terminal velocity": http://forum.unity3d.com/threads/terminal-velocity.34667/ Set your ...



Top 50 recent answers are included