unity – How can I use rigidbody to addforce to transform movement and to move the transform to a target?

using UnityEngine;
using System.Collections;

public class Move : MonoBehaviour
{
    public Transform target;
    public float force = 1f;
    public Rigidbody rb;

    private void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

    private void FixedUpdate()
    {
        var distance = Vector3.Distance(transform.position, target.position);

        rb.AddForce(transform.forward * force);
    }
}

In the screenshot the components on the transform. I added a Rigidbody and freezed the position on X and Y. Now the transform is moving straight getting force slowly.

The problem is if I’m not locking the X and Y on the Constraints the transform will fall down.
In the other hand locking the X and Y will prevent it to rotate or move to specific directions isn’t it ?

transform components settings

Now I want to add few stuff to it :

  • To make the transform to move to a target not just to move nonostop.

  • To make that when the transform reach a specific speed then stay at this speed for example speed 7.

  • To make that when the transform for example is in distance 10 from the target start removed force slowly until the transform is reaching the target then the force should be 0 so the transform will stop slowly smooth at the target.

  • To add a rotation to the transform when the transform start moving to the target he also will rotate facing the target.

unity – How can I increase/decrease the transform movement speed according to the distance from the target with rotation?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Move : MonoBehaviour
{
    public Transform target;
    public float speed;
    public float rotationSpeed;

    private Vector3 originalPosition;
    private Quaternion originalRotation;

    // Start is called before the first frame update
    void Start()
    {
        originalPosition = transform.position;
        originalRotation = transform.rotation;
    }

    // Update is called once per frame
    void Update()
    {
        var distance = Vector3.Distance(transform.position, target.position);
        if(distance < 0.1f)
        {
            transform.rotation = Quaternion.LookRotation(originalPosition);
        }

        transform.rotation = Quaternion.Lerp(transform.rotation, target.rotation, Time.deltaTime * rotationSpeed);
        transform.position = Vector3.MoveTowards(transform.position, target.position, Time.deltaTime * speed);
    }
}

So now it’s start moving and the same time rotating smooth to facing the target.
but I want that the speed will not be static but for example the speed start at 3 so instead I want the speed to start at let’s say 1.5 and to slowly increase until to 3 so it will looks like power effect like the transform take power the speed increasing and then I want that when it’s getting close to the target to smooth decrease the speed so when it’s getting to the target for example distance 0.1 from the target then the speed should be get already to 0.

Same logic the back way when the transform reached the target rotate slowly back to the original position/rotation and again increase the move speed to 3 and when getting close to the original position start slowly decrease the speed until 0.

One of the problems I always getting messed with is how to calculate the needed rotation speed according to the movement speed. If the transform move at speed 10 the rotation speed should be higher then 3 but how much higher ? And same of the transform is slower speed of movement then what the rotation speed should be ? In some cases the transform lost for some time the track because he couldn’t finish the rotation fast enough according to the movement speed.

control – Godot 3.X Implementing a smooth movement for pitch, yaw & roll

I’m implementing pitch, yaw and roll on airplane object, but when rotating the object (either pitch, roll or yaw), it starts rotating slowly but then the rotating movement goes awfully fast very quickly.
it’s quite jarring. i’m not sure how to make more smooth.

The issues:

  • I think the problem lies in the acceleration when the object rotates, i want to be an uniform speed
  • Other problem from this code, it’s that if want to change the rotating direction it’s slow to change, takes a while to rotate to the opposite direction

The player input code:

extends Node
const MAX_CAM_ANGLE = 30
var pitch_dir = 0
var yaw_dir = 0
var roll_dir = 0
var thrust = 0.5
var input = ''
func _ready():
    $DebugStats.add_property($Plane, "transform:origin", "round")
    $DebugStats.add_property($Plane, "force", "round")
    $DebugStats.add_property($Plane, "torque", "round")
    $DebugStats.add_property(self, "pitch_dir", "round")
    $DebugStats.add_property(self, "input", "")

func _physics_process(delta):
    process_inputs(delta)
    process_movement(delta)
    
func process_inputs(delta):
    if Input.is_action_pressed("p1_fire"):
        $Plane.fire_weapon()
        input = 'fire'
    if Input.is_action_pressed("ui_up"):
        thrust += delta
        input = 'accel'
    if Input.is_action_pressed("ui_down"):
        thrust -= delta
        input = 'slow'
    if Input.is_action_pressed("p1_pitch_up"):
        pitch_dir += delta
        input = 'up'
    if Input.is_action_pressed("p1_pitch_down"):
        pitch_dir -= delta
        input = 'down'
    if Input.is_action_pressed("p1_roll_left"):
        roll_dir += delta
        input = 'yaw left'
    if Input.is_action_pressed("p1_roll_right"):
        roll_dir -= delta
        input = 'yaw right'
    if Input.is_action_pressed("p1_yaw_left"):
        yaw_dir += delta
        input = 'yaw left'
    if Input.is_action_pressed("p1_yaw_right"):
        yaw_dir -= delta
        input = 'yaw right'

    if Input.is_action_pressed("ui_quit"):
        get_tree().quit()
    
#TODO Adjust values to make movement more smooth
func process_movement(delta):
     thrust = clamp(thrust, 0.2, 1)
     pitch_dir  = clamp(pitch_dir, -.6, .6)
     yaw_dir  = clamp(yaw_dir, -.6, .6)
     roll_dir  = clamp(roll_dir, -.6, .6)
     $Plane.calc_force(thrust, pitch_dir, roll_dir, yaw_dir)

The plane movement script:

extends RigidBody

const v3 = Vector3(0, 0, 0)
const scalar_z = Vector3(0, 0, -1)
var force = v3
var torque = v3
var drag = v3
var lift = v3
var thrust = v3

const MAX_THRUST_TURN = 150
const MAX_THRUST = 1  # temporal value just to debug the rotating problem
const MAX_CAM_ANGLE = 30
const DRAG_CONST = 1 # temporal value just to debug the rotating problem

# Calculates flying speed and direction
func calc_force(thrust, pitch_dir, roll_dir, yaw_dir):
    var speed = MAX_THRUST * (thrust)
    var drag_coef = DRAG_CONST / MAX_THRUST / MAX_THRUST  
    thrust = transform.basis.z * (-speed)
    drag = transform.basis.z * drag_coef
    lift = transform.basis.y * drag_coef
    
    force = thrust + drag + lift
    var pitch = global_transform.basis.x * pitch_dir * MAX_THRUST_TURN
    var yaw = global_transform.basis.z * yaw_dir * MAX_THRUST_TURN
    var roll = global_transform.basis.z * roll_dir * MAX_THRUST_TURN
    torque = pitch + yaw + roll

# Applies all force at once in the airplane object
func _integrate_forces(state):
    add_central_force(force)
    add_torque(torque)

How i can make the rotating movement more smoother?
Note: this is an arcade game, not really interested in a complex solution for the physics.

Note 2: if you want to test it, you can check out here
https://github.com/balmeidaa/godot_sky_aces

algorithm – Qix diagonally adjacent movement

I’m implementing a Qix clone game and I do not have any problems with implementation but rather with possible scenario.

Is this a valid scenario for this game and if yes how exactly should gameplay go in this case?

Black – Filled, Red – Current Player’s Path, Blue – Player

Step 1

If this is a possible scenario, then after completing the path player will end up with two diagonally adjacent rectangles.

Step 2

After that player can start moving from the bottom of the top rectangle to the right.

Step 3

In this case it should be immediately considered as a complete path and fill 1×1 square or player can create a path adjacent to the top of the bottom rectangle?

Step 4

unity – How and where in the code should I use the loop bool flag to decide if to loop or to make once movement between the waypoints?

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.AI;

public class Move : MonoBehaviour
{
    public Transform() targets;
    public LineRenderer lineRenderer;
    public float speed;
    public bool go = false;
    public bool countOrigPosAsWaypoint = true;
    public bool startFromFirstPositionOnStart = false;
    public bool goForward = true;
    public bool loop = true;

    private List<Vector3> pos = new List<Vector3>();
    private List<Vector3> positions = new List<Vector3>();
    private int index = 0;
    private List<GameObject> objectsToMoveCopy = new List<GameObject>();

    // Start is called before the first frame update
    void Start()
    {
        if (lineRenderer != null)
        {
            pos = GetLinePointsInWorldSpace();
        }
        else
        {
            if (countOrigPosAsWaypoint == true)
            {
                pos.Add(transform.position);
            }

            for (int i = 0; i < targets.Length; i++)
            {
                pos.Add(targets(i).position);
            }
        }

        if (startFromFirstPositionOnStart == true)
        {
            transform.position = pos(index);
        }

        if (pos.Count <= 1)
        {
            Debug.LogWarning("Targets list count must be more then 1");
        }
    }

    List<Vector3> GetLinePointsInWorldSpace()
    {
        positions = new Vector3(lineRenderer.positionCount).ToList();
        //Get the positions which are shown in the inspector 
        lineRenderer.GetPositions(positions.ToArray());


        //the points returned are in world space
        return positions;
    }

    // Update is called once per frame
    void Update()
    {
        if (go == true && pos.Count > 1)
        {
            Moving();
        }
    }

    void Moving()
    {
        Vector3 newPos = transform.position;
        float distanceToTravel = speed * Time.deltaTime;

        bool stillTraveling = true;
        while (stillTraveling)
        {
            Vector3 oldPos = newPos;
            newPos = Vector3.MoveTowards(oldPos, pos(index), distanceToTravel);
            distanceToTravel -= Vector3.Distance(newPos, oldPos);
            if (newPos == pos(index)) // Vector3 comparison is approximate so this is ok
            {
                // when you hit a waypoint:
                if (goForward)
                {
                    bool atLastOne = index >= pos.Count - 1;
                    if (!atLastOne) index++;
                    else { index--; goForward = false; }
                }
                else
                { // going backwards:
                    bool atFirstOne = index <= 0;
                    if (!atFirstOne) index--;
                    else { index++; goForward = true; }
                }
            }
            else
            {
                stillTraveling = false;
            }
        }

        transform.position = newPos;
    }
}

If true make a loop between the waypoints either backward or forward and if false just move forward or backward once and stop the last/first waypoint.

Powerful 30 PBN Backlinks for Casino Poker and Gambling for SERP movement for $20

Powerful 30 PBN Backlinks for Casino Poker and Gambling for SERP movement

Powerful Real PBN Backlinks for Casino, Poker, Gambling and betting, Increase ranking in Search Engine.

We work with the high page as well as high domain authority website representatives. All of them, along with us, are in charge of providing you with decent do-follow backlinks, coming from PBN.

Why Choose My Service:

  • Domain Authority High DA/PA and TF/CF
  • Trust Flow quality
  • All Links are Permanent Homepage Links.
  • 100% Safest Backlinks according to the latest Google update.
  • Using articles for all posts.
  • 100% Unique IPs.
  • 1 URL and 5 Keywords for maximum links diversity.
  • Every blog has a distinctive CMS.
  • Thousands of our client’s keywords in the first google pages.
  • Awesome boost in search.

How it Works?

✺ We do manual outreach to high quality sites related online casino, Gambling, poker, Related your niche

✺ Talk to the bloggers and secure a Blog posting Placement

✺ Craft a unique content with your link

✺ Submit it to the blog with a link back to your website

FAQS

Q: Do you guarantee the SERP movement?

A: Of course we guarantee the SERP movement.

Q: Do you provide a report?

A: Yes, we provide a complete and detailed report of Excel file.

Q: Are these links permanent?

A: Yes, all links are permanent.

Q: Do you accept foreign keywords?

A: Yes we do, but the article will still be in English.

Q: Do you provide the articles?

A: Yes we do. We use 100% unique well-spin articles with each post.

Inbox me for any query.

.

unity – IK script causing glitchy movement

I have a FPS character game object, which consists of just the arms. I made this IK script off of a tutorial.

{
public int chainLength = 2;

public Transform target;
public Transform pole;

public int iterations = 10;

public float marginOfError = 0.001f;

(Range(0, 1))
public float snapBackStrength = 1f;

protected float() bonesLength;
protected float completeLength;
protected Transform() bones;
protected Vector3() positions;
protected Vector3() startDirection;
protected Quaternion() startRotationBone;
protected Quaternion startRotationTarget;
protected Quaternion startRotationRoot;

public bool ikActive = false;

// Start is called before the first frame update
void Start()
{
    if (ikActive)
    {
        Init();
    }
}

// Update is called once per frame
void Update()
{
    
}

void LateUpdate()
{
    if (ikActive)
    {
        ResolveIK();
    }
}

void Init()
{
    bones = new Transform(chainLength + 1);
    positions = new Vector3(chainLength + 1);
    bonesLength = new float(chainLength);
    startDirection = new Vector3(chainLength + 1);
    startRotationBone = new Quaternion(chainLength + 1);

    startRotationTarget = target.rotation;
    completeLength = 0;

    var current = transform;
    for(var i = bones.Length - 1; i>= 0; i--)
    {
        bones(i) = current;
        startRotationBone(i) = current.rotation;

        if (i == bones.Length - 1)
        {
            startDirection(i) = target.position - current.position;
        }

        else
        {
            startDirection(i) = bones(i + 1).position - current.position;
            bonesLength(i) = (bones(i + 1).position - current.position).magnitude;
            completeLength += bonesLength(1);
        }

        current = current.parent;
    }
}

void ResolveIK()
{
    if (target == null)
    {
        return;
    }

    if (bonesLength.Length != chainLength)
    {
        Init();
    }

    for (int i = 0; i < bones.Length; i++)
    {
        positions(i) = bones(i).position;
    }

    var rootRotation = (bones(0).parent != null) ? bones(0).parent.rotation : Quaternion.identity;
    var rootRotationDifference = rootRotation * Quaternion.Inverse(startRotationRoot);
   
    if ((target.position - bones(0).position).magnitude >= completeLength)
    {
        var direction = (target.position - bones(0).position).normalized;

        for (int i = 1; i < positions.Length; i++)
        {
            positions(i) = positions(i - 1) + direction * bonesLength(i - 1);
        }
    }
      
    else
    {
        for (int i = 0; i < positions.Length - 1; i++)
        {
            positions(i + 1) = Vector3.Lerp(positions(i + 1), positions(i) + rootRotationDifference * startDirection(i), snapBackStrength);
        }

        for (int iteration = 0; iteration < iterations; iteration++)
        {
            for (int i = positions.Length - 1; i > 0; i--)
            {
                if (i == positions.Length - 1)
                {
                    positions(i) = target.position;
                }

                else
                {
                    positions(i) = positions(i + 1) + (positions(i) - positions(i + 1)).normalized * bonesLength(i);
                }
            }

            for (int i = 1; i < positions.Length; i++)
            {
                positions(i) = positions(i - 1) + (positions(i) - positions(i - 1)).normalized * bonesLength(i - 1);
            }

            if ((positions(positions.Length - 1)).magnitude < marginOfError)
            {
                break;
            }
        }
    }

    if (pole != null)
    {
        for(int i = 1; i < positions.Length - 1; i++)
        {
            var plane = new Plane(positions(i + 1) - positions(i - 1), positions(i - 1));
            var projectedPole = plane.ClosestPointOnPlane(pole.position);
            var projectedBone = plane.ClosestPointOnPlane(positions(i));
            var angle = Vector3.SignedAngle(projectedBone - positions(i - 1), projectedPole - positions(i -1), plane.normal);
            positions(i) = Quaternion.AngleAxis(angle, plane.normal) * (positions(i) - positions(i - 1) + positions(i - 1));
        }
    }

    for (int i = 0; i < positions.Length; i++)
    {
        if (i == positions.Length - 1)
        {
            bones(i).rotation = target.rotation * Quaternion.Inverse(startRotationTarget) * startRotationBone(i);
        }

        else
        {
            bones(i).rotation = Quaternion.FromToRotation(startDirection(i), positions(i + 1) - positions(i)) * startRotationBone(i);
        }

        bones(i).position = positions(i);
    }
}

}

The hierarchy looks like this:

FPS Person

(the arm mesh)

FPS armature

   camera bone


      shoulder bone.L


         upper arm bone.L


            lower arm bone.L


               hand.L


      shoulder bone.R


         upper arm bone.R


            lower arm bone.R


               hand.R
    

                  weapon holder (empty object)


                     assault rifle


                        (assault rifle mesh)


                        assault rifle armature (gun bone and magazine bone)


                        left hand position    (empty game object)




                        right hand position (empty game object)

I have the IK script attached to each of the hand bones with a chain length of 2, with no pole set. I have the target for the left hand as the left hand position, and I have the target for the right hand as the right hand position. The right hand position is in the exact same location as the hand bone.

The left hand IK works fine. For some reason, when I rotate the right hand position, the hand moves, but it moves really fast and in a jagged way, so that it looks glitchy. It also moves up and down even if I’m not rotating the gun.

Why is this happening, and how can I fix this?

I’d preferably no rotate the weapon holder itself since I plan to have multiple weapons as its child objects for weapon switching and I don’t want to mess the rotation up.

movement – What happens if a character’s velocity is greater than 0m when the character gets a Phase?

I’m preparing to run a Hero System, 6th Edition campaign, and I’m struggling to understand movement, especially velocity. Here’s the question: When a character’s Phase ends yet his velocity is still greater than 0m, does the character’s velocity affect what Actions the character can take on his next Phase?

For example, Slick’s Phase ends, but his velocity is still 20m. On Slick’s next Phase, can he take a Zero Phase Action to add velocity (E61 156), spend a Half Phase to take a Half Move during which he adds even more velocity, then spend a Half Phase to take an Action that requires an Attack roll, despite Slick still having a greater-than-0m velocity? Or, because Slick’s velocity is 20m at the start of the Phase, must Slick first take a Full Move or Half Move to reduce his velocity to 0m before the character can do anything else besides move?


Note: My confusion stems from this statement: A character “may not deactivate the Movement Power until he decelerates to 0m normally or through some outside means” (E61 156 and E62 25). So far as I can tell, the game doesn’t describe exactly what this means (i.e. I can’t tell if not moving is supposed to be the same thing as deactivating a Movement Power). Further, the game doesn’t seem to describe how already having velocity when a Phase begins impacts the character’s ability to take Actions. Finally, I’ve found no examples that cover what I imagine is this relatively common situation.

collision detection – Sliding movement on a grid

I’m trying to implement “sliding” movement on a simple grid, where the movement vector is continuous (floating point direction) but the grid is discrete (boolean blocked or open on integer axes).

The “destination” tile is found by adding the rounded movement vector to the current tile. That part is naive and works well enough.

For example, here:

  • blue is the current (source) tile
  • the yellow arrow is the movement vector
  • green is the destination tile

enter image description here

But this movement ends up being restrictive and I’d like to enable “sliding” to approximate player intent. My goal is that if the destination tile is blocked, the “next best” tile is used instead, provided it is available. I don’t know how to calculate that.

As you can see, the naive destination tile (where the yellow arrow lands) is blocked. As a result, I’d like to pick the green tile above as the destination tile.

enter image description here

However, crossing a diagonal should be allowed either, so the following case should result in the movement being blocked:

enter image description here

Finally, I’d like this algorithm to be as permissive as possible, so even the smallest component of the movement vector could win if no better alternative is found. For example, the movement should carry upwards in that case:

enter image description here

This sounds like a fairly simple problem and there may be existing algorithms for it, but I don’t know what it’s called, so I’m having trouble finding resources on it.

mac – Is there a way to automate the movement of application windows to assigned monitors?

So I have a new set up: 2 large screens (top left and top right), my macbook pro (centre), and my ipad (left).

I’m a coder, I like to have my coding environment in the centre, with research on the top left, results (e.g. created webpages) top right. Certain apps like Postman are on the left on the ipad.

Sometimes, as we all do, I reset my computer. When I do this, upon login, all my apps will open on the same screen.

Is there a way (maybe an Alfred script), to move all my applications to the desired monitor (and the desired desktop on that monitor)? It would save SO much time I can’t even begin to say.

Thanks.