hi
I’ve been playing with trying to setup some more complicated vehicle systems (hovering vehicle) by adding forces to engines, I’m a game artist and this is possibly my second week of dabbling in coding so excuse the horrible “artist code”
i have this simple code that ray casts downwards (relatively) and then produces a force in the opposite direction if within a certain tolerance:
RaycastHit hit;
Debug.DrawRay(transform.position, -transform.up * hoverHeight);
if (Physics.Raycast (transform.position, -transform.up,out hit,hoverHeight))
{
float height = hit.distance;
float actualForce = hoverHeight - height;
if (actualForce < 0f)
actualForce = 0f;
rigidbody.AddRelativeForce(transform.up * (actualForce * hoverForce));
Debug.DrawRay(transform.position, transform.up * actualForce ,Color.red);
}
this works fine on a single engine it does exactly what i want it to, now i can’t seem to make this part of a more complex system easily
obviously first issue is i can’t add forces to child rigid bodies without lots of issues, tried adding fixed joints but everything gets very spongy and goes very wrong, so I’m trying to apply offset forces to the parent object using its children’s offset transforms.
problem is this goes beyond my knowledge it seems
I’ve added four public transforms which i hoped i could use as replacements for the transform.postions and transform.up but i can’t…
i want to use the colds transform offset from the parent to cast a ray from and then produce a force for multiple engines so that the vehicle balances on these
any ideas of the best way to do this, I’ve looked for hours now and can’t find a solution, now I’m sure I’ve just missed something simple but if you could point me in the direction i would be very grateful
cheers