- Home /
flickering on applying Force
HI , below mentioned is script attached to a cube but when it moves upwards it flickers. How can I make it smooth? Any help on this would be great.
using UnityEngine;
using System.Collections;
public class charcter_upwardmotion : MonoBehaviour {
void Start ()
{
Vector3 dir = Quaternion.AngleAxis(105, Vector3.forward) * Vector3.right;
this.rigidbody.AddForce(dir*6.5f,ForceMode.VelocityChange);//6.5f
}
}
Hmm.. Your script looks fine to me. Did you changed the physics? or have you added any other script to the cube object?
yup i have changed the gravity to -2 and there is one more script attached to destroy the instantiated object containing below mentioned method
void OnCollisionEnter(Collision col)
{
if (col.collider.tag == "basetrigger")
Destroy(this.gameObject);
}
I think the gravity scale of -2 with colliding object is causing the issue. Can you explain why you set the gravity to -2?
You need to create a physics material. Go to Assets -- Create Physics $$anonymous$$aterial and then you can play around with the various setting like friction, Bounce etc. Assign the material to the physics material property of you game object.
Answer by rezki · Dec 30, 2014 at 12:40 PM
this.rigidbody.AddForce(dir*6.5f,ForceMode.VelocityChange);//6.5f
// multiply your force by Time.deltaTime
this.rigidbody.AddForce(dir*6.5f * Time.deltaTime,ForceMode.VelocityChange);//6.5f
Your answer
Follow this Question
Related Questions
How would I counteract the force of the velocity and set it to zero after the input has stopped? 3 Answers
Get x and y Distance between two Vectors 1 Answer
Z-fighting problem. 1 Answer
Set Velocity at relative position. 2 Answers
Tried unsuccesfully many tips, vectorial force will keep adding to my object 1 Answer