Get Velocity of Rigidbody Object Below Another Object
Hi all, so I'm having trouble trying to work this one out on my own.
Basically I have a 2D platform that will be moving to carry objects on-top of each-other. I need those objects to 'look' directly below them (even if they're rotated in real-world space), so it's always looking down relative to the world, not the object.
I've seen similar things done with Rays but I have no idea how to use them (most I've seen are in JavaScript and I need C#), especially in this context.
So the platform and the objects are all rigidbodies and I'm modifying the velocity of the platform, I've got them so they move together currently, but that's due to the platform's rigidbody velocity and the high friction, but they fall off too easily.
What I need is for them to also gain the same speed in the correct direction, but minus a few 0.1f's to give a bit of a 'sway' effect.
This is the code I'm using for the platform (no code written for the objects themselves yet):
void Update()
{
float distance_to_screen = Camera.main.WorldToScreenPoint(gameObject.transform.position).z;
Vector3 pos_move = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, distance_to_screen));
mouseDelta = pos_move - lastMousePosition;
acceleration = mouseDelta.x * 0.4f;
platformVelocity += acceleration;
platform.velocity = new Vector2(platformVelocity, 0) * speed;
lastMousePosition = pos_move;
}
All help is very much appreciated! Thank you!
Your answer
Follow this Question
Related Questions
Help with weapon rotation top down 2D C# 0 Answers
Rotate towards mouse pointer 1 Answer
Can't get a gameObject to follow my mouse 0 Answers
Help me with gui please (C#) 2 Answers
Child an Object to Another Objects Parent On Collision 1 Answer