I have applied force on object. I want it moving constantly with same speed, it will collide with other objects such as player, enemy... I want it(object) to move constantly with same speed and don't change the velocity after collision. What should I do, because as it collides with other objects its velocity changes according to physics.... Any help will be appreciated.. Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Linq; public class Platform : MonoBehaviour { Rigidbody2D rb2d; void Start() { startMoving(); } public void startMoving() { Vector2 direction = new Vector2(-30, 0); Vector2 force = direction * 3f; rb2d.AddForce(force, ForceMode2D.Impulse); } }
Depends on what you want to have happen to other objects reacting to this object. You could try using rigidbody.moveposition instead of manipulating forces or velocities to see if that works out.
Neither one of these wouldn't change anything. Collisions still work using both. Even setting it to triggers wouldn't work.(misunderstood the OP, thought it was for projectiles, saw the code was for a platform.) For platforms you need Kinematic movement. Set the rigidbody body type to Kinematic. If AddForce doesn't work after that try movePosition or setting velocity directly.