# Tag Info

1

Here's one very simple way to do it: package; import flixel.FlxG; import flixel.FlxSprite; class Player extends FlxSprite { public static inline var VELOCITY:Float = 4; public function new() { super(); // enforce subpixel-rendering for smoother movement pixelPerfectRender = false; } override public function ...

0

Your understanding of Vector3.MoveTowards() is close, but not quite right. public static Vector3 MoveTowards(Vector3 current, Vector3 target, float maxDistanceDelta); Each time you call this method it returns a point along the vector from current to target that is at most maxDistanceDelta away from current. So if current is (0.0, 0.0, 0.0) and target is ...

0

You're better off using Lerp. float ElapsedTime; float FinishTime; Vector3 StartPosition Vector3 Target; void Start () { Vector3 StartPosition = Vector3.zero; Target = Vector3.one * 50; ElapsedTime = 0; FinishTime = 60f; } void Update () { ElapsedTime += Time.deltaTime; transform.position = Vector3.Lerp (StartPosition, Target, ...

0

Your code wasn't formatted and structured well at all (bunch of if, else is never pleasant to read), so I decided to re-write everything and give you an example of how you are supposed to code in C#. To check if you are structuring your code well or not, you can check 2 things. 1) Your Game class needs to be less than 50-80 lines of code. 2) How easy would ...

1

Do you want the objects to move along the X axis (right to left) at the same speed or should this vary? If it should be the same speed, simply apply some sort of random modification to their Y velocity every X frames while keeping the X velocity at a constant. If they should slightly vary in speed from left to right, do the same as above making sure to ...

0

Here is a pseudo theory on how to write it. Base on the lines drawn the max value for the Y-axis when generating random values is based off of the most extreme points from the object's center. You will also need a timer to set check distance. a more advanced version would be to apply random time to the below pseudo code to trigger more random variations ...

0

You could remedy to this by adding another bool canJump : public void Jump () { if(canJump) { if (grounded) rigidbody2D.velocity = jumpVelocity * Vector2.up; canJump = false; } } So when you are clicking, the Jump() method will run the jumping loop one time.After this code, you will need to set the canJump ...

0

I've edited your example, you can now rotate using the keys, it uses CSS3 rotations. If you want to move more fluid, you can either update the move() faster, or add some easing animations. You can still make several improvements, but here is one solution: http://codepen.io/anon/pen/jPraGK The css rotation code: \$("#block_green").css({'-webkit-transform' ...

3

Both of these examples are commonly used because they both have their advantages and drawbacks, mainly on the programming side of things. Square/Restricted Maps Pros: Easy to program, positions can be stored in tile-coordinates as integers and/or in world coordinates. Easy for the player to understand Fast Fairly easy math Cons: Very restricted in ...

0

This code snippet appears to simply compare two euclidean distances; the ordered distance and (what I'm assuming) is the maximum distance allowed (based on a movement radius?). Euclidean distance is normally calculated as: sqrt(dx^2 + dy^2) ; (where dx is delta x and dy is delta y) If you just want to compare two distances, to see which is greater, you ...

1

I would suggest making a separate buffer for each player that is responsible for squashing commands together. Basically, it should reduce a set of network packets into an approximation of user's input, which is sampled only once per game update that should result in equally significant change for every player. The question is, what should be sampled from ...

1

Your game shouldn't depend on the speed at which the packets are sent as it will vary depending on your internet connection regardless of what rate you attempt to send them. Instead your server should move the character depending on the user actions (e.g. while they are pressing (sending) W move them forward, or if you are counting mouse clicks then send ...

0

Like both answers said, there are 2 "secrets", one is you need to stop applying gravity when bounces are determined to be over (which is a bit of an extension over Leftium answers, he just said "resting" which is not enough because you rest as soon as you touch by this definition). Secondly, check for speed, obviously. This later condition is in relation to ...

0

Stop applying (the gravity) force after reaching RESTING_CONTACT. My guess is your sphere is reaching resting contact, but gravity (or other forces) causes it to continue moving as soon as the next update happens. Explanation: Generally, once an object reaches resting contact, it should not respond to forces until there is a force large enough to "push" ...

0

Instead of checking the distance for a resting contact, check for velocity. If 2 objects are moving slowly and hit each other, they should be put to rest. If not, they should do what they would do if they weren't resting. So... if (CollisionDetection()) { if (sphereVelocity.GetMagnitude() <= .1f) { //NoGravity(); //NoForces(); ...

-1

Get the velocity to move at based on the object's size and the speed. Move with that velocity. Then keep checking if the object has passed the target. IEnumerator MoveObject (Vector3 source, Vector3 target, float speed) { int Dot1 = (int)Mathf.Sign(Vector3.Dot(source, target)); //Get the original orientation int Dot2 = Dot1; //This is the current ...

0

You can do this: void moveObjectBySpeed(Vector3 source, Vector3 target, float speed) { pathLength = (target - source).magnitude; duration = pathLength / speed; moveObject(source, target, duration); } IEnumerator moveObject(Vector3 source, Vector3 target, float duration) { float startTime = Time.time; while(Time.time < startTime + duration) ...

0

When talking about 'speed' there are a couple of ways of thinking about it. You can think about it one way, like 'meters per frame' (ie: for each frame, I want the player to move X meters). For that type of functionality, see this: public IEnumerator MoveAtSpeedCoroutine(Vector3 end, float speed){ //while you are far enough away to move while ...

1

You can use something like this: IEnumerator MoveFromTo(Transform objectToMove, Vector3 a, Vector3 b, float speed) { float step = (speed / (a - b).magnitude) * Time.fixedDeltaTime; float t = 0; while (t <= 1.0f) { t += step; // Goes from 0 to 1, incrementing by step each time objectToMove.position = ...

0

Perhaps something like this: [RequireComponent(typeof(Rigidbody))] public class MovementTowardsTarget : MonoBehaviour { private void Start() { var target = GameObject.Find("Target"); StartCoroutine(MoveObject(target, 1.0f)); } private IEnumerator MoveObject(GameObject target, float speed) { var direction = ...

1

The mouse is in the screen coordinates. The screen is two dimensional. And you are trying to convert the 2d screen coordinates to 3d world coordinates. You need to specify the desired z position to the mouse position vector (you can think of it as the distance from the camera): var mousePos = Input.mousePosition; mousePos.z = 10f; mousePos = ...

0

You are currently setting their velocities when you press a key, when you release the key, their velocities must return to normal. That is the part you are missing. You should write something like this; public void keyReleased(MouseEvent e){ int key = e.getKeyCode(); if(key == KeyEvent.VK_W){ vel_y = 0; } if(key == KeyEvent.VK_S){ vel_y = 0; } ...

2

Add the following line to your Start() method: GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ; This will prevent the object from rotating on x & z axis, which will prevent it from rolling. If you don't want it to turn sideways as well, add FreezeRotationY as well, and then it ...

2

You can Freeze the rotation Change the transform's position(with translate, not recommended for physics though) Set the rotation equal to itself

Top 50 recent answers are included