How do you aim towards mouse when two objects are moving?

I’m trying to build a fairly simple 2D sidescroller, where the player does not control the actual character but helps them along by tossing objects at them. However, I’ve hit a problem - when using the mouse to target a section of screen and two objects are moving, there is a lag time where the object will fall behind the player and character and not to the relative position.

alt text

I’ve gotten this far:

		// Launch Position
		Vector3 cameraPosition = Camera.main.transform.position;
		
		// Mouse Position
		Vector3 pos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 12f));
	
		GameObject _object = items*;*
  •  // Create Item //*
    
  •  GameObject _item = Instantiate(_object, cameraPosistion, Quaternion.identity) as GameObject;*
    

But I’m utterly stumped on what to do next. The items have rigidbodies attached and use physics.

Hi Teon,

I think it is logical for the object thrown to be ‘left behind’ since both the camera and the character you are aiming for is always moving.

There are 2 possible methods I can think of for now. First one is to make the camera and character walking on the spot and animate all the backgrounds instead. This will still create the illusion of moving without literally moving them in the scene.

Secondly, by instantiating the thrown object as a child of either the camera or the character, which has been described here.

Best of luck!